Python 第二周作业
凯撒密码B
s = input() t = "" for c in s: if 'a' <= c <= 'z': #str是可以直接比较的 t += chr( ord('a') + ((ord(c)-ord('a')) + 3 )%26 ) elif 'A'<=c<='Z': t += chr( ord('A') + ((ord(c)-ord('A')) + 3 )%26 ) else: t += c print(t)
括号配对检测A
Str=input("") Left_bracket=0 Left_bracket_Z=0 Right_bracket_Z=0 for i in Str: if i== '(': Left_bracket+=1 elif i== ')': if Left_bracket>0: Left_bracket-=1 else: print("配对不成功") break elif i=='[': Left_bracket_Z+=1 elif i==']': Right_bracket_Z+=1 else: if Left_bracket!=0: print("配对不成功") elif Left_bracket_Z!=Right_bracket_Z: print("配对不成功") else: print("配对成功")
天天向上的力量B
NN=eval(input("")) Working=pow((1.0+0.001*NN),364) Pig=pow((1.0-0.001*NN),364) BB=int(Working//Pig) print("{:.2f}, {:.2f}, {}".format(Working,Pig,BB))
同符号数学运算
n = eval(input()) N = abs(n) a = N + 10 b = N - 10 c = N * 10 if n < 0: a = -abs(a) b = -abs(b) c = -abs(c) else: a = abs(a) b = abs(b) c = abs(c) print(N, a , b, c, end = "")
快乐的数字
def happy(n): try: if n==1: print('True') else: new = str(n) sum = 0 for c in new: sum += int(c)**2 return happy(sum) except Exception as e: print('False')
# print(e) n = eval(input()) happy(n)
字符串反码A
while True: try: string=input() if string!="!": res="" for i in string: if i.isupper(): res+=chr(ord("Z")-(ord(i)-ord("A"))) elif i.islower(): res += chr(ord("z") - (ord(i) - ord("a"))) else: res+=i print(res) except: break
计算矩形面积
a = float(input()) b = float(input()) square = a*b print(format(square,'.2f'))
格式化输出
num = float(input()) print("{:.3f}".format(num))
字符串逆序输出
str1 = input() print(str1[::-1])
照猫画虎求阶乘
a = int(input()) b = 1 for i in range(1, a+1): b = b*i print("%d" % float(b))
树懒爱睡,日常敲代码
努力营业

浙公网安备 33010602011771号