![]() |
Module Result - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Module Result (/thread-40330.html) |
Module Result - EddieG - Jul-12-2023 I have been writing this code which must result in different result after running the code for heads and tails. I am having only one same result each time and not random. code: import random output={"Heads":0, "Tails":0} coin=list(output.keys()) for i in range(10000): output[random.choice(coin)]=+1 print("Heads:", output["Heads"]) print("Tails:", output["Tails"])Result in IDLE Shell 3.11.4 Is there some revision on the code required to get the same result as the textbook example?Newbie here.. RE: Module Result - deanhystad - Jul-12-2023 The problem is where you assign the value to 1 (= +1) instead of incrementing the value (+= 1). |