Aleksik Aleksik - 6 months ago 16
Python Question

Define a function or loop, which restarts if given integer-parameter is less than X, or refuses to accept value less than 3

I'm writing a simple program where a person can go on a trip, but the trip has to last

days minimum. The whole program has more parts which all work well, and the whole program works, but now I want to enhance it and set the minimal parameter value of function

In it's most basic form, my function is:

def hotel_cost(days):
# hotel costs 140$ per day
return 140 * int(days)

And the above obviously works, but I want to change it so that it does not accept less than 3.

I'm experimenting with while and a boolean but it gives me
, and I've also faced accidental infinite recursion. Sorry if this question is too basic, it's my first one. I tried searching but to no avail.


Your can condense asking the user for the number of days, and giving them there price in in one function.

def ask_num_hotel_days():
    i = int(input("Enter nuber of days: "))
    while(i < 3):
        print(str(i) + " is not a valid number of days")
        i = int(input("Enter nuber of days: "))
    return 140 * i