第二次作业-python123
1.计算矩形面积
a = float(input())
b = float(input())
s = a * b
s_S = round(s,2)
print(""+str(s_S))
2.格式化输出
s = float(input())
print("{:.3f}".format(s))
3.字符串逆序输出
str = input() print(str[::-1])
4.照猫画虎求阶乘
n = int(input()) a = 1 for i in range(1,n+1): a = a * i print(a)
5.天天向上的力量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))
6.同符号数学运算
N=eval(input())
N1=abs(N)
if N<0:
N2=-abs(abs(N)+10)
N3=-abs(abs(N)-10)
N4=-abs(N*10)
else:
N2=abs(N+10)
N3=abs(N-10)
N4=abs(N*10)
print("{:} {:} {:} {:}".format(N1,N2,N3,N4))
7.快乐的数字
def x(n):
list = [int(i)for i in str(n)]
s = 0
for i in range(0,len(list)):
s = s + pow(list[i],2)
return s
n = input()
while x(n)>=10:
n = x(n)
else:
if x(n)==1:
print('True')
else:
print('False')
8.凯撒秘密B
s = input("")
t = ""
for c in s:
if 'a' <= c <= 'z':
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)
9.括号配对检测A
st=input()
a=0
for x in st:
if x=="(":
a+=1
if x==")":
a-=1
if a<0:
print("配对不成功")
break
else:
if a == 0:
print("配对成功")
else:
print("配对不成功")
10.字符串反码A
s=input() t='' for i in range(len(s)): if 97<=ord(s[i])<=122 : t+=chr(122-ord(s[i])+97) continue if 65<=ord(s[i])<=90: t+=chr(90-ord(s[i])+65) else: t+=s[i] print(t)

浙公网安备 33010602011771号