Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/280.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 巨蟒头尾_Python - Fatal编程技术网

Python 巨蟒头尾

Python 巨蟒头尾,python,Python,我需要帮助我目前正在创建的Python游戏。当运行代码时,它将保持打开状态,并在输入多次翻转后不执行任何操作。以下是我到目前为止的情况: # 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 Tai

我需要帮助我目前正在创建的Python游戏。当运行代码时,它将保持打开状态,并在输入多次翻转后不执行任何操作。以下是我到目前为止的情况:

# 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")
这有什么问题?我已经研究了我的代码,没有任何错误。

更改此行

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

CurrentCoinToss = int(randint(1, 2))

在您编写的while循环中:

CurrentCoinToss == int(randint(1, 2))
它实际上测试currentCointost的值,但没有给它一个值

更改为:

CurrentCoinToss = int(randint(1, 2))

您有一个额外的=。请避免使用PascalCase,并对变量使用snake\u case。请参阅,以获取Python codeCurrentCointost=0的样式指南,然后CurrentCointost==intrandint1,2只比较2个变量,而不打印出来或对结果执行某些操作。下一次,您应该尝试调试代码,而不只是研究它。如果您添加了一些额外的print语句来监视正在发生的事情,或者用于逐行遍历代码并观察变量发生了什么,那么您很快就会发现currentcointos从未更改过。