它不断出现SyntaxError:
编译一条语句时发现多个语句。
name=input("Hi, what is your first name?")
age=int(input("How old are you?")
days=365
days=int(365)
days = days * age
print(name,"is",days," days old.")
hours=8760
hours=int(8760)
hours = hours * age
print(name,"is",hours,"hours old.")
minutes=525600
minutes=int(525600)
minutes = minutes * age
print(name,"is",minutes,"minutes old.")
seconds=31536000
seconds=int(31536000)
seconds = seconds * age
print(name,"is",seconds,"seconds old.")
您在age = int(input("How old are you?")
行缺少右括号。另外,您需要使用str
运算符包装小时,分钟,秒,类似于使用int(days)
进行包装,并在打印语句中用+
符号替换逗号。
更正后的代码如下:
name = input("Hi, what is your first name?")
age = int(input("How old are you?"))
days = 365
## Not Needed days=int(365)
days=days * age
print(name + " is" + str(days) + " days old.")
hours=8760
hours=int(8760)
hours=hours * age
print(name + " is" + str(hours), " hours old.")
minutes=525600
minutes=int(525600)
minutes=minutes * age
print(name + " is" + str(minutes) + "minutes old.")
seconds=31536000
seconds=int(31536000)
seconds=seconds * age
print(name + " is", str(seconds) + "seconds old.")