Here are my instructions:
Write a program that “flips” a coin repeatedly and displays the results to the screen.

  • The program only stops when a specific # of heads has been flipped. And, that # of heads is specified by the user
  • Your program should output the total number of flips made during execution.
  • So after every flip I need Heads 1, Tails 1, etc.

Here’s my code:

import random

tails= 0

heads_flips= int(input("Enter the amount of flips for heads:"))

while number_of_heads < heads_flips:
    flip= random.randrange(2)
    if flip == heads:
           number_of_heads += 1
           print("Heads", number_of_heads)


Trả lời

Email của bạn sẽ không được hiển thị công khai. Các trường bắt buộc được đánh dấu *