#๐Ÿ”’ Dodoegg

18 messages ยท Page 1 of 1 (latest)

feral garden
#

I don't know how to make a user input something again if the answer is invalid

worthy rainBOT
#

@feral garden

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

last kiln
#

Show what you wrote plz

feral garden
#

okay

#
def error():
    if name1=="":
        print("invalid")
        


def gathering():
    name1=input("input a Proper Noun (name): ")
    error()
    name2=input("input a Proper Noun (name): ")
    error()
    name3=input("input a Proper Noun (name): ")
    error()
    adjective1=input("input an adjective: ")
    error()
    adjective2=input("input an adjective: ")
    error()
    verb1=input("input a past tense verb: ")
    error()
    noun0=input("input a noun (living creature or person-can be made up)-singular: ")
    error()
    noun1=input("input a noun (living creature or person-can be made up)-plural: ")
    error()
    verb2=input("input a past tense verb: ")
    error()
    noun2=input("input a noun (living creature or person-can be made up)-singular: ")
    error()
    verb3=input("input a progressive verb: ")
    error()
    verb4=input("input a verb targetted towards your {noun2}: ")
    error()
    verb5=input(f"input a verb targetted towards your {noun1}")
    error()
    print(f"Once upon a time there were 3 elves. They were named {name1}, {name2}, and {name3}. ")
    print(f"The elves were {adjective1} and {adjective2} and people {verb1} on them. One day a mighty ")
    print(f"{noun0} and with his wand {verb2} them. The elves then awoke as {noun1} and {verb3}")
    print(f" {noun2} that was {verb3}. The {noun1} {verb4} the {noun2} and the {noun2} {verb5} them.")
    print(f"The {noun1} died. The end")
gathering()```
#

if the user inputs for instance "a", i want them to have to input that question again. I don't want to create a miloion loops however

last kiln
#

Maybe start with a single input first.

meager trout
#

you create a function which does the generic task of "keep asking until the user enters something valid", and then use that as your input function

ocean mauve
#

Like how would you define an invalid input

#

or do you just mean if they make a typo and want to go back and enter again

#

I know this wasn't your question but you could do something like this to make your code a little bit less repetitive

def validate() -> bool:
    pass

prompts = [
"input a Proper Noun (name): ",
"input an adjective: "
]
outputs = []

for prompt in prompts:
    while True:
        name = input(prompt)
        if validate(name):
            #the input was valid
            outputs.append(name)
            break
#

@feral garden

upper wedge
ocean mauve
#

oops yes

neat pond
#

!close

worthy rainBOT
#
Python help channel closed for inactivity

This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.