Python练习题 判断语句(19-36)

判断语句

第十九题

在这里插入图片描述

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)
choice = input("你的生日在不在以上数字当中(y/n):")
if choice == "y" or choice == "Y" or choice == "yes" or choice =="YES" or choice =="yES":
       day += 1

print(set2)
choice = input("你的生日在不在以上数字当中(y/n):")
if choice == "y" or choice == "Y" or choice == "yes" or choice =="YES" or choice =="yES":
       day += 2

print(set3)
choice = input("你的生日在不在以上数字当中(y/n):")
if choice == "y" or choice == "Y" or choice == "yes" or choice =="YES" or choice =="yES":
       day += 4

print(set4)
choice = input("你的生日在不在以上数字当中(y/n):")
if choice == "y" or choice == "Y" or choice == "yes" or choice =="YES" or choice =="yES":
       day += 8

print(set5)
choice = input("你的生日在不在以上数字当中(y/n):")
if choice == "y" or choice == "Y" or choice == "yes" or choice =="YES" or choice =="yES":
       day += 16

if day == 0 :
       print("?")
else :
       print("你的生日在%d号"%day)

第二十题

在这里插入图片描述

height = input("height(m): ")
weight = input("weight(kg): ")
BIM = float(float(weight) / (float(height) ** 2)
if BMI < 18.5:
    print("超轻")
 
elif 18.5 <= BMI < 25.0:
    print("标准")
 
elif 25.0 <= BMI < 30.0:
    print("超重")
 
else:
    print("痴肥")

第二十一题

在这里插入图片描述

year = int(input("请输入年份:"))
condition1 = year % 4 == 0 and year % 100 != 0
condition2 = year % 400 == 0
if condition1 or condition2:
    print(year, "是个闰年")

第二十二题

在这里插入图片描述

import random
com = random.randint(10,99)
usr = int(input("请输入数字:"))
ca = com // 10
cb = com % 10
ua = usr // 10
ub = usr % 10
if ca == ua and cb == ub :
    print("10000美金")
elif ca == ub and cb == ua :
    print("3000美金")
elif ca == ua or ca == ub or cb == ua or cb == ub :
    print("1000美金")
else :
    print("无")

第二十三题

请添加图片描述

a, b, c = eval(input("Enter a,b,c:"))
delt = b ** 2 - 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("No real roots")

第二十四题

在这里插入图片描述

a, b, c, d, e, f = eval(input("Enter a,b,c,d,e,f:"))
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 %.1f and y is %.1f" %(x,y))

第二十五题

在这里插入图片描述

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

第二十六题

在这里插入图片描述

a1, a2 = eval(input("请输入第一种所购产品的重量和价格:") )
b1, b2 = eval(input("请输入第二种所购产品的重量和价格:") )
if (a2 / a1) > (b2 /b1):
    print("第一种产品和第二种产品相比之下,第二种产品更好")
elif (a2 / a1) == (b2 /b1):
    print("第一种产品和第二种产品相比之下,两种产品一样好")
elif (a2 / a1) < (b2 /b1):
    print("第一种产品和第二种产品相比之下,第一种产品更好")

第二十七题

在这里插入图片描述

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)

第二十八题

在这里插入图片描述

import random

com = random.randint(0, 2)
usr = int(input("剪刀(0),石头(1),布(2):"))

com_str = ""
usr_str = ""
if com == 0:
    com_str = "剪刀"
elif com == 1:
    com_str = "石头"
else:
    com_str = "布"

if usr == 0:
    usr_str = "剪刀"
elif usr == 1:
    usr_str = "石头"
else:
    usr_str = "布"

if com == usr:
    print("玩家是%s,电脑是%s,是一个平局" % (usr_str, com_str))
elif usr - com == -1 or usr - com == 2:
    print("玩家是%s,电脑是%s,玩家输" % (usr_str, com_str))
else:
    print("玩家是%s,电脑是%s,玩家赢" % (usr_str, com_str))

第二十九题

在这里插入图片描述

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")

第三十题

在这里插入图片描述

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("不合法")

第三十一题

在这里插入图片描述

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 星期五")

第三十二题

在这里插入图片描述

x, y =eval((input("Enter a point with two coordinates:")))
if x <= 10 and y <= 10:
    print("Point (%.1f,%.1f) is in the circle"%(x,y))
else:
    print("Point (%.1f,%.1f) is not in the circle"%(x,y))

第三十三题

在这里插入图片描述

x, y = eval(input("Enter a point with two coordinates:"))
if x >= -5 and x <= 5 and y <= 2.5 and y >= -2.5:
    print("Point (%.1f,%.1f) is in the rectangle"%(x,y))
else :
    print("Point (%.1f,%.1f) is not in the rectangle" % (x, y))

第三十四题

在这里插入图片描述

number = int(input("Enter a three-digit integer:"))
a = number % 10
b = number // 100
if a == b:
    print("%d is a palindrome" %number)
else :
    print("%d not is a palindrome" %number)

第三十五题

在这里插入图片描述

x, y = eval(input("Enter a point's x- and y-coordinates:"))
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")

第三十六题

在这里插入图片描述

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")

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值