Get the most out of your questions with IDNLearn.com's extensive resources. Ask anything and receive prompt, well-informed answers from our community of knowledgeable experts.

If anyone knows how to code on python:
I need to write a program that asks the user for two dice rolls and will tell the user to advance the number spaces coressponeing to the total rolled.

Etc.
Enter first roll: 4
Enter second roll: 6
Advance 10 spaces

The code should include a message for invalid rolls, and should also tell the user to roll again if they roll the same two numbers. Someone please help me out!


Sagot :

Answer:

def dice_roller():

   # ask for first input

   input1 = int(input("Enter the first roll: "))

   # check if it's valid

   while input1 < 1 or input1 > 6:

       print("Invalid number")

       # ask for new input if the previous was invalid

       input1 = int(input("Enter the first roll: "))

   # ask for second input

   input2 = int(input("Enter the second roll: "))

   # check if it's valid

   while input2 < 1 or input2 > 6:

       print("Invalid number")

       # ask for new input if the previous was invalid

       input2 = int(input("Enter the second roll: "))

   # check of the numbers are the same

   if input1 == input2:

       print("You rolled the same numbers. Try again")

       # if they are the same call this function again to get new numbers

       dice_roller()

   else:

       # print how many spaces to advance

       print("Advance", input1+input2, "spaces")

if __name__ == '__main__':

   dice_roller()

View image Kenshri1