1

Compiler just stops enter image description here

import time
import random

def game():
    score1=0
    score2=0
    name1=input("Player 1, please enter your name: ")
    time.sleep(0.5)
    name2=input("Player 2, please enter your name: ")
    time.sleep(0.5)
    print(name1, "rolls two dice")
    dice1=random.randint(0,6)
    dice2=random.randint(0,6)
    time.sleep(0.5)
    if dice1 == dice2:
        print(name1, "rolled a double! They may roll a third dice, whatever number they roll will be the number of points they earn.")
        dice3=random.randint(0,6)
        score1=score1+dice3
        print(name1, "rolled", dice3)
    else:
        total=dice1+dice2
        if (total % 2) == 0:
            score1=score1+10
        else:
            score1=score1-5

#Start
goes=0
while goes >10:
    goes=0+1
    game()

When I run my code it works until it rolls two dice, which is when it just stops, the compiler returns to its opening state. I'm not sure what I'm doing wrong either, help will be greatly appreciated.

4
  • goes will never equal 10, not entirely sure what the issue is you're trying to solve though Commented Jan 16, 2020 at 10:13
  • you have problem is here goes=0+1 you keep restarting Commented Jan 16, 2020 at 10:13
  • unfinished yet, sorry i should have clarified. Commented Jan 16, 2020 at 10:14
  • each iteration players are asked for names. Maybe make getting names a seperate function and call it only once? Then roll as many dice as you want with goes+=1 Commented Jan 16, 2020 at 10:15

1 Answer 1

1

There are 2 things you have to fix here.

  1. while goes > 10 This should be while goes < 10. goes is initially 0, and your condition checks for goes greater than 10, which will never work and wont enter while loop.

  2. goes=0+1 This should be goes = goes + 1 or goes += 1. You code will set goes to 1 every time it enters while loop.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.