Python-11~15题

2020-08-18  本文已影响0人  AoEliauk

---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
上一篇下一篇

猜你喜欢

热点阅读