Using while true with if statement you can make a multiple-choice question in Python. stop the loop if the user enters “Q”.
Example make a multiple-choice question in Python
Simple example code making a very simple multiple-choice story in Python, repeat if neither of the options is selected.
while True: d1a = input("Do you want to: \n A) House. B) Stable. [A/B]? : ") if d1a == "A": print("You approach the cottage.") elif d1a == "B": print("You approach the stables.") elif d1a == "Q": print("Done!") break
Do comment if you have any doubts or suggestions on this Python program code.
Note: IDE: PyCharm 2021.3.3 (Community Edition)
All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.
Degree in Computer Science and Engineer: App Developer and has multiple Programming languages experience. Enthusiasm for technology & like learning technical.
it keeps repeating
Try putting a break after each print line