Created
January 25, 2017 23:02
-
-
Save Jessime/c75f900b4196c3ecdbb1776318a4f7fe to your computer and use it in GitHub Desktop.
I used this script as a 3 part lesson on Python for a 4th grade class.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
import random | |
#Introduction | |
print "Hello, Players!" | |
print "Welcome to Multiplication Battles!" | |
print "" | |
#Input information | |
player1 = raw_input("What is your name, Player 1? ") | |
player1_points = 0 | |
player2 = raw_input("What is your name, Player 2? ") | |
player2_points = 0 | |
length_per_round = int(raw_input("How many seconds do you want each round to be? ")) | |
highest_num = int(raw_input("What's the largest number you want to multiply? ")) | |
#Launch Player1's game | |
print "" | |
raw_input("{}! Hit any key to start your time.".format(player1)) | |
current_time = time.time() | |
end_time = current_time + length_per_round | |
while current_time <= end_time: | |
#Do math | |
a = random.randint(0, highest_num) | |
b = random.randint(0, highest_num) | |
c = a*b | |
answer = int(raw_input("What is {}x{}? ".format(a,b))) | |
#Check if right or wrong | |
if answer == c: | |
print "You're Correct!" | |
player1_points += 1 | |
else: | |
print "Sorry. {}x{}={}.".format(a,b,c) | |
#Must update the time at the end of each loop. | |
current_time = time.time() | |
print "You scored {} points!".format(player1_points) | |
#Get ready for Player2 | |
print "" | |
raw_input("{}! Hit any key to start your time.".format(player2)) | |
current_time = time.time() | |
end_time = current_time + length_per_round | |
while current_time <= end_time: | |
#Do math | |
a = random.randint(0, highest_num) | |
b = random.randint(0, highest_num) | |
c = a*b | |
#Check if right or wrong | |
answer = int(raw_input("What is {}x{}? ".format(a,b))) | |
if answer == c: | |
print "You're Correct!" | |
player2_points += 1 | |
else: | |
print "Sorry. {}x{}={}.".format(a,b,c) | |
#Must update the time at the end of each loop. | |
current_time = time.time() | |
print "You scored {} points!".format(player2_points) | |
#Decide a winner | |
print "" | |
if player1_points > player2_points: | |
print "{} wins! Good job!".format(player1) | |
elif player2_points > player1_points: | |
print "{} wins! Good job!".format(player2) | |
else: | |
print "It was a tie! You two should play again!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment