Roshan Christison
Roshan Christison

Reputation: 5

Why does my program just stop in Python with no error?

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.

Upvotes: 1

Views: 253

Answers (1)

Gagan T K
Gagan T K

Reputation: 728

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.

Upvotes: 1

Related Questions