Question

Please help me put this in order!! THANKYOU!!

(CO 4 and 6) Create a program with a function named flipCoin that will flip a coin as many times as the user asks. The flipCoin function should return “heads” or “tails”. The program should continue while the user presses Y.

SAMPLE OUTPUT:

How many times do you want to flip a coin? 5

You got: tails

You got: tails

You got: tails

You got: tails

You got: heads

To continue press Y: Y

How many times do you want to flip a coin? 3

You got: heads

You got: tails

You got: tails

To continue press Y: N

flips = int(input(How many times do you want to flip a coin?)) if(flip== 1); [Choose cont=Y while cont==Y: [Choose] [Ch

0 0
Add a comment Improve this question Transcribed image text
Answer #1

The required sequence of statements is given below. Thumbs Up please if it helps. :)

1)import random
2)#flip coin function returns a heads or tails depending on what is flipped
3)def flipCoin():
4) flip = random.randint(1,2);
5) if(flip == 1):
6) return "heads"
7) else:
8) return "tails"
9)def main():
10) cont = "Y"
11) while(cont == "Y"):
12) flips = int(input("How many times do you want to flip a coin? "))
13) for i in range(0,flips):
14) print("You got",flipCoin())
15) cont = input("To continue press Y : ").upper()
16)if __name__ == '__main__':
17) main()

SEE SCREENSHOT LINE NUMBER TELLS SEQUENCE

Run Debug Stop e Share A Save Beautify Language Python 3 @ main.py 1 import random 2 #flip coin function returns a heads or t

Run Debug Stop e Share A Save Beautify Language Python 3 @ main.py 1 import random 2 #flip coin function returns a heads or tails depening on what is flipped 3- def flipCoin(): flip = random.randint(1,2); if(flip == 1): return "heads" else: return "tails" 9 def main(): cont = "/" while(cont == "Y"): flips = int(input("How many times do you want to flip a coin? ")) for i in range(@,flips): print("You got",flipCoin()) cont = input("To continue press Y: ").upper() 16 if _name__ == '_main__': 17 main() 13 - 15 input How many times do you want to flip a coin? 5 You got tails You got tails You got tails You got heads You got tails To continue press Y: Y How many times do you want to flip a coin? 3 You got heads You got tails You got tails To continue press Y : N ... Program finished with exit code o Press ENTER to exit console.

Add a comment
Know the answer?
Add Answer to:
Please help me put this in order!! THANKYOU!! (CO 4 and 6) Create a program with...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a function that flips a coin; it returns heads or tails. Use that function to...

    Write a function that flips a coin; it returns heads or tails. Use that function to write a GetHeadsInARow functions that accepts the number of heads to roll in a row before you return with total rolls it took to get that number of heads in a row. Please Code in Python3 my attempt below will not print out the answer and I do not know why def HeadTails(): from random import randrange """Will simulate the flip of a coin."""...

  • In C++ please Create a coin-flipping game. Ask the user how many times to flip the...

    In C++ please Create a coin-flipping game. Ask the user how many times to flip the coin, and use the random function to determine heads or tails each time a coin is flipped. Assume the user starts with $50. Every time the coin is flipped calculate the total (heads +$10, tails -$10). Create another function to test if the user has gone broke yet (THIS FUNCTION MUST RETURN A BOOLEAN TRUE/FALSE VALUE). End the program when the user is broke...

  • Write a C program that prompts the user for the number for times the user wants...

    Write a C program that prompts the user for the number for times the user wants to flip a coin. Your program will flip a virtual coin that number of times and return the following: 1) The number of times heads occurred. 2) The number of times tails occured. Then take the coin flip program and modify the random number generator to roll a single 6-sided dice.   DO NOT DISPLAY THE RESULTS OF EACH ROLL. 1) Ask the user how...

  • Practice: • function • loops • if condition • random Roll a dice many times, you...

    Practice: • function • loops • if condition • random Roll a dice many times, you will see that each face value will count of roughly 1/6 • write a function • roll a dice once, return value will be 1-6, • use your functin I call your function 6000 times • count how many times of face 1 • count how many times of face 2 • print out the numbers of total face 1, 2, ..., 6 you...

  • Write a program that simulates the toss of a coin. Whenever a coin is tossed the...

    Write a program that simulates the toss of a coin. Whenever a coin is tossed the result will be either a head or tail. Prompt the user as shown by entering an ‘H’ for heads or ‘T’ for tails. Use a loop for input validation of an ‘h’ or ‘t’. Make sure that both an upper case and lower case will be accepted. Have the computer generate a random number. Assign a char variable a (‘h’ ^ ’t’) head or...

  • (Microsoft Visual Source, C++, Course: CIS-5, Intro to Programming) Write a program that starts a player...

    (Microsoft Visual Source, C++, Course: CIS-5, Intro to Programming) Write a program that starts a player off with a bank of $15.00. A coin will flip and randomly choose heads or tails.The user will guess heads or tails to win. If the coin flip matches the player's guess his bet will be doubled. It costs 1 dollar to play and the program will bet that amount automatically each time as long as there is the available bank amount. Note: Do...

  • Using c++ Write a function named coinToss that simulates tossing a coin. When you call the...

    Using c++ Write a function named coinToss that simulates tossing a coin. When you call the function it should generate and return a random number in the range 1 through 2. 1 represents heads and 2 represents tails. Exercise 1 (40 points) Write a function named coinToss that simulates tossing a coin. When you call the function it should generate and return a random number in the range 1 through 2.1 represents heads and 2 represents tails Use the function...

  • Please help: For this project, you will create a shape drawing program using Turtle graphics. Your...

    Please help: For this project, you will create a shape drawing program using Turtle graphics. Your program will begin by asking the user how many points they would like to enter (# of vertices for the shape). Next, you will use a loop to input each X and Y coordinate and store these coordinates in lists. After inputting all of the coordinates, create a second loop that will draw and fill the shape using the coordinates that were entered. All...

  • # JAVA Problem Toss Simulator Create a coin toss simulation program. The simulation program should toss...

    # JAVA Problem Toss Simulator Create a coin toss simulation program. The simulation program should toss coin randomly and track the count of heads or tails. You need to write a program that can perform following operations: a. Toss a coin randomly. b. Track the count of heads or tails. c. Display the results. Design and Test Let's decide what classes, methods and variables will be required in this task and their significance: Write a class called Coin. The Coin...

  • Random Number Generation and Static Methods Write a program that simulates the flipping of a coin...

    Random Number Generation and Static Methods Write a program that simulates the flipping of a coin n-times to see how often it comes up heads or tails. Ask the user to type in the number of flips (n) and print out the number of times the coin lands on head and tail. Use the method ‘random()’ from the Math class to generate the random numbers, and assume that a number less than 0.5 represents a tail, and a number bigger...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT