0
点赞
收藏
分享

微信扫一扫

Python练习题 判断语句

他说Python 2022-04-13 阅读 67
python

Demo19

 

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"
day = 0
print(set1)
a = input("你的生日是否在表格中(yes/no):")
if a == "yes" :
       day += 1
print(set2)
a = input("你的生日是否在表格中(yes/no):")
if a == "yes" :
       day += 2
print(set3)
a = input("你的生日是否在表格中(yes/no):")
if a == "yes" :
       day += 4
print(set4)
a = input("你的生日是否在表格中(yes/no):")
if a == "yes" :
       day += 8
print(set5)
a = input("你的生日是否在表格中(yes/no):")
if a == "yes" :
       day += 16
if a == 0 :
       print("不存在")
else :
       print("你的生日在%s号"%(day))

Demo20

a = float(input("请输入身高:"))
b = float(input("请输入体重:"))
BMI = b / (a **2)
if BMI < 18.5 :
	print("超轻")
elif BMI >= 18.5 and BMI < 25.0 :
	print("标准")
elif BMI >= 25.0 and BMI < 30.0 :
	print("超重")
else :
	print("痴胖")

 Demo21

year = int(input("请输入年份:"))
first = year % 4 == 0 and year % 100 != 0
second = year % 400 == 0
if first or second :
	print("%d是个闰年"%(year))
else :
	print("%d是个平年"%(year))

 Demo22

Demo23

a,b,c = eval(input("请输入三个数:"))
delt = b * b - 4 * a * c
if delt > 0 :
	x1 = (-b + delt ** 0.5) / (2 * a)
	x2 = (-b - delt ** 0.5) / (2 * a)
	print("x1 = %.2f,x2 = %.2f"%(x1,x2))
elif delt == 0 :
	x = (-b + delt ** 0.5) / (2 * a)
	print("x = %.2f"%(x))
else :
	print("The equation has no roots")

 Demo24

a,b,c,d,e,f = eval(input("请输入6个数:"))
if a * d - b * c == 0 :
	print("The equation has no solution")
else :
	x = (e * d - b * f) / (a * d - b * c)
	y = (a * f - e * c) / (a * d - b * c)
	print("x is %s , y is %s"%(x,y))

 Demo25

today = int(input("请输入今天的日期:"))
a = int(input("请输入要经过多少天:"))
if (today + a) % 7 == 0 :
	print("Today is Sunday and future day is 星期天")
elif (today + a) % 7 == 1 :
	print("Today is Sunday and future day is 星期一")
elif (today + a) % 7 == 2 :
	print("Today is Sunday and future day is 星期二")
elif (today + a) % 7 == 3 :
	print("Today is Sunday and future day is 星期三")
elif (today + a) % 7 == 4 :
	print("Today is Sunday and future day is 星期四")
elif (today + a) % 7 == 5 :
	print("Today is Sunday and future day is 星期五")
elif (today + a) % 7 == 6 :
	print("Today is Sunday and future day is 星期六")

 Demo26

weight1,price1 = eval(input("请输入第一种包装的重量和价钱:"))
weight2,price2 = eval(input("请输入第二种包装的重量和价格:"))
if (price1 / weight1) > (price2 / weight2) :
	print("第二种更好")
elif (price1 / weight1) == (price2 / weight2) :
	print("两种一样好")
else :
	print("第一种更好")

 Demo27

a = int(input("请输入一个整数:") )
if a % 5 == 0 and a % 6 == 0:
    print("%d这个数能被5和6都整除" % a)
elif a % 5 != 0 and a % 6 == 0:
    print("%d这个数能被6整除,但不能被5整除" % a)
elif a % 5 == 0 and a % 6 != 0:
    print("%d这个数能被5整除,但不能被6整除" % a)
elif a % 5 != 0 and a % 6 != 0:
    print("%d这个数不能被5或者6整除" % a)

Demo28

 

Demo29

rate = eval(input("Enter the exchange rate from do1lars to RMB: "))
choice = eval(input("Enter 0 to convert do11ars to RMB and 1 vice versa: "))
amount = eval(input("Enter the do1lar amount: "))
if choice == 0:
    amount1 = amount * rate
    print("$%.1f is %.1f yuan"%(amount,amount1))
elif choice == 1:
    amount1 = amount / rate
    print("%.1f yuan is $%.2f"%(amount, amount1))
else :
    print("Incorrect input")

 Demo30

a, b, c = eval(input("Enter three sides:"))
if a + b > c and a + c > b and b + c > a:
    print(a+b+c)
else :
    print("非法")

 Demo31

import math
year = eval(input("Enter year:(e,g.,2008):"))
month = eval(input("Enter month:1-12:"))
q = eval(input("Enter the day of the month:1-31:"))
m = 0
if month == 1 or month == 2:
    m = 12 + month
    year = year - 1
j = year // 100
k = year % 100
h = (q + ((26 * (m + 1)) // 10) + k + k // 4 + j // 4 + 5 * j) % 7
if h == 0:
    print("Today is Sunday and the future day is 星期六")
elif h == 1:
    print("Today is Sunday and the future day is 星期天")
elif h == 2:
    print("Today is Sunday and the future day is 星期一")
elif h == 3:
    print("Today is Sunday and the future day is 星期二")
elif h == 4:
    print("Today is Sunday and the future day is 星期三")
elif h == 5:
    print("Today is Sunday and the future day is 星期四")
elif h == 6:
    print("Today is Sunday and the future day is 星期五")

 Demo32

x1, y1 = eval(input("请输入一个点的坐标:"))
x2 = 0 
y2 = 0
l = ((x2 - x1) ** 2 + (y2 - y1) ** 2) ** 0.5
if l <= 10 :
	print("这个点在圆内")
else :
	print("这个点在圆外")

 Demo33

x, y = eval(input("请输入一个点的坐标::"))
if x >= -5 and x <= 5 and y <= 2.5 and y >= -2.5:
    print("点 (%.1f,%.1f) 在矩形内"%(x,y))
else :
    print("点 (%.1f,%.1f) 不在矩形内" % (x, y))

 Demo34

num = int(input("请输入一个三位整数:"))
a = num % 10
b = num // 100
if a == b :
	print("%d是回文数"%(num))
else :
	print("%d不是回文数"%(num))

 Demo35

x, y = eval(input("Enter a point's x- and y-coordinates:"))
# 先限定xy的范围
if x >= 0 and x <= 200 and y >= 0 and y <= 100:
    k = y / (200 - x)
    if k <= 100 / 200:
        print("The point is in the triangle")
    else:
        print("The point is not in the triangle")
else:
    print("The point is not in the triangle")

 Demo36

x1, y1, r1= eval(input("Enter circlel's_ center x1,y1coordinates,and radius:"))
x2, y2, r2= eval(input("Enter circlel's_ center x2,y2coordinates,and radius:"))
d = ((x2 - x1) ** 2 + (y2 - y1) ** 2) ** 0.5

if d <= abs(r1 - r2):
    print("circle2 is inside circle1")
elif  d <= r1 + r2:
    print("circle2 overlaps circle1")
else:
    print("circle2 does not overlap circle")

 

举报

相关推荐

Python判断语句练习题

SQL语句练习题

python -【二】判断语句

if 判断语句

if判断语句

Python练习题

python 练习题

python练习题

0 条评论