第四周作业

一只青蛙一次可以跳上1级台阶,也可以跳上2级。请问该青蛙跳上一个n级的台阶总共有多少种跳法。‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‭‬

输入台阶数,输出一共有多少种跳法

 1 def jump(num):
 2     if num <= 2:
 3         return num
 4     else:
 5         t1,t2 = 1,2
 6         for i in range(3,num+1):
 7             t1,t2 = t2,t1+t2
 8         return t2
 9 n = eval(input())
10 t = jump(n)
11 print(t)

 

验证码校验

1 a = input()
2 before = 'qS2x'
3 after = 'Qs2X'
4 table = ''.maketrans(before, after)
5 if a.translate(table) == 'Qs2X':
6     print('验证码正确')
7 else:
8     print('验证码错误,请重新输入')

大小写转换

 1 str = input()
 2 for c in str:
 3     if 'a' <= c <= 'z':
 4         c = c.upper()
 5         print(c,end='')
 6         continue
 7     elif 'A' <= c <= 'Z':
 8         c=c.lower()
 9         print(c,end = '')
10     else:
11         print(c,end = '')

查找特定字符

str = input()
for c in str:
    if 'a' <= c <= 'z':
        c = c.upper()
        print(c,end='')
        continue
    elif 'A' <= c <= 'Z':
        c=c.lower()
        print(c,end = '')
    else:
        print(c,end = '')

敏感词过滤

1 str = input()
2 print(str.replace('垃圾','*').replace('陷阱','*').replace('不要脸','*').replace('内幕','*').replace('辣鸡','*'))

字符串替换

old = input()
new = input()
alls = input()
print(alls.replace(old,new))

身份证号处理

 1 from datetime import*
 2 now = datetime.now().year
 3 num = str(input())
 4 print('你出生于{}年{}月{}日'.format(num[6:10],num[10:12],num[12:14]))
 5 age = now - eval(num[6:10])
 6 print('你今年{}周岁'.format(age))
 7 if eval(num[16]) % 2 == 0:
 8     print('你的性别为女')
 9 else:
10     print('你的性别为男')

 

posted on 2020-04-01 22:56  B·W  阅读(177)  评论(0编辑  收藏  举报