我是Python新手,正在探索一个简单的辅助项目,以了解函数和循环是如何工作的。你知道吗
我这里有密码
age = 0
def ageInMonths (age):
months = int(age) * 12
return print('You are ' + str(months) + ' months old!')
def ageInDays(age):
days = int(age)*365
return print('You are ' + str(days) + ' days old!')
def ageInHrs(age):
hrs = int(age)* 8765.81
return print('You are ' + str(hrs) + ' hours old!')
def ageinMin(age):
minutes = int(age)* 525948.8
return print('You are ' + str(minutes) + ' minutes old!')
def ageinSec(age):
sec= int(age)* 31556926
return print('You are ' + str(sec) + ' seconds old!')
def agePrint(age):
age=age
ageInMonths(age)
ageInDays(age)
ageInHrs(age)
ageinMin(age)
ageinSec(age)
print('Done')
return
while age != 99:
print( 'Please enter your age?')
age = input()
if age == 99:
break
print('You are ' + age + ' years old!')
agePrint(age)
每次输入99,while循环都不会中断。任何关于我哪里出错的建议。。你知道吗
您忘记将输入转换为
int
:如果不显式地这样做,
age
将是一个字符串,自然'99' != 99
。你知道吗相关问题 更多 >
编程相关推荐