Python Forum

Full Version: Module Result
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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
Output:
Python 3.11.4 (tags/v3.11.4:d2340ef, Jun 7 2023, 05:45:37) [MSC v.1934 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license()" for more information. = RESTART: C:/Users/hp/Desktop/Pythoncodes/rdmhead.tails.py Heads: 1 Tails: 1 =========== RESTART: C:/Users/hp/Desktop/Pythoncodes/rdmhead.tails.py ========== Heads: 1 Tails: 1 =========== RESTART: C:/Users/hp/Desktop/Pythoncodes/rdmhead.tails.py ========== Heads: 1 Tails: 1 Expected Results: =========== RESTART: C:/Users/hp/Desktop/Pythoncodes/rdmhead.tails.py ========== Heads:4993 Tails:5007 =========== RESTART: C:/Users/hp/Desktop/Pythoncodes/rdmhead.tails.py ========== Heads:5080 Tails:4920 =========== RESTART: C:/Users/hp/Desktop/Pythoncodes/rdmhead.tails.py ========== Heads:4912 Tails:5061
Is there some revision on the code required to get the same result as the textbook example?
Newbie here..
The problem is where you assign the value to 1 (= +1) instead of incrementing the value (+= 1).