import math
import random
#练习1,判断是否润年
def fan():
year = int(input("你问我猜:"))
if (year % 400 == 0) or (year % 4 == 0 and year % 100 != 0):
print("您输入的年份[%d]是润年" % year)
else:
print("您输入的年份[%d]不是润年" % year)
fan()
练习2,输入一个三位数,判断是否为水仙花数abc
def fan():
number = input("请输入3位数")
if int(number) == pow(int(number[0]), 3) + pow(int(number[1]), 3) + pow(int(number[2]), 3):
print("是水仙花数abc")
if int(number) != pow(int(number[0]), 3) + pow(int(number[1]), 3) + pow(int(number[2]), 3):
print("不是水仙花数abc")
fan()
练习3,输入一个5位数,判断是否为回文数abcba
a = input("请输入5个数字:")
if a[0] == a[-1] and a[1] == a[-2]:
print("是回文数")
else:
print("不是回文数")
练习4,输入压大压小,取值1-3为小,4-6为大
def box():
tex = input("请开始下注,压大或者小")
a = random.randrange(1, 7)
print(a)
if a >= 4 and tex == "大" or a <= 3 and tex == "小":
print("恭喜你中了五百万")
if a >= 4 and tex == "小" or a <= 3 and tex == "大":
print("不好意思,没中奖")
box()
import random
#练习1,判断是否润年
def fan():
year = int(input("你问我猜:"))
if (year % 400 == 0) or (year % 4 == 0 and year % 100 != 0):
print("您输入的年份[%d]是润年" % year)
else:
print("您输入的年份[%d]不是润年" % year)
fan()
练习2,输入一个三位数,判断是否为水仙花数abc
def fan():
number = input("请输入3位数")
if int(number) == pow(int(number[0]), 3) + pow(int(number[1]), 3) + pow(int(number[2]), 3):
print("是水仙花数abc")
if int(number) != pow(int(number[0]), 3) + pow(int(number[1]), 3) + pow(int(number[2]), 3):
print("不是水仙花数abc")
fan()
练习3,输入一个5位数,判断是否为回文数abcba
a = input("请输入5个数字:")
if a[0] == a[-1] and a[1] == a[-2]:
print("是回文数")
else:
print("不是回文数")
练习4,输入压大压小,取值1-3为小,4-6为大
def box():
tex = input("请开始下注,压大或者小")
a = random.randrange(1, 7)
print(a)
if a >= 4 and tex == "大" or a <= 3 and tex == "小":
print("恭喜你中了五百万")
if a >= 4 and tex == "小" or a <= 3 and tex == "大":
print("不好意思,没中奖")
box()