Home > Mobile >  Trying to create a program that tracks which inputs I've added but stuck
Trying to create a program that tracks which inputs I've added but stuck

Time:10-21

Basically I'm trying to get my program to loop back to main_screen after entering a screen_number, repeating indefinitely until I press T to terminate it. Meanwhile P is supposed to track how many numbers I've imputed throughout the session. This is what I have so far and I only know how to loop screen_number. Just can't figure out how to loop back to main_screen or how to go about making the "P" function.

main_screen = str(input("Pick W to add a new number, P to show how many numbers, high or low, have been added, or T to terminate: "))
if(main_screen == "W"):
    screen_number = int(input("Input your grade: "))    
    if(screen_number >= 10):
        print("It's high.")
    elif(user_grade < 10):
        print("It's low.")
if(user_menu == "T"):
    print("Terminating system.")
else:
    print("Invalid.")```

CodePudding user response:

Try this:

while True:
    main_screen = input("Pick W to add a new number\nP to show how many numbers high or low have been added\nT to terminate: ")
    if main_screen == "W":
        user_grade = int(input("Input your grade: "))    
        if user_grade >= 10:
            print("It's high.")
        elif user_grade < 10:
            print("It's low.")
    elif main_screen == "T":
        print("Terminating system.")
        break
    else:
        print("Invalid.")

CodePudding user response:

Try looping with a condition and break when the correct input is entered:

while True:
    main_screen = str(input("Pick W to add a new number, P to show how many numbers, 
    high or low, have been added, or T to terminate: "))
    if(main_screen == "W"):
        screen_number = int(input("Input your grade: "))    
    if(screen_number >= 10):
        print("It's high.")
    elif(user_grade < 10):
        print("It's low.")
    if(user_menu == "T"):
        print("Terminating system.")
        return
    else:
        print("Invalid.")
  • Related