Question 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
Hints: In case of input data being supplied to the question, it should be assumed to be a console input.
upper,lower = 0,0
for i in x:
if 'a'<=i and i<='z':
lower = lower + 1
if 'A'<=i and i<='Z':
upper = upper +1
#or use the function belowing:
# for i in x:
# lower+=i.islower()
# upper+=i.isupper()
print("lower:",lower)
print("upper:",upper)
summary:
这一部分主要集中在列表的遍历和字符的判断,islower()和iupper()两个方法算是比较常用的两个方法,可以直接记忆
Question 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
Hints:
In case of input data being supplied to the question, it should be assumed to be a console input.
def compute(num):
return num+(10*num+num)+(100*num+10*num+num)+(1000*num+100*num+10*num+num)
compute(9)
没什么难度的题,也没什么好说的
网友评论