目录
demo19
Set1 = "1\t3\t5\t7\n"\
"9\t11\t13\t15\n"\
"17\t19\t21\t23\n"\
"25\t27\t29\t31\t"
Set2 = "2\t3\t6\t7\n"\
"10\t11\t14\t15\n"\
"18\t19\t22\t23\n"\
"26\t27\t30\t31\t"
Set3 = "4\t5\t6\t7\n"\
"12\t13\t14\t15\n"\
"20\t21\t22\t23\n"\
"28\t29\t30\t31\t"
Set4 = "8\t9\t10\t11\n"\
"12\t13\t14\t15\n"\
"24\t25\t26\t27\n"\
"28\t29\t30\t31\t"
Set5 = "16\t17\t18\t19\n"\
"20\t21\t22\t23\n"\
"24\t25\t26\t27\n"\
"28\t29\t30\t31\t"
day = 0
print(Set1)
a = int(input("看表中是否有与你生日的数字,有的话输入 1 ,没有输入 2:"))
if a == 1:
day = day+1
print(Set2)
b = int(input("看表中是否有与你生日的数字,有的话输入 1 ,没有输入 2:"))
if b == 1:
day = day+2
print(Set3)
c = int(input("看表中是否有与你生日的数字,有的话输入 1 ,没有输入 2:"))
if c == 1:
day = day+4
print(Set4)
d = int(input("看表中是否有与你生日的数字,有的话输入 1 ,没有输入 2:"))
if d == 1:
day = day+8
print(Set5)
e = int(input("看表中是否有与你生日的数字,有的话输入 1 ,没有输入 2:"))
if e == 1:
day = day+16
print(day)
运行结果:
demo20
a = float(input("请输入以榜为单位的体重:"))
b = float(input("请输入以英尺为单位的身高:"))
BMI = (a*0.4535937)/(b*0.0254)
if BMI >= 30.0:
print("痴胖")
elif BMI >=25.0:
print("超重")
elif BMI >= 18.5:
print("标准")
else:
print("超轻")
运行结果:
demo 21
year = int(input("请输入一个年份:"))
if (year%4==0 and year%100!=0) or year%400==0:
print("%s是闰年"%year)
else:
print("%s不是闰年"%year)
运行结果:
demo 22
from random import randint
a=randint(10,99)
b = int(input("请输入一个两位的数字:"))
c = a%10
d = a//10
if d == b//10 and c ==b%10:
print("恭喜获得奖金10000美元")
elif (d == b//10 or d ==b%10) and (c == b//10 or c ==b%10):
print("恭喜获得奖金3000美元")
elif d == b//10 or d ==b%10 or c ==b//10 or c ==b%10:
print("恭喜获得奖金1000美元")
else:
print("没中奖")
运行结果:
demo 23
import math
a,b,c = map(float, input("enter a,b,c:").split())
panduan = b*b - 4*a*c
if panduan > 0:
r1 = (-b+ math.sqrt(panduan))/2*a
r2 = (-b- math.sqrt(panduan))/2*a
print("The roots are %s and %s "%(r1,r2))
elif panduan ==0 :
r1 = (-b+ math.sqrt(panduan))/2*a
print("The roots are %s"%(r1))
elif panduan <0:
print("没有值")
运行结果:
demo 24
a,b,c,d,e,f = map(float, input("enter a,b,c,d,e,f:").split())
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 and y is %s"%(x,y))
运行结果:
demo 25
dct={1:'Monday',2:'Tuesday',3:'Wednesday',4:'Thursday',5:'Friday',6:'Saturday',7:'Sunday'}
today = int(input("输入今天的日期以数字表示:"))
a = int(input("请输入要经过多少天:"))
if (today + a) % 7 == 0:
print("Today is %s and the future day is 星期天"%dct.get(today))
elif (today + a) % 7 == 1:
print("Today is %s and the future day is 星期一"%dct.get(today))
elif (today + a) % 7 == 2:
print("Today is %s and the future day is 星期二"%dct.get(today))
elif (today + a) % 7 == 3:
print("Today is %s and the future day is 星期三"%dct.get(today))
elif (today + a) % 7 == 4:
print("Today is %s and the future day is 星期四"%dct.get(today))
elif (today + a) % 7 == 5:
print("Today is %s and the future day is 星期五"%dct.get(today))
elif (today + a) % 7 == 6:
print("Today is %s and the future day is 星期六"%dct.get(today))
运行结果:
demo 26
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("包装一产品更好")
运行结果:
demo 27
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)
运行结果:
demo 28
shuju = {0:'剪刀',1:'石头',2:'布'}
from random import randint
a=randint(0,3)
b = int(input("请输入0(剪刀),1(石头),2(布):"))
if (a-b)==0:
print("电脑是:%s,玩家是:%s,平局"%(shuju.get(a),shuju.get(b)))
elif (a-b)==-2 or (a-b)==1:
print("电脑是:%s,玩家是:%s,电脑赢"%(shuju.get(a),shuju.get(b)))
else:
print("电脑是:%s,玩家是:%s,玩家赢"%(shuju.get(a),shuju.get(b)))
运行结果:
demo 29
a = eval(input("Enter the exchange rate from do1lars to RMB: "))
b = eval(input("Enter 0 to convert do11ars to RMB and 1 vice versa: "))
amount = eval(input("Enter the do1lar amount: "))
if b == 0:
amount1 = amount * a
print("$%.1f is %.1f yuan"%(amount,amount1))
elif b == 1:
amount1 = amount / a
print("%.1f yuan is $%.2f"%(amount, amount1))
else :
print("Incorrect input")
运行结果:
demo 30
a, b, c = eval(input("请输入三边:"))
if a + b > c and a + c > b and b + c > a:
print(a+b+c,"合法")
else :
print("不合法")
运行结果:
demo 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 星期五")
运行结果:
demo 32
import math
a,b = eval(input("Enter a point with two coordinates:"))
r = math.sqrt(a*a+b*b)
if r < 10:
print("点(%s,%s)在圆内"%(a,b))
else:
print("点(%s,%s)在圆内"%(a,b))
运行结果:
demo 33
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))
运行结果:
demo 34
x = int(input("Enter a three-digit integer:"))
a = x % 10
b = x // 100
if a == b:
print("%d is a palindrome" %x)
else :
print("%d not is a palindrome" %x)
运行结果:
demo 35
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")
运行结果:
demo 36
import math
x1,y1,r1 = eval(input("请输入圆一的圆心心坐标和半径:"))
x2,y2,r2 = eval(input("请输入圆二的圆心心坐标和半径:"))
juli = math.sqrt((x1-x2)**2+(y1-y2)**2)
if juli <= math.sqrt((r1-r2)**2):
print("圆二在圆一内")
elif juli <= r1+r2:
print("圆二与圆一有重叠")
else:
print("无相交")
运行结果: