Write a python script that lets the user guess whether a ran

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.

Solution

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\'

 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 r

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site