1. Statistics of the number of words in English strings
Be Enter an English string, follow Space to split words and count the number of words Be Be
input format
Enter an English string Be
output format
number of words Be
Answer code:
print(len(input().strip().split()))
Be Test Case:
2. Get the month string
describe
Input a number from 1 to 12, output the corresponding month, for example, input 3, output "March" Be Be
input format
Enter a number between 1 and 12 Be Be
output format
output month Be
Example of input and output
enter | output | |
Example 1 | 1 | January |
11 | November |
Answer code:
n = input()
Number = list(range(1, 13))
Name = ['一月份', '二月份', '三月份', '四月份', '五月份', '六月份', '七月份','八月份','九月份','十月份','十一月份','十二月份']
monthBook = {}
for i in range(len(Number)):
d1 = "{}".format(Number[i])
d2 = "{}".format(Name[i])
monthBook[d1] = d2
print(monthBook[n])
Test Case:
3. Judging leap years
describe
Enter a year to determine whether it is a leap year Be Be
The criteria for judging leap years are as follows, and one of the following conditions can be satisfied. Be Be
1. Divisible by 4, but not divisible by 100 Be Be
2. Divisible by 400 Be
Example of input and output
enter | output | |
Example 1 | 1896 2020 2019 |
1896 is a leap year Be 2020 is a leap year Be 2019 is not a leap year |
Answer code:
year = int (input ())
if (year % 4 ==0 and year % 100 !=0) or year % 400 ==0:
print("%d年是闰年"%year)
else:
print("%d年不是闰年"%year)