-1

So I am an beginner to Python and I self-taught some basic stuff. So i'm trying to create an Quiz game and on the menu you need to put in the number to corresponds to one of the options. So if you wanted to play an quiz, you'd type 1. But one thing is that I made it so if let's say instead of typing 1 or 2 you type in "i amz rebels lol" it would simply just do the input again till it get's 1 or 2. While this works, I would like it to be more cleaner. So is there an way that if I said "lol" it would delete the text of it saying lol and basically replace it with the input? So instead of input making a new line it would delete the "lol" and then do the input. If there isn't is there any workarounds to this? If it's needed here's the code i have so far.

print("========================")
print("=         Quiz!        =")
print("========================")
print("    1 = Play Quiz.")
print("    2 = Quiz Maker")
while True:
 menu = input()
 if menu == "1":
  print("1")
 elif menu == "2":
  print("2")
 else:
  continue
Jacklack3
  • 9
  • 4
  • Please clarify what you are asking – Dan Mar 23 '17 at 02:14
  • from what i understand here even if you put 1 or 2 the input should show again as it is always True – Mayeul sgc Mar 23 '17 at 02:17
  • So basically, when it asks for an input and you answer it, it will keep the input on the screen. It will loop back since you didn't answer correctly but it would do it on the next line. What I want is if you don't do the input right instead of asking again but on the next line, it would delete the input and ask it again on THAT line. Sorry if i'm being confusing. – Jacklack3 Mar 23 '17 at 02:18
  • 1
    (made a gif to explain it. http://i.imgur.com/f3ze0UP.gif) – Jacklack3 Mar 23 '17 at 02:20
  • @Jacklack3 The answer to this question will do exactly that -> [remove last STDOUT line in Python](http://stackoverflow.com/questions/12586601/remove-last-stdout-line-in-python), just be sure to use the `print` statement in the [first comment](http://stackoverflow.com/questions/12586601/remove-last-stdout-line-in-python#comment16961903_12586667) – chickity china chinese chicken Mar 23 '17 at 02:39
  • 1
    exact duplicate of [remove last STDOUT line in Python](http://stackoverflow.com/questions/12586601/remove-last-stdout-line-in-python) – chickity china chinese chicken Mar 23 '17 at 02:40
  • Possible duplicate of [remove last STDOUT line in Python](http://stackoverflow.com/questions/12586601/remove-last-stdout-line-in-python) – Kevin J. Chase Mar 23 '17 at 03:52

1 Answers1

0

The best alternative I could find is to use os.system("cls"):

import os
def menu():
    print("========================")
    print("=         Quiz!        =")
    print("========================")
    print("    1 = Play Quiz.")
    print("    2 = Quiz Maker")

while True:
    menu()
    prompt = input()
    if menu == "1":
        os.system("cls")
        print("1")
    elif menu == "2":
        os.system("cls")
        print("2")
    else:
        os.system("cls")
Community
  • 1
  • 1