Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7667391
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T15:05:26+00:00 2026-05-31T15:05:26+00:00

In Python 3.2, I’m writing up a basic menu program, and when the option

  • 0

In Python 3.2, I’m writing up a basic menu program, and when the option to quit is entered, the function is not ending.
When quit is chosen, it ends the loop the rest of the script is in, and should terminate the script, but it isn’t, for whatever reason?
Am I missing an ‘end’ function that kills the script, or is the new Python Shell just buggy?
Pretty sure this wasn’t necessary in Python 2.7.

import random
choice = str(input("\nMenu:\n(I)nstructions\n(C)alculate blah\n(Q)uit\n>>>"))
while choice != "q" or choice != "Q":
    while choice != "i" and choice != "I" and choice != "c" and choice != "C" and choice != "q" and choice != "Q":
        print("Invalid menu choice.")
        choice = str(input("\nMenu:\n(I)nstructions\n(C)alculate blah\n(Q)uit\n>>>"))
    if choice == "i" or choice == "I":
        print("blahblah.")
        choice = str(input("\nMenu:\n(I)nstructions\n(C)alculate blah\n(Q)uit\n>>>"))   
    if choice == "c" or choice == "C":
        x = int(input("Please enter the number of x: "))
        while x < 0:
            x = int(input("Please enter the number of x: "))
        y = int(input("Please enter the number of y: "))
        while y < 0:
            y = int(input("Please enter the number of y: "))
        z = str(input("blah (B) or (P) z?: "))
        while z != "b" and z != "p" and z != "B" and z != "P":
            z = str(input("blah (B) or (P) z?: "))
        if z == "b" or z == "B":
            total = x*10 + y*6 + 0
            print("blah $", total, " blah ", x, " x and ", y, " y. blah!")
        #function that outputs the cost of premium z
        if z == "p" or z == "P":
            luck = random.randrange(1, 11, 1)
            if luck == 10:
                total = x*10 + y*6
                print("\nblah$", total, " blah z for ", x, " x and ", y, " y. blah!")
            #below is the normal function, for when the customer is not a lucky winner
            if luck != 10:
                total = x*12.50 + y*7.50
                print("blah $", total, " blah ", x, " x and ", y, " y. blah!")
        choice = str(input("\nMenu:\n(I)nstructions\n(C)alculate\n(Q)uit\n>>>"))
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T15:05:28+00:00Added an answer on May 31, 2026 at 3:05 pm

    Your condition is wrong:

    while choice != "q" or choice != "Q":    # this should be "and"!
    

    always returns True, creating an infinite loop.

    Also, you’ve got quite a convoluted bit of logic here. This can be simplified a lot:

    import random
    while True:
        choice = str(input("\nMenu:\n(I)nstructions\n(C)alculate blah\n(Q)uit\n>>>")).lower()
        if choice == "i":
            print("blahblah.")
            continue
        elif choice == "q":
            break
        elif choice == "c":
            while True:
                x = int(input("Please enter the number of x: "))
                if x >= 0: break
            while True:
                y = int(input("Please enter the number of y: "))
                if y >= 0: break
            while True:
                z = str(input("blah (B) or (P) z?: ")).lower()
                if z in "bp": break
            if z == "b":
                total = x*10 + y*6 + 0
                print("blah $", total, " blah ", x, " x and ", y, " y. blah!")
            #function that outputs the cost of premium z
            else:  # z must be "p"
                luck = random.randrange(1, 11, 1)
                if luck == 10:
                    total = x*10 + y*6
                    print("\nblah$", total, " blah z for ", x, " x and ", y, " y. blah!")
                #below is the normal function, for when the customer is not a lucky winner
                if luck != 10:
                    total = x*12.50 + y*7.50
                    print("blah $", total, " blah ", x, " x and ", y, " y. blah!")
        else:
            print("Invalid menu choice.")
            continue
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

python newbie here. I'm writing the code to control an experiment that has multiple
Python code: for i in xrange(10): for j in xrange(5): pass # The for-loop
Python has heapq module which implements heap data structure and it supports some basic
Python 2.6 introduced a next function. Why was this necessary? One could always type
Python's file.read() function won't read anything. It always returns '' no matter what's inside
Python's access to environment variables does not accurately reflect the operating system's view of
Python metacharacter negation. After scouring the net and writing a few different syntaxes I'm
Python newbie here. I'm writing a script that can dump some output to either
Python 3.2 documentation refers to Collin Winter's functional module which contains function compose :
Python newbie here: I'm writing a market simulation in Python using Pysage, and want

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.