判断语句(练习题)
代码示例
19
set1 = "1\t3\t5\t7\n" \
"9\t11\t13\t15\n" \
"17\t19\t21\t23\n" \
"25\t27\t29\t31\n"
set2 = "2\t3\t6\t7\n" \
"10\t11\t14\t15\n" \
"18\t19\t22\t23\n" \
"26\t27\t30\t31\n"
set3 = "4\t5\t6\t7\n" \
"12\t13\t14\t15\n" \
"20\t21\t22\t23\n" \
"28\t29\t30\t31\n"
set4 = "8\t9\t10\t11\n" \
"12\t13\t14\t15\n" \
"24\t25\t26\t27\n" \
"28\t29\t30\t31\n"
set5 = "16\t17\t18\t19\n" \
"20\t21\t22\t23\n" \
"24\t25\t26\t27\n" \
"28\t29\t30\t31\n"
A = str(input("请问你的生日在set1中吗(T or F):"))
print(set1)
if A == "T":
a = 1
else: a = 0
B = str(input("请问你的生日在set2中吗(T or F):"))
print(set2)
if B == "T":
b = 2
else: b = 0
C = str(input("请问你的生日在set3中吗(T or F):"))
print(set3)
if C == "T":
c = 4
else: c = 0
D = str(input("请问你的生日在set4中吗(T or F):"))
print(set4)
if D == "T":
d =8
else: d = 0
E = str(input("请问你的生日在set5中吗(T or F):"))
print(set5)
if E == "T":
e = 16
else: e = 0
print("你的生日是:%s"%(a + b+c+d+e))
代码运行展示:
a =int(input("输入你的体重(磅)"))
b =int(input("输入你的身高(英寸)"))
c = a * 0.45359237
d = b * 0.0254
BMI = c/(d**2)
if BMI < 18.5:
print("超轻")
elif 18.5<= BMI < 25.0:
print("标准")
elif 25.0<= BMI < 30.0:
print("超重")
elif 30.0<= BMI :
print("痴肥")
代码运行展示:
代码展示
a = int(input("请输入年份:"))
b = a % 4 == 0 and a % 100 != 0
c = a % 400 ==0
if b or c:
print("闰年")
else :
print("平年")
代码运行展示P:
代码展示:
import random
com = random.randint(10,99)
people = int(input("请输入你的彩票号码(10---99):"))
if com // 10 == people // 10 and com % 10 == people % 10:
print("恭喜你获得10000美金")
if com // 10 == people % 10 and com % 10 == people // 10:
print("恭喜你获得3000美金")
if com // 10 == people // 10 or com // 10 == people % 10 or com % 10 == people % 10 or com % 10 == people // 10 :
print("恭喜你获得1000美金")
else:
print("谢谢惠顾")
代码运行展示:
代码展示:
a,b,c = map(float,input("请输入a,b,c的值:").split())
Q = (b ** 2) - (4 * a * c)
if Q > 0:
X1 = (-b +Q ** 0.5) / (2*a)
X2 = (-b -Q ** 0.5) / (2*a)
print("X1 = %f, X2 = %f"%(X1,X2))
elif Q == 0:
X = (-b -Q ** 0.5) / (2*a)
print("X = %f"%(X))
else:
print("no real roots")
代码运行展示:
代码展示:
a,b,c,d,e,f = map(float,input("请输入a,b,c,d,e,f的值:").split())
if (a * b) -(b * c) != 0:
x = ((e * d) - (b * f)) / ((a * d) - (b * c))
y = ((a * f) - (e * c)) / ((a * d) - (b * c))
print("X =%f,Y=%f"%(x,y))
else:
print("no solution")
代码运行展示: