Python-11~15题

---11---

Question:

>Write a program which accepts a sequence of comma separated 4 digit binary numbers as its input and then check whether they are divisible by 5 or not. The numbers that are divisible by 5 are to be printed in a comma separated sequence.

>Example: 0100,0011,1010,1001

>Then the output should be:1010

Hints:

>In case of input data being supplied to the question, it should be assumed to be a console input.

Solution:

解法一:

解法二:

解法三:


result

---12---

Question:

>Write a program, which will find all such numbers between 1000 and 3000 (both included) such that each digit of the number is an even number.The numbers obtained should be printed in a comma-separated sequence on a single line.

Hints:

In case of input data being supplied to the question, it should be assumed to be a console input.

Solution:

解法一:

解法二:

。。。

---13---

Question:

>Write a program that accepts a sentence and calculate the number of letters and digits.

>Suppose the following input is supplied to the program:hello world! 123

>Then, the output should be:

LETTERS 10

DIGITS 3

Solution:

解法一:

解法二:

上述两种解决方法中显示了两种不同地格式化方法

result

解法三:

program(3)
result

---14---

Question:

>Write a program that accepts a sentence and calculate the number of upper case letters and lower case letters.

>Suppose the following input is supplied to the program:Hello world!

>Then, the output should be:

UPPER CASE 1

LOWER CASE 9

Solution:

解法一:

解法二:

代码与解法一 一样,打印方法不同。

解法三:

结果:

解法四:

result

---15---

Question:

>Write a program that computes the value of a+aa+aaa+aaaa with a given digit as the value of a.

>Suppose the following input is supplied to the program: 9

>Then, the output should be: 11106

解法一:

解法二:

result
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容