-1

The code runs fine up to the point where it asks you if you want to keep playing. As of now, no matter what you type in it will go through the prompt again. I need it to run again if you type anything that starts with y, and break if anything else is typed

while(str(guess) == str(random_num)):
    if(int(num_sum) <= int(1)):
        print("You got it right in 1 guess!")
        again = str(input("Would you like to play again? "))
        print()
        return prompt()
    elif(int(num_sum) > int(1)):
        print("you got it right in " + str(num_sum) + " guesses! ")
        again = str(input("Would you like to play again? "))
        return prompt()
    if(str(again.startswith)("y") or ("Y")): #am I using the "startswith" feature wrong?
        print()
        return prompt()
    else:
        print("Overall Results")
        break
  • 1
    What is in the function `prompt()`? It's pretty difficult to imagine what the rest of your code might be doing and how it combined with this code has an issue. Can you post more complete code? See [this](http://stackoverflow.com/help/mcve) page for details on producing a good code example. – Paul Rooney Feb 22 '17 at 02:07
  • try using regEx to compare user input with either 'Y','y' or 'N','n'. – Vrushank Doshi Feb 22 '17 at 02:47
  • @VrushankDoshi - No. – TigerhawkT3 Feb 22 '17 at 02:56

1 Answers1

-1
def prompt():
    constant_1 = 1
    constant_2 = 100
    random_num = (randint(constant_1, constant_2))
    im_thinking = ("I'm thinking of a number between" +
    (" ") + str(constant_1) + (" ") + ("and") + (" ") + str(constant_2) + ("..."))
    print(im_thinking)
    print(random_num)
    guess = int(input("Your guess? "))
    num_sum = 1
    while((str(guess)  != str(random_num))):
    num_sum = num_sum + 1
        if (str(guess) > str(random_num)):
        print("It's lower.")
        guess = int(input("Your guess? "))      
        elif (str(guess) < str(random_num)):
        print("It's higher.")
        guess = int(input("Your guess? "))
    else:
        guess = False