Python(二)判断语句

Demo19

 

#Demo19
Set1 = [1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31]
Set2 = [2,3,6,7,10,11,14,15,18,19,22,23,26,27,30,31]
Set3 = [4,5,6,7,12,13,14,15,20,21,22,23,28,29,30,31]
Set4 = [8,9,10,11,12,13,14,15,24,25,26,27,28,29,30,31]
Set5 = [16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31]
print("""
	     1   3   5   7
	     9   11  13  15
	     17  19  21  23
	     25  27  29  31""")
S1 = input("你的生日在Set1中吗?(y/n): ")
if S1 == "y":
	a = 1
elif S1 == "n":
	a = 0 
print("   ")

print("""
	     2   3   6   7
	     10  11  14  15
	     18  19  22  23
	     26  27  30  31""")
S2 = input("你的生日在Set2中吗?(Y/N): ")
if S2 == "y":
	b = 2
elif S2 == "n":
	b = 0 
print("   ")

print("""
	    4   5   6   7
	    12  13  14  15
	    20  21  22  23
	    28  29  30  31""")
S3 = input("你的生日在Set3中吗?(Y/N): ")
if S3 == "y":
	c = 4
elif S3 == "n":
	c = 0 
print("   ")

print("""
	   8   9   10  11
	   12  13  14  15
	   24  25  26  27
	   28  29  30  31""")
S4 = input("你的生日在Set4中吗?(Y/N): ")
if S4 == "y":
	d = 8
elif S4 == "n":
	d = 0 
print("   ")

print("""
	   16  17  18  19
	   20  21  22  23
	   24  25  26  27
	   28  29  30  31""")
S5 = input("你的生日在Set5中吗?(Y/N): ")
if S5 == "y":
	e = 16
elif S5 == "n":
	e = 0 
print("   ")
print("你的生日是: ",a+b+c+d+e)

Demo20

 

 

#Demo20
weight,height = eval(input("Enter your weight and height: "))
weight1 = weight * 0.45359237
# print(weight1)
height1 = height * 0.0254
# print(height1)
BMI = (weight1 / height1)**2
# print(BMI)
if BMI < 18.5:
	print("超轻")
elif 18.5 <= BMI and BMI <= 25.0:
	print("标准")
elif 25.0 <= BMI and BMI <= 30.0:
	print("超重")
elif BMI <= 30.0:
	print("痴肥")

Demo21

 

 

#Demo21
year = int(input("Enter an year: "))
if year % 4 == 0 and year % 100 != 0:
	print(year,"年是闰年")
elif year % 400 == 0:
	print(year,"年是闰年")
else:
	print(year,"年不是闰年")

Demo22

 

 

#Demo22
import random
num = int(input("请输入一个两位数(10~99): "))
a = num // 10
b = num % 10
# print(a)
# print(b)

N = random.randint(10,99)
# print(N)
c = N // 10
d = N % 10
# print(c)
# print(d)

L = [c,d]
# print(L)

if num == N:
	print("恭喜你获得一等奖!奖金10000美元!!")
elif a in L and b in L:
	print("还不错哟,你获得了二等奖!奖金3000美元!!")
elif a in L or b in L:
	print("再接再厉,你获得了三等奖!奖金1000美元!!")
else:
	print("真遗憾,你没有中奖!!")

Demo23

 

 

#Demo23
import math
a,b,c = eval(input("Enter a b c: "))
k = b**2 - 4 * a * c
if k < 0:
	print("The equation has no real roots")

elif k == 0:
	r1 = (-b + math.sqrt(b**2 - 4 * a * c)) / (2 * a)
	r2 = (-b - math.sqrt(b**2 - 4 * a * c)) / (2 * a)
	print("The root is: ",r1)

elif k > 0:
	r1 = (-b + math.sqrt(b**2 - 4 * a * c)) / (2 * a)
	r2 = (-b - math.sqrt(b**2 - 4 * a * c)) / (2 * a)
	print("The roots are: ",r1,r2) 

Demo24

 

 

#Demo24
a,b,c,d,e,f = eval(input("Enter a,b,c,d,e,f: "))
if a * d - b * c == 0:
	print("The equaton 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: ",x,"and y is: ",y)

Demo25

 

 

#Demo25
toDay = eval(input("Enter today's day: "))
futureDay = eval(input("Enter number of day elapsed since today: "))
z = (toDay + futureDay) % 7
if toDay == 1:
	if z == 1:
		print("Today is Monday and the future day is Monday")
	elif z == 2:
		print("Today is Monday and the future day is Tuesday")
	elif z == 3:
		print("Today is Monday and the future day is Wednesday")
	elif z == 4:
		print("Today is Monday and the future day is Thursday")
	elif z == 5:
		print("Today is Monday and the future day is Friday")
	elif z == 6:
		print("Today is Monday and the future day is Saturday")
	elif z == 0:
		print("Today is Monday and the future day is Sunday")

elif toDay == 2:
	if z == 1:
		print("Today is Tuesday and the future day is Monday")
	elif z == 2:
		print("Today is Tuesday and the future day is Tuesday")
	elif z == 3:
		print("Today is Tuesday and the future day is Wednesday")
	elif z == 4:
		print("Today is Tuesday and the future day is Thursday")
	elif z == 5:
		print("Today is Tuesday and the future day is Friday")
	elif z == 6:
		print("Today is Tuesday and the future day is Saturday")
	elif z == 0:
		print("Today is Tuesday and the future day is Sunday")

elif toDay == 3:
	if z == 1:
		print("Today is Wednesday and the future day is Monday")
	elif z == 2:
		print("Today is Wednesday and the future day is Tuesday")
	elif z == 3:
		print("Today is Wednesday and the future day is Wednesday")
	elif z == 4:
		print("Today is Wednesday and the future day is Thursday")
	elif z == 5:
		print("Today is Wednesday and the future day is Friday")
	elif z == 6:
		print("Today is Wednesday and the future day is Saturday")
	elif z == 0:
		print("Today is Wednesday and the future day is Sunday")

elif toDay == 4:
	if z == 1:
		print("Today is Thursday and the future day is Monday")
	elif z == 2:
		print("Today is Thursday and the future day is Tuesday")
	elif z == 3:
		print("Today is Thursday and the future day is Wednesday")
	elif z == 4:
		print("Today is Thursday and the future day is Thursday")
	elif z == 5:
		print("Today is Thursday and the future day is Friday")
	elif z == 6:
		print("Today is Thursday and the future day is Saturday")
	elif z == 0:
		print("Today is Thursday and the future day is Sunday")

elif toDay == 5:
	if z == 1:
		print("Today is Friday and the future day is Monday")
	elif z == 2:
		print("Today is Friday and the future day is Tuesday")
	elif z == 3:
		print("Today is Friday and the future day is Wednesday")
	elif z == 4:
		print("Today is Friday and the future day is Thursday")
	elif z == 5:
		print("Today is Friday and the future day is Friday")
	elif z == 6:
		print("Today is Friday and the future day is Saturday")
	elif z == 0:
		print("Today is Friday and the future day is Sunday")

elif toDay == 6:
	if z == 1:
		print("Today is Saturday and the future day is Monday")
	elif z == 2:
		print("Today is Saturday and the future day is Tuesday")
	elif z == 3:
		print("Today is Saturday and the future day is Wednesday")
	elif z == 4:
		print("Today is Saturday and the future day is Thursday")
	elif z == 5:
		print("Today is Saturday and the future day is Friday")
	elif z == 6:
		print("Today is Saturday and the future day is Saturday")
	elif z == 0:
		print("Today is Saturday and the future day is Sunday")

elif toDay == 0:
	if z == 1:
		print("Today is Sunday and the future day is Monday")
	elif z == 2:
		print("Today is Sunday and the future day is Tuesday")
	elif z == 3:
		print("Today is Sunday and the future day is Wednesday")
	elif z == 4:
		print("Today is Sunday and the future day is Thursday")
	elif z == 5:
		print("Today is Sunday and the future day is Friday")
	elif z == 6:
		print("Today is Sunday and the future day is Saturday")
	elif z == 0:
		print("Today is Sunday and the future day is Sunday")

else:
	print("Enter is error,please Enter again!!")

Demo26

 

 

#Demo26
weight1,price1 = eval(input("Enter weight and price for package 1: "))
weight2,price2 = eval(input("Enter weight and price for package 2: "))
x1 = price1 / weight1
x2 = price2 / weight2
if x1 > x2:
	print("package 2 has the better price!")
elif x1 < x2:
	print("package 1 has the better price!")
else:
	print("two packages are the same price!") 

Demo27

 

 

#Demo27
num = int(input("Enter an integer: "))
print("IS ",num," divisible by 5 and 6 ? ",True if num % 5 ==0 and num % 6 == 0 else False)
print("IS ",num," divisible by 5 or 6 ? ",True if num % 5 ==0 or num % 6 == 0 else False)
if num % 5 ==0 and num % 6 == 0:
	print("IS ",num," divisible by 5 or 6, but not both? False")
elif num % 5 ==0 or num % 6 == 0:
	print("IS ",num," divisible by 5 or 6, but not both ? True")

Demo28

 

 

#Demo28
import random
num = eval(input("Enter scissor (0), rock (1), paper (2): "))
N = random.randint(0,2)
# print(N)
if num == 0:
	if N == 0:
		print("The computer is scissor. you are scissor. It is a draw")
	elif N == 1:
		print("The computer is rock. you are scissor. you are lose")
	elif N == 2:
		print("The computer is paper. you are scissor. you are won")

if num == 1:
	if N == 0:
		print("The computer is scissor. you are rock. you are won")
	elif N == 1:
		print("The computer is rock. you are rock. It is a draw")
	elif N == 2:
		print("The computer is paper. you are rock. you are lose")

if num == 2:
	if N == 0:
		print("The computer is scissor. you are paper. you are lose")
	elif N == 1:
		print("The computer is rock. you are paper. you are won")
	elif N == 2:
		print("The computer is paper. you are paper. It is a draw")

Demo29

 

 

#Demo29
exchangeRate = float(input("Enter the exchange rate from dollars to RMB: "))
num = int(input("Enter 0 to convert dollars to RMB and 1 vice versa: "))
if num == 0:
	dollarsNumber = float(input("Enter the dollars amount: "))
	print("$",dollarsNumber,"is ",exchangeRate * dollarsNumber,"yuan")
elif num == 1:
	rmbNumber = float(input("Enter the RMB amount: "))
	print(rmbNumber,"yuan is $",rmbNumber / exchangeRate)
else:
	print("Incorrect input")

Demo30

 

 

#Demo30
a,b,c = eval(input("Enter three edgs: "))

if a + b > c and a + c > b and b + c >a:
	print("The perimeter is ",a + b +c)
else:
	print("The input is invalid")

Demo31

 NULL

#Demo31
year = int(input("Enter year: (eg:2018..): "))
m = int(input("Enter month: 1-12: "))
q = int(input("Enter the day of the month: 1-31: "))
if m == 1 or m == 2:
	m += 12
	print(m)
	year -= 1
	print(year)
	j = year / 100 
	print(j)
	k = year % 100
	print(k)
	h = (q + 26 * (m + 1) / 10 + k + k / 4 + j / 4  + 5 * j) % 7
	print(h)
else:
	print(m)
	print(year)
	j = year / 100
	print(j)
	k = year % 100
	print(k)
	h = (q + 26 * (m + 1) / 10 + k + k / 4 + j / 4  + 5 * j) % 7
	print(h)

 

Demo32

 

 

#Demo32
import math
x1,y1 = eval(input("Enter a point with two coordinates: "))
distance = math.sqrt((x1 - 0)**2 + (y1 - 0)**2)
if distance <= 10:
	print("Point (",x1,",",y1,") is in the circle")
else:
	print("Point (",x1,",",y1,") is not in the circle")

Demo33

 

 

#Demo33
import math
x,y = eval(input("Enter a point with two coordiinates: "))
distance = math.sqrt((x - 0)**2 + (y - 0)**2)
if distance <= 5 and math.sqrt(y**2):
	print("Point (",x,",",y,") is in the rectangle")
else:
	print("Point (",x,",",y,") is not in the rectangle")

Demo34

 

 

#Demo34
num = int(input("Enter a three-digit integer: "))
a = num // 100 #百位
b = (num // 10) % 10 #十位
c = num % 10 #个位
x1 = [a,b,c]
x2 = [c,b,a]
if x1 == x2:
	print(num,"is a palindrome")
else:
	print(num,"is not a palindrome")

Demo35

 

 

#Demo35
import math
x,y = eval(input("Enter a point's x- and y- coordinates: "))
s = math.sqrt((0.5 * (0 * 10 + 0 * 0 + 200 * 0 - 0 * 0 - 0 * 0 - 200 * 100))**2)
# print(s)

s1 = math.sqrt((0.5 * (x * 0 + 0 * 100 + 0 * y - x * 100 - 0 * y -0 * 0))**2)
# print(s1)
s2 = math.sqrt((0.5 * (x * 100 + 0 * 0 + 200 * y - x * 0 - 0 * y -200 * 100))**2)
# print(s2)
s3 = math.sqrt((0.5 * (x * 0 + 0 * 0 + 200 * y - x * 0 - 0 * y - 200 * 0))**2)
# print(s3)
if s == s1 + s2 + s3:
	print("The point is in the triangle")
else:
	print("The point is not in the triangle")

Demo36

 

 

#Demo
import math
x1,y1,r1 = eval(input("Enter circle1's center x-, y- coordinates, and radius: "))
x2,y2,r2 = eval(input("Enter circle2's center x-, y- coordinates, and radius: "))
d = math.sqrt((x1 - x2)**2 + (y1 - y2)**2)
if d > r1 + r2:
	print("circle1 和 circle2 外离")
elif d == r1 + r2:
	print("circle1 和 circle2 外切")
elif d < r1 + r2:
	print("circle1 和 circle2 相交")
elif d == math.sqrt((r1 - r2)**2):
	print("circle1 和 circle2 内切")
elif d < math.sqrt((r1 - r2)**2):
	print("circle1 和 circle2 内含")

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值