Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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'

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote