mardi 23 février 2021

Jupyter Notebook - Random Module Flip a coin

I'm very new to this website and I am a novice at Python, I've just started. This may have been asked many times now, but I'm not sure why the following code is not running:

import random

output={"Heads":0, "Tails":0}
coin=list(output.keys())

for a in range(10000):
    output[random.choice(coin)]+=1
    
print("Heads:", output["Heads"])
print("Tails:", output["Tails"])

Expected Result : It should randomly give you the total of how many times it was heads and tails whilst flipping the coin 10,000 times.

Actual Result: TypeError: 'list' object is not callable

I've googled this problem and it seems you have to use a square bracket but I'm not sure where to amend this. This code works for Python IDLE but not for Jupyter Notebook.

Any help would be much appreciated, thank you.

Peter.




Aucun commentaire:

Enregistrer un commentaire