Question: Write a Python program that emulates a dice using a random variable between 1 and 6. Start by asking the user to guess the dice

 Write a Python program that emulates a dice using a random

Write a Python program that emulates a dice using a random variable between 1 and 6. Start by asking the user to guess the dice outcome, if the guess is correct blink a green LED connected on pin 10 for 3 times and print "You have won" on the screen. If wrong blink a red LED connected on pin 7 for 3 times and print "You have lost". At the end ask the user if he wants to roll again, if the answer is "yes", clear the terminal and repeat the game. Use BCM numbering. import RPi emu.GPIO as GPIO import os import time import random GPIO. (GPIO.BCM) GPIO GPIO. roll_again = "yes" count guess while roll_again == "yes": ('clear") dice=random ("Make your guess:") if guess== print "You have won, the number is " + str(dice) whiled GPIO time.sleep(1) GPIO time.sleep(1) .HIGH) .LOW) else: print "You have lost the number is" + str(dice) while(count>0) GPIO .HIGH) time.sleep(1) GPIO -LOW) time.sleep(1) roll_again ("Roll the dice again? yeso") GPIO GPIO.IN setmode 1 input count 10 setup randint os.system output dice 3 count> 6 GPIO.OUT

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!