Write a python script that lets the user guess whether a randomly flipped coin d
ID: 3923196 • Letter: W
Question
Write a python script that lets the user guess whether a randomly flipped coin displays head or tail. The program randomly generates an integer 0 or 1, which represents head or tail respectively. The program prompts the user to enter a guess value (0 or 1) and reports whether the guess is correct or incorrect. Sample program output I (computer guesses Tail): Enter 0 for Head and 1 for Tail: 0 Sorry, it is a tail. Sample program output II (computer guesses Tail): Enter 0 for Head and 1 for Tail: 0 You guessed correctly! Sample program output III (computer guesses Head): Enter 0 for Head and 1 for Tail: 1 Sorry, it is a head.Explanation / Answer
import random
guess=input('enter 0 for head or 1 for tail : ')
actual=random.choice([0,1])
if guess==actual:
print 'you guessed correctly ! ';
else:
if actual==1:
print 'Sorry,it is tail'
if actual==0:
print 'Sorry,it is head'
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.