Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

Python Easy Python Help

willp4rry

New Coder
Hi, I just began python and made a dice simulator. I am having the following issues: 1)the random integer is always the same (it is a value from 1 to 6, but within the loop it is always the same). Can I fix this or perhaps this is because I'm using an online interpreter?2) After the loop goes through once, the second input of "Would you like to roll again" (even if yes) will print "ByeBye!" No matter what the response is. I think I need to chance my if input("Would you like to roll again?") != "yes" or "Yes": statement? Any advice would help. Thanks!

Python:
received = input("Type roll to go!")
import random
value = random.randint(1,6)
while received == "Roll" or "roll":
    print(value)
    again = input("Would you like to roll again?")
    if again == "yes" or "Yes":
        print("Ok!")
    if input("Would you like to roll again?") != "yes" or "Yes":
        print("ByeBye!")
        break
else:
    print("mistake!")
 
Last edited by a moderator:
I don't have Python installed here, but maybe this would work:

Python:
import random

received = input("Type roll to go!")
while received == "Roll" or received == "roll":
    value = random.randint(1,6)
    print(value)
    again = input("Would you like to roll again?")
    if again == "yes" or again == "Yes":
        print("Ok!")
        received = "roll"
    else:
        print("ByeBye!")
        received = "stop"
 
Hi @willp4rry,

The reason you always get the same random number is because the code only generates it once since it is not in a repeating loop. To fix this put it at the start of the while loop. Also the reason why it always outputs "ByeBye" is because it is told to do that every time the user inputs yes, whereas it should do that when the user doesn't input yes.

You can also put '.lower()' on the end of the inputs so you only have to check for the lower case inputs. E.g.
Python:
again = input("Would you like to roll again?").lower()
    if again == "yes":

This isn't essential but makes the code more efficient.
 
Last edited:

New Threads

Latest posts

Buy us a coffee!

Back
Top Bottom