Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

Python Best way to rerun this snippet of code:

paracelx

New Coder
New to python3 working on a fantasy character generator, tyring to find the best way to rerun the snippet of code if the wrong letters are entered in input.
Thanks for any help you can give me.
Python:
#Code to exit or reginirate script
quittogen = input("""\nDo you want to quit or generate another creature?
 Type q to quit or g to generate a new creature.""")

if str(quittogen) == "q" or str(quittogen) == "Q":
    input("Thank you for using the Fantasy Creature Generator.")
elif str(quittogen) == "g" or str(quittogen) == "G":
    print("Generating New Creature\n")
else:
    if str(quittogen) != "q" or str(quittogen) != "g" or \
    str(quittogen) != "Q" or str(quittogen) != "Q":
        quittogen = input("""\nDo you want to quit or generate another
 creature? Type q to quit or g to generate a new creature.""")
 #Need a else code here to repeat the whole upper code
 
Python:
while True:
    print('q to quit or g to generate another')
    myinput = input('>> ')

    if myinput.lower() in ['q', 'quit'] :
        print('Thanks for playing')
        break
    elif myinput.lower() in ['g', 'generate']:
        print('Generating new character')
    else:
        print('That is not a valide character.\nPlease try again.')
 

New Threads

Buy us a coffee!

Back
Top Bottom