In this module you learned about making decisions. You learned about the syntax and rules used to develop programs containing decisions and how the logic can make your programs more robust. Draw a flowchart for a program that shows the logic for a program that generates a random number. The program will simulate tossing coin. The program should generate a random number(0 and 1). If the random number is 0, then it should display the word "Heads". If the random number is 1, then it should display the word "Tails". You want to add the code so the player can enter their name, then display a welcome message using their name. You also want to display a message that describes what the program will do. When your program ends, thank the person for playing. There are NO LOOPS, NO Functions or NO MODULES at this point. Everything at this point is in sequence(Line-By-Line). You can add comments at the beginning of each block to explain what the code is doing.. Make a working version of this program in Python. Complete the flowchart. Upload it to the Blackboard assignment area by clicking on the Browse My Computer button below the text editor. Complete the Python code using IDLE. Upload your .py file to the Blackboard assignment area by clicking on the Browse My Computer button below the text editor.
import random
#prompt the user to enter a name
name = input("Enter your name:\t")
#display the welcome message for the user
print("Hello " + name + ", Welcome to Coin Tossing Game")
#describe the game
print("Here you have to toss a coin and it will show the
result")
#prompt the user whether they want to toss the coin
ch = input("want to toss a coin?(y/n) ")
#if the user enter y
if(ch == "y"):
#generate a random number between 0 and 1
coin = random.randint(0, 1)
#check the number is 0 or 1 and print the
message
if(coin == 1):
print("Heads")
else:
print("Tails")
#display the ending message
print("Thank you for playing the game")
Follow the image for indentation
If you have any doubts please comment and please don't dislike.
Get Answers For Free
Most questions answered within 1 hours.