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"
day = 0
print(set1)
choice = input("判断数字在不在set1, y表示在, n表示不在")
if choice == "y" or choice == "Y":
day += 1
print(set2)
choice = input("判断数字在不在set2, y表示在, n表示不在")
if choice == "y" or choice == "Y":
day += 2
print(set3)
choice = input("判断数字在不在set3, y表示在, n表示不在")
if choice == "y" or choice == "Y":
day += 4
print(set4)
choice = input("判断数字在不在set4, y表示在, n表示不在")
if choice == "y" or choice == "Y":
day += 8
print(set5)
choice = input("判断数字在不在set5, y表示在, n表示不在")
if choice == "y" or choice == "Y":
day += 16
print("你的生日在%d号"%day)
执行框图:
20、
代码:
weight = float(input("请输入体重:"))
height = float(input("请输入身高:"))
bmi = weight / (height**2)
if bmi <= 18.5:
print("过轻")
elif bmi >= 18.5 and bmi <= 25:
print("正常")
elif bmi >= 25 and bmi <= 28:
print("过重")
elif bmi >= 28 and bmi <= 32:
print("过重")
elif bmi > 32:
print("痴胖")
执行框图:
21、
代码:
year = int(input("请输入年份:"))
if year // 4 == 0 and year // 100 != 0 and year // 400 == 0:
print("这个年份是闰年")
else:
print("这个年份不是闰年")
执行框图:
22、
代码:
import random
i = int(input("请输入随机两位数:"))
a = random.randint(10,100)
print("中奖号码为:",a)
b = a%10
c = a//10
d = i%10
e = i//10
if i == a:
print("恭喜获得10000美金")
elif b == e and c == d:
print("恭喜获得3000美金")
elif b == d or b == e or c == d or c == e:
print("恭喜获得1000美金")
else:
print("你未中奖")
执行框图:
23、
代码:
import math
a = int(input("请输入a的值:"))
b = int(input("请输入b的值:"))
c = int(input("请输入c的值:"))
d = b**2-4*a*c
if d < 0:
print("判定式值为负,无根")
elif d > 0:
r1 = (-b+math.sqrt(d))/2*a
r2 = (-b-math.sqrt(d))/2*a
print("方程的根为%d,%d"%(r1,r2))
elif d == 0:
r = -b/(2*a)
执行框图:
24、
代码:
a = int(input("请输入a的值:"))
b = int(input("请输入b的值:"))
c = int(input("请输入c的值:"))
d = int(input("请输入d的值:"))
e = int(input("请输入e的值:"))
f = int(input("请输入f的值:"))
if a*d-b*c == 0:
print("该等式无意义")
else:
x = (e*d-b*f)/(a*d-b*c)
y = (a*f-e*c)/(a*d-b*c)
print("x is %d and y is %d"%(x,y))
执行框图:
25、
代码:
now = int(input("Enter today's day(星期天为0,星期一为1,...,星期六为6):"))
n = int(input("Enter the number of day elapsed since today:"))
if (now + n) % 7 == 0:
print("The future day is Sunday")
elif (now + n) % 7 == 1:
print("The future day is Monday")
elif (now + n) % 7 == 2:
print("The future day is Tuesday")
elif (now + n) % 7 == 3:
print("The future day is Wednesday")
elif (now + n) % 7 == 4:
print("The future day is Thursday")
elif (now + n) % 7 == 5:
print("The future day is Friday")
elif (now + n) % 7 == 6:
print("The future day is Saturday")
执行框图:
26、
代码:
weight1, price1 = eval(input("输入第一种包装的重量和价钱weight1, price1:"))
weight2, price2 = eval(input("输入第二种包装的重量和价钱weight2, price2 :"))
if (weight1 / price1) < (weight2 / price2):
print("第二种包装价钱更好")
elif (weight1 / price1) == (weight2 / price2):
print("两种包装一样好")
elif (weight1 / price1) > (weight2 / price2):
print("第一种包装价钱更好")
执行框图:
28、
代码:
import random
a = int(input("剪刀(0),石头(1),布(2):"))
i = random.randint(0,2)
if i == 0:
print("对方出的剪刀")
elif i == 1:
print("对方出的石头")
elif i == 2:
print("对方出的布")
if a == 0:
print("你出的剪刀")
elif a == 1:
print("你出的石头")
elif a == 2:
print("你出的布")
if a==i:
print("drew")
elif a==0 and i==2:
print("you win")
elif a==1 and i == 0:
print("you win")
elif a==2 and i==1:
print("you win")
else:
print("you lose")
执行框图:
29、
代码:
apl = float(input("请输入美元汇率:"))
rate = float(input("输入0表示美元换为RMB,输入1表示RMB换为美元:"))
if rate == 0:
dollar = float(input("请输入所需兑换美元金额:"))
a = dollar*apl
print("$%d is %d yuan"%(dollar,a))
elif rate == 1:
y = float(input("请输入RMB总额:"))
a = y/apl
print("%d yuan is $%d"%(y,a))
elif rate != 0 and rate != 1:
print("错误输入")
30、
代码:
x = int(input("x="))
y = int(input("y="))
z = int(input("z="))
if x+y>z and x+z>y and y+z>x:
c = x+y+z
print("这个三角形的周长为:",c)
else:
print("这个输入是不合法的")
执行框图:
31、
代码:
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 星期五")
执行框图:
32、
代码:
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))
执行框图:
33、
代码:
x, y = eval(input("输入点:"))
if x >= -5 and x <= 5 and y <= 2.5 and y >= -2.5:
print("Point (%.1f,%.1f) 在矩形内"%(x,y))
else:
print("Point (%.1f,%.1f) 不在矩形内" % (x, y))
执行框图:
34、
代码:
number = int(input("Enter a three-digit integer:"))
a = number % 10
b = number // 100
if a == b:
print("%d is a 回文数" %number)
else :
print("%d not is a 回文数" %number)
执行框图:
35、
代码:
x,y = eval(input("输入点:"))
# y = -0.5*x +100 x = 200-2y
if x >= 0 and x <= 200 and y >= 0 and y <= 100:
k = y / (200 - x)
if k <= 100 / 200:
print("点在三角形内")
else:
print("点不在三角形内")
else:
print("点不在三角形内")
执行乱涂:
36、
代码:
x1, y1, r1= eval(input("输入圆1圆心坐标和它们的半径:"))
x2, y2, r2= eval(input("输入圆2圆心坐标和它们的半径:"))
d = ((x2 - x1) ** 2 + (y2 - y1) ** 2) ** 0.5
if d <= abs(r1 - r2):
print("圆2在圆1中")
elif d <= r1 + r2:
print("圆2与圆1有重叠部分")
else:
print("圆2和圆1无重叠部分")
执行框图: