【Python新手求助】关于字符串拼接
temp = input("请输入一个年份:")while not temp.isdigit():
temp = ("您的输入有误,请重新输入一个整数:")
year = int(temp)
if (year/4) == int(year/4) and (year/100) == float(year/100):
print(temp +"年是普通闰年.")
if (year/100) == int(year):
print(temp +"年是世纪闰年.")
为什么在拼接字符串的时候用temp可以正常拼接,而用year却不行?
temp = input("请输入一个年份:")
while not temp.isdigit():
temp = ("您的输入有误,请重新输入一个整数:")
year = int(temp)
if (year/4) == int(year/4) and (year/100) == float(year/100):
print(year +"年是普通闰年.")
if (year/100) == int(year):
print(year +"年是世纪闰年.")
因为字符串拼接是字符串与字符串,而 year 是整形,不能拼接
页:
[1]