year =input("请输入年份:")# 判断用户输入的是否为数字if year.isdigit():
year =int(year)if year %4==0:print(str(year)+"是闰年")else:print(str(year)+"不是闰年")else:print("请输入年份!!")
请输入年份:2000
2000是闰年
"1"+1
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-8-ec358fc6499a> in <module>
----> 1 "1" + 1
TypeError: can only concatenate str (not "int") to str
import random
secert = random.randint(1,100)# 计算机生成一个随机数
times =3# 初始化用户的次数是3while times:
num =input("请输入数字: ")if num.isdigit():
temp =int(num)if temp == secert:print("你猜对了!!")breakelif temp < secert:print("你的数字太小了")
times = times -1else:print("你的数字太大了")
times = times -1else:print("请输入数字!!")print("你的机会用完了")