Issue
def get_fare(mini, maxi):
fare = float(input("travel fare please: "))
while fare not in range(mini, maxi+1):
print("invalid value, please enter a new one")
fare = float(input("travel fare please: "))
return fare
travel_fares = [get_fare(5,20), get_fare(5,20), get_fare(5,20)] # list of the functions
average = sum(travel_fares)/len(travel_fares)
print (average)
I want to change this format where the user can input many fares instead 3. If I am to use list form, how can should I make the changes?
thank you
Solution
Use a loop or list comprehension.
how_many = int(input("How many fares?"))
travel_fares = [get_fare(5, 20) for _ in range(how_many)]
Answered By - Barmar
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.