2016-04-27 3 views
-5

Ich brauche Hilfe für ein Python-Spiel, das ich gerade erstelle. Wenn der Code ausgeführt wird, bleibt er offen und tut nichts, nachdem er mehrmals umgelegt hat. Hier ist, was ich bisher:Python Heads and Tails

# Heads and Tails generator 
# User how many times they wish to flip a coin and will recieve the results 
CoinTosses = int(input("How many coins do you wish to flip: ")) 
Heads = 0 
Tails = 0 
CurrentCoinToss = 0 
from random import randint 
while CoinTosses != 0: 
    CurrentCoinToss == int(randint(1, 2)) 
    if CurrentCoinToss == 1: 
     Heads += 1 
     CoinTosses -= 1 
    if CurrentCoinToss == 2: 
     Tails += 1 
     CoinTosses -= 1 
print("During this round you recieved: ", Heads, " and", Tails, " Tails!") 
input("Press the enter key to exit") 

Was mit diesem ist falsch? Ich habe meinen Code studiert und nichts sollte falsch sein.

+0

Sie haben eine extra '=' bekam. – TigerhawkT3

+2

Und bitte vermeiden Sie PascalCase und verwenden Sie snake_case für Variablen. In [PEP 8] (https://www.python.org/dev/peps/pep-0008/) finden Sie einen Style Guide für Python Code – Francesco

+0

CurrentCoinToss ist gleich 0, dann CurrentCoinToss == int (randint (1, 2)) vergleicht nur 2 Variablen (ohne es auszudrucken oder etwas mit dem Ergebnis zu tun) –

Antwort

0

Ändern Sie diese Zeile

CurrentCoinToss == int(randint(1, 2)) 

dieser

CurrentCoinToss = int(randint(1, 2)) 
0

In der while-Schleife Sie geschrieben haben:

CurrentCoinToss == int(randint(1, 2)) 

, die tatsächlich den Wert von CurrentCoinToss testet, aber doesn‘ t gib es einen Wert.

Veränderung durch:

CurrentCoinToss = int(randint(1, 2))