Python Forum
nested while loop flow help
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
nested while loop flow help
#1
def car_rental():
    exceeded_period_invalid = True
    while exceeded_period_invalid:
    
        daily_rental_period_requested_is_invalid = True
        while daily_rental_period_requested_is_invalid:          
            print()
            daily_rental_period = int(input("Enter the number of days requested: "))
            print()
            if daily_rental_period < 0:
                print ("Please enter a number greater than 0: ")
            if daily_rental_period > 180:
                print ("The rental period exceed 180 days try a lower amount: ")
            else:
                daily_rental_period_requested_is_invalid = False

        weekly_rental_period_requested_is_invalid = True
        while weekly_rental_period_requested_is_invalid:  
            print()
            weekly_rental_period = int(input("Enter the number of weeks requested: "))
            print()
            if weekly_rental_period < 0:
                print ("Please enter a number greater than 0: ")
            if weekly_rental_period > 25:
                print ("The rental period exceed 180 days try a lower amount: ")
            else:
                weekly_rental_period_requested_is_invalid = False
        
        # Convert weeks in to days
        converted_weekly_rental_to_day = weekly_rental_period // 7                      
        total_daily_rental_period = converted_weekly_rental_to_day + daily_rental_period

        # Add converted days to customer day input and check if total exceed 180 days 
        total_rental_period = total_daily_rental_period + daily_rental_period

    if total_daily_rental_period > 180:
            print ("The rental period exceeded 180 days try a lower amount: ")
            exceeded_period_invalid = False

    #for debugging only        
    print("exceeded period loop",exceeded_period_invalid,)
    print("daily invalid loop",daily_rental_period_requested_is_invalid)
    print("weekly invalid loop",weekly_rental_period_requested_is_invalid)



car_rental()
hi

i got a 1 main while loop, inside of it i have 2 while loops, it adds the result of the two inner and if it exceeds 180 days then the main loops runs again and ask the customer gain.

everything is fine untile you reach:

    if total_daily_rental_period > 180:
            print ("The rental period exceeded 180 days try a lower amount: ")
            exceeded_period_invalid = False


it eihter ignores it or gets an error depending on indentation level

and cant use other python features, this professor is a moron. Big Grin
Reply


Messages In This Thread
nested while loop flow help - by Ponamis - Nov-02-2018, 10:21 PM
RE: nested while loop flow help - by j.crater - Nov-02-2018, 10:46 PM
RE: nested while loop flow help - by Ponamis - Nov-02-2018, 11:01 PM
RE: nested while loop flow help - by j.crater - Nov-02-2018, 11:15 PM
RE: nested while loop flow help - by Ponamis - Nov-02-2018, 11:22 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Bug Need help on this nested loop task PP9044 4 4,731 Apr-16-2021, 01:31 PM
Last Post: perfringo
  Nested if stmts in for loop johneven 2 5,936 Oct-19-2019, 04:05 AM
Last Post: xeedon
  Nested for loop issue always using index 0 searching1 2 2,639 Dec-30-2018, 09:17 AM
Last Post: searching1
  Nested loop Tryhard20 3 5,785 Sep-05-2018, 04:57 AM
Last Post: volcano63
  Inflow watertank before outward flow starts orjstrand 6 5,052 May-02-2018, 11:31 AM
Last Post: j.crater
  Nested Loop multiplication table SushiRolz 3 10,308 Feb-28-2018, 04:34 AM
Last Post: Larz60+
  Nested Loop to Generate Triangle Babbare 12 11,915 May-29-2017, 05:00 AM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020