畅享聊:Python的练习题(7)

畅享聊:Python的练习题(7)分享兴趣,传播快乐,增长见闻,留下美好!亲爱的您,这里是LearningYard新学苑。今天小编为你带来畅享聊:Python的练习题(7),欢迎

畅享聊:Python的练习题(7)

分享兴趣,传播快乐,增长见闻,留下美好!

亲爱的您,这里是LearningYard新学苑。今天小编为你带来

畅享聊:Python的练习题(7),

欢迎您的访问!

Share interests, spread happiness, increase knowledge, and leave beautiful!

Dear you, this is LearningYard Academy.

Today, the editor brings you

Enjoy chatting: Exercises in Python (7),

welcome your visit!

大家好,今天小编继续带着大家一起看看Python的练习题。

Hello, everyone. Today, Xiao Bian continues to show you the Python exercises.

畅享聊:Python的练习题(7)

畅享聊:Python的练习题(7)

题目如上图所示,要求判断输入的数字是几位数以及将每位数字倒着打印出来。

The question is as shown in the figure above. It is required to judge how many digits the input number is and print each digit upside down.

既然要我们给一个数,那么我们就设置一个x作为我们给出的数字,/n是用来换行的。同时我们将五位数字依次设为a,b,c,d,e,这样我们便能清晰地对应起来。//是整数除法,它能很方便地帮我们确定各个位置数字到底是几,%是返回除数的余数。然后我们直接输出e,d,c,b,a这样就完成了第二小问。

Since we are required to give a number, we will set an x as the number we give, and/n is used to wrap lines. At the same time, we set the five digits as a, b, c, d, e in order, so that we can clearly correspond// It is an integer division. It can help us determine the number of each position conveniently.% is the remainder of the returned divisor. Then we directly output e, d, c, b, and a to complete the second question.

接下来就是判断该数字是几位数,这里我们用到if elif语句来进行判断。“!=”是不等于。

如果a不等于0那么也就是说,这个数有五位数字,以此类推便,便可以判断出x是几位数。详细的代码如下图所示

Next is to determine the number of digits. Here we use the if elif statement to judge. “!=” is not equal to.

If a is not equal to 0, that is to say, this number has five digits. By analogy, you can determine how many digits x is. The detailed code is shown in the figure below

畅享聊:Python的练习题(7)

输入结果测试一下:

Test the input results:

畅享聊:Python的练习题(7)

畅享聊:Python的练习题(7)

先将我们要输入的数字为a,再将a[ : : -1]赋值给b。“a[ : : -1]”是将a的值倒序复制,接着用选择语句来判断输入数字是否为回文数。%s是用作Python的格式化输出,下图的%s就是插入字符中为%a进行占位,这样才能正确地输出结果。

代码与输出结果如下图所示。

First set the number we want to enter as a, and then assign a [:: – 1] to b. “A [:: – 1]” is to copy the value of a in reverse order, and then use the selection statement to determine whether the input number is palindrome number.% S is used as the formatted output of Python.% s in the figure below is the placeholder for% a in the insertion character, so that the result can be output correctly.

The code and output results are shown in the figure below.

畅享聊:Python的练习题(7)

畅享聊:Python的练习题(7)

以上两道题都是基础的对数字进行排列判断,巩固基础才能发现更多。

The above two questions are both basic. Only by arranging and judging the numbers can we find more.

今天的分享就到这里了。

如果您对今天的文章有独特的想法,

欢迎给我们留言,

让我们相约明天,

祝您今天过得开心快乐!

That’s it for today’s sharing.

If you have a unique idea about today’s article,

Welcome to leave us a message,

Let us meet tomorrow,

I wish you a happy day today!

本文由learningyard新学苑原创,如有侵权,请联系我们。

参考资料:菜鸟教程

翻译来源:百度翻译

文字&排版|calm

审核|闫庆红

今天的文章畅享聊:Python的练习题(7)分享到此就结束了,感谢您的阅读。

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/59441.html

(0)
编程小号编程小号

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注