我的一些Python代码有问题。 我意识到这是一个相当懒惰的工作,但我一直试图找出如何返回函数值3小时了。你知道吗
这只是一些代码和函数的摘录:
def main():
another_round = 'y'
print ('''
Hawaiian Beach Bike Hire
''')
while another_round == 'y':
biketype = bikeType()
bikeDays(biketype)
bikeDistance(biketype)
print ('''
days bike rent ($):''',bikeDays(biketype))
print ('extra distance rent ($): ',bikeDistance(biketype))
print ('''
total amount ($):''',bikeDistance(biketype) + bikeDays(biketype))
another_round= input('''
is there anymore bikes to count?''')
def bikeType():
biketype = input ('Bike type ')
if biketype == 'Kids'or biketype == 'kids':
biketype = 15
elif biketype == 'womans'or biketype == 'Womans':
biketype = 20
elif biketype == 'Mens'or biketype == 'mens':
biketype = 25
else:
print ('choose a valid bike')
return biketype
def bikeDistance(biketype):
if biketype == 15:
biked= 1.5
elif biketype == 20:
biked= 2.0
elif biketype == 25:
biked= 2.2
distanceRent = float(input('Distance Traveled '))
bikeAdd = distanceRent * biked
return biketype
main()
我使用biketype
返回大多数函数似乎不对,但其他任何函数都不起作用。你知道吗
这个程序正常运行(即整个程序一起产生正确的计算结果),但是每次在main中调用函数并使用biketype
时,它都会重复要求输入这些部分(行驶的距离等)
有没有办法只返回值而不返回字符串?你知道吗
给你:
问题是在print函数内部调用
bikeDays()
和bikeDistance()
,以及在声明biketype
之后。为了清楚起见,我还把print()
放在一行上。你知道吗相关问题 更多 >
编程相关推荐