pythonif-statementfor-else

Issue with if/else statement


I'm fairly new to coding and I've come across a problem I can't figure out or find an answer to.

Basically everytime the user enters yes into the raw_input it spits out the 'if' string but then doesnt exclude the 'else' string.

I'm assuming its because the delay is interfering and I havent set it out correctly because in the code it goes (If, For, Else), maybe the For is hindering the code, I don't know. Would appreciate some help! :)

import sys
import time
string = 'Hello comrade, Welcome!\n'
for char in string:
    sys.stdout.write(char)
    sys.stdout.flush()
    time.sleep(.03)
time.sleep(1)
x=raw_input('Are you ready to enter the fascinating Mists of Verocia? ')
if x == 'yes':
   string = "Verocia was a mystical land located just south of Aborne"
for char in string:
    sys.stdout.write(char)
    sys.stdout.flush()
    time.sleep(.03)
else:
    print ('Please restart program whenever you are ready!')

Solution

  • Please mind the indentation. I think the for loop should be inside the if statement.

    if x == 'yes':
        string = "Verocia was a mystical land located just south of Aborne"
        for char in string:
            sys.stdout.write(char)
            sys.stdout.flush()
            time.sleep(.03)
    else:
        print ('Please restart program whenever you are ready!')