Jul-12-2023, 10:41 AM
(This post was last modified: Jul-12-2023, 11:16 AM by Gribouillis.)
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:
Newbie here..
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..
Gribouillis write Jul-12-2023, 11:16 AM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.