5.1
表达上:长整型+L
内容上:长整型表示的数字更大
5.2
(a)
def product(a,b):
print("the consequence:",a*b)
(b)
5.3
c = int(input("please input a number:"))
if c>=90 and c<=100:
print("A")
elif c>=80 and c<=89:
print("B")
elif c>=70 and c<=79:
print("C")
elif c>=60 and c<=69:
print("D")
else:
print("F")
5.4
c = int(input("please input the year:"))
if c%4==0:
print("this year is leap year ")
elif c%4==0 and c%100==0:
print("this year is the leap year")
else:
print("this year is not a leap year")
5.5美元换算成美分
#美元换算成美分
c = int(input("please input the number:"))
A = divmod(c,20)
if A[1]>1:
B = divmod(A[1],10)
if B[1]>1:
C = divmod(B[1],5)
print("this can be converted %s 20cents,%s 10cents %s 5cents %s 1cents" %(A[0],B[0],C[0],C[1]))
else:
print("this can be converted %s 20cents,%s 10cents %s 1cents" % (A[0], B[0], B[1]))
else:
print("this can be converted %s 20cents, %s 1cents" % (A[0], A[1]))
(蹩脚英语表达见谅 ?)
5.6
def test(a,s,b):
if s == "+":
print(a+b)
elif s == "-":
print(a-b)
elif s == "*":
print(a*b)
elif s == "%":
print(a%b)
elif s == "/":
print(a/b)
elif s == "//":
print(a//b)
elif s == "**":
print(a**b)
else:
print("invalid expression! ")
test(1,"=",4)
5.7
应该是用switch吧
5.8
计算面积和体积
import math
print("1正方形\n2立方体\n3圆\n4球")
choice=input("please input your choice:")
length =int(input("please input the length:"))
if choice == "1":
# length = input("please input the length:")
print("正方形的面积:", length*length)
if choice == "2":
# length = input("please input the length:")
print("立方体的面积:", 6*length*length)
print("立方体的体积:", length**3)
if choice == "3":
# length = input("please input the length:")
print("圆的面积:", length*length*math.pi)
if choice == "4":
print("球的体积:", 4/3*length**3*math.pi)
5.17
import random
N = random.randint(2,100)
print("N:",N)
list = []
for i in range(N):
n = random.randint(0,2**31-1)
list.append(n)
i=i+1
list.sort()
print(list)