Python Forum
Random module, coin flipping
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Random module, coin flipping
#3
I guess you should be using "i" instead of "pick" in if block condition,

import random
  
numbers = []
#picks 5 random numbers from 0 to 1
while True:
    if len(numbers) == 5:
        break
    pick = random.randint(0,1)
    #print(pick)
    numbers.append(pick)

print(numbers)
#0 == Tails; 1 == Heads
for i in numbers:
    if i == 0:
        print("Tails!")
    else:
        print("Heads!")
Output:
python test.py [0, 0, 1, 0, 1] Tails! Tails! Heads! Tails! Heads!
Best Regards,
Sandeep

GANGA SANDEEP KUMAR
Reply


Messages In This Thread
Random module, coin flipping - by gus17 - Jan-05-2020, 06:58 PM
RE: Random module, coin flipping - by ichabod801 - Jan-05-2020, 07:55 PM
RE: Random module, coin flipping - by sandeep_ganga - Jan-06-2020, 07:26 AM
RE: Random module, coin flipping - by perfringo - Jan-06-2020, 10:29 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Print the frequency of each coin for the combinations that sum to the amount N Pranav 3 2,646 May-19-2020, 06:16 AM
Last Post: Pranav
  Need help with coin change program Gateux 2 6,181 Jun-25-2019, 02:32 PM
Last Post: perfringo
  Adding and Removing coins to match Coin Bag Total infinite times Strayfe 8 4,776 Sep-11-2018, 07:30 PM
Last Post: gruntfutuk

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020