0

Let's say I have if user.lower() == 'start': If they type something wrong, or make a typo, it just ends the program and you have to restart all over. How would I counter that? I know I'll need an else, but what then?

Sorry for long code, all that's relevant is where is says if user.lower() == 'start' to the bottom where the else statement is

    user = input(f"\nJohnny: Well, it's time, {name}. Your very first space trip. How you feeling, man??\nOptions: Good, not so good, bad, scared, nervous: ")
    if user.lower() == 'good':
        print("\nJohnny: That's good to hear! It's a bit nerve-wracking at first, but I promise it's not that bad after a little\n")
        sleep(4)
        print('\nAs you finish talking to Johnny, the sergeant, Mark, comes up to you\n')
        sleep(4)
    elif user.lower() == 'not so good':
        user = input("\nJohnny: Ah, I'm sorry about that. You just nervous?\nOptions: Yeah, Yes, No")
        if user.lower() == "yeah" or "yes":
            print("\nJohnny: Yeah, I get it. I'm sure you'll do just fine! Like I said, I promise it's not all that bad once you're used to it! You can do it!\n")
            print("\nAs you finish talking to Johnny, the general, Mark, comes up to you\n")
            sleep(4)
        elif user.lower() == 'no':
            print("\nJohnny: No? Then I couldn't imagine why you'd not be feeling good, this is a dream for most haha")
            sleep(4)
            print("\nAs you finish talking to Johnny, the general, Mark, comes up to you\n")
    elif user.lower() == 'bad':
        user = input("\nJohnny: Sorry about that, man. I get it, it's your first time going into the giant vacuum of space. You'll be fine!\nOptions: Gee thanks, laugh, or press enter to skip: ")
        if user.lower() == 'gee thanks':
            print('\nGee, thanks, Johnny. What a truly great pep-talk that was! Really eased my nerves -_-')
            sleep(4)
            print("\nJohnny: Haha, you know I'm just messing with you. You'll do great, I swear")
            sleep(4)
            print("As you finish talking to Johnny, the general, Mark, comes up to you\n")
            sleep(4)
        elif user.lower() == 'laugh':
            print("\nHahaha, you're soo funny, Johnny -_-")
            sleep(4)
            print("\nJohnny: I'm just kidding, my guy. I know you're nervous, I was too my first trip up there. You'll do great, I know it")
            sleep(4)
            print('As you finish talking to Johnny, the general, Mark, comes up to you\n')
            sleep(4)
    elif user.lower() == 'nervous':
        print("\nJohnny: Who wouldn't be, let alone on their first time. It takes a brave soul to do what you're about to do")
        print("\nAs you finish talking to Johnny, the general, Mark, comes up to you\n")
        sleep(4)
else:
    print('Invalid, retry')```
  • What have you tried for this problem? Maybe you can show the code. – Shivam Jha Jul 31 '20 at 14:36
  • That's the thing, there's a lot of code. I'll edit the post with a little of it – Sir Lancelot Jul 31 '20 at 14:37
  • @HampusLarsson It might help me some, but I'm not sure it solves it – Sir Lancelot Jul 31 '20 at 14:40
  • 2
    @SirLancelot Read through the accepted answer on the other thread and try to understand the logic there for how they are testing the input from the user. If you're stuck trying to implement one of the solutions in that thread in your own code, try to open a new question with the **minimal** amounts of code to replicate the error. You could also mention in the new post that you're trying to implement a specific solution from there, and try to get more feedback that way. – Hampus Larsson Jul 31 '20 at 14:44
  • @HampusLarsson Yeah, I looked at it more in depth and I think I found a solution, so thanks much for the help – Sir Lancelot Jul 31 '20 at 14:47

0 Answers0