Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need help with Loop.
#1
Hello!

This is my first post so I apologize if Ive done this incorrectly.

I am a beginner and this is only my third day of learning python. I attempted to create my first mini game(without looking online for help) where it asks "What is your guess?" for what you think the dice will roll and it will reveal the answer, then print if you won or lose.

I created that pretty quickly but realized I wanted it to ask if the player wanted to play again. So I created a function and initially thought it worked but actually after the second time through the program ends.

My question is why does it end after the second play through and how can I fix this?





import random
import time


user_answer = input("Would you like to try and guess the number the dice will roll? : ")

def guess_number():

    dice_sides = ["1", "2", "3", "4", "5", "6"]



    r_roll = random.choice(dice_sides)

    if user_answer == "yes" or "Yes":
        print("Excellent, lets play!")

    else:
        print("Okay, have a great day!")

    user_guess = input("What is your guess? : ")



    time.sleep(1)

    print("The number is.....")

    time.sleep(1.5)

    print(r_roll)

    if user_guess == r_roll:
     print("Congrats! You won!")

    else:
     print("Sorry, you lose....")

guess_number()

again = input("Do you want to play again? : ")

if again == "yes" or "yes":
    guess_number()
else:
    print("Have a good day!")
Reply


Messages In This Thread
Need help with Loop. - by gnosticwhispers - Apr-01-2020, 07:42 PM
RE: Need help with Loop. - by deanhystad - Apr-01-2020, 08:39 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020