Ниже приведены три функции, которые вычисляют стоимость отпускаемых пользователей. Пользователю предлагается ввести детали своего праздника, которые затем передаются в функции в качестве аргументов.Почему я не могу передать эту переменную типа int в качестве аргумента в Python?
def hotel_cost(days):
days = 140*days
return days
"""This function returns the cost of the hotel. It takes a user inputed argument, multiples it by 140 and returns it as the total cost of the hotel"""
def plane_ride_cost(city):
if city=="Charlotte":
return 183
elif city =="Tampa":
return 220
elif city== "Pittsburgh":
return 222
elif city=="Los Angeles":
return 475
"""this function returns the cost of a plane ticket to the users selected city"""
def rental_car_cost(days):
rental_car_cost=40*days
if days >=7:
rental_car_cost -= 50
elif days >=3:
rental_car_cost -= 20
return rental_car_cost
"""this function calculates car rental cost"""
user_days=raw_input("how many days would you be staying in the hotel?") """user to enter a city from one of the above choices"""
user_city=raw_input("what city would you be visiting?") """user to enter number of days intended for holiday"""
print hotel_cost(user_days)
print plane_ride_cost(user_city)
print rental_car_cost(user_days)
Я заметил, что когда я печатаю функции выше, только plane_ride_cost (user_city) работает правильно. Остальные две функции выплевывают тарабарщину. Почему это?
'raw_input' возвращает строку, а не INT –
Поскольку у вас нет каких-либо«переменные типа INT». У вас есть только строки. –
Связанный - http://stackoverflow.com/questions/3536996/multiplying-a-string-with-a-number-in-python –