Any Help will be Greatly Appreciated!
"""
Stephen Frazier
PA1
9/19/2012
The purpose is to pick a random word from a list, scramble it and get the user to guess it as fast as possible.
Then print out the users statistics
"""
from math import *
from random import * #Imports all the needed modules for the assignment
from time import *
from scrambleFunction import scramble
def playGame():
randList = ["computer", "science", "mouse", "keyboard", "mathematics", "memory", "programmer", "storage", "drive", "gigabyte"] #Creates a list of 10 words
print("Welcome to the scramble game, I will present you with a word that has to do with computers, and you have to guess what it is!")
sleep(6)
print("\n")
print("Ready, here we go!")
sleep(2)
print("\n")
correctAnswers = 0 # Sets correctAnswers equal to 0
wrongAnswers = 0 #Sets wrongAnswers equal to 0
playAgain = "yes" #Starts playAgain at yes, so the loop will start
while playAgain == "yes": #As long as playAgain is yes, then the loop will repeat
RI = randint(0, len(randList)-1) #Assigns RI the value of one of the words in the list
startTime = clock() #Starts the timing
answer = input(scramble(randList[RI])) #Assigns answer, the value of what the user guesses
averageTimeCounter = 0 #Sets the totalTimeCounter to 0
if answer == randList[RI]: #Tells if what the user entered is the word at that position
correctAnswers = correctAnswers+1 #Adds 1 to correctAnswers
print("Good job, you got it!")
endTime = clock() #Ends the timing
totalTime = endTime - startTime #Calculates the total time
print("It took you " ,totalTime, "seconds")
if totalTime < 5: #If the user gets the answer in under 5 seconds, it tells them they're fast
print("Wow, your fast!")
elif 10>totalTime>5:
print("Come on now, you do know where the keys are right?") #If they get it in more than 5 but less than 10, tells them that
elif 15>totalTime>10:
print("You know that you can use two hands to type, right?") #If they get it in more than 10 but less than 15, tells them that
else:
print("I can type faster than they with my feet!") #If they take more than 15 seconds, than it just tells them this
print("\n")
playAgain = input("Would you like to play again? Enter yes or no ") #Asks the user if they want to play again, and if they enter anything other than yes, it ends the loop
if playAgain == "no":
averageTimeCounter = averageTimeCounter+totalTime
print("You got ", correctAnswers, "correct, and ", wrongAnswers, "incorrect, with an average time of ", averageTimeCounter) #Compares how many right and wrong the user got
if correctAnswers > wrongAnswers:
print("Well you got more right than wrong, so Good Job! ") #If they got the more right than wrong, then it prints this
elif correctAnswers == wrongAnswers:
print("Well you broke even, same amount wrong as right.") #If they got the same amount wrong and right, it prints this
else:
print("Well you have more wrong than you do right, Your a Failure! ") #If they got more wrong than right, it prints this
else:
wrongAnswers = wrongAnswers+1 #Adds 1 to wrongAnswers
endTime2 = clock() #Creates a 2nd time ender, in case they do not get it right
totalTime2 = endTime2 - startTime #Calculates their total time
print("Congratulations it took you ", totalTime2, " seconds to get the wrong answer")
playAgain = input("The word was " + randList[RI] + " do you want to try another word? Enter yes or no ") #Assigns whatever the user enters as playAgain, to either end of keep the loop going
if playAgain == "no":
print("You got ", correctAnswers, "correct, and ", wrongAnswers, "incorrect")
if correctAnswers > wrongAnswers:
print("Well you got more right than wrong, so Good Job! ")#If they got the more right than wrong, then it prints this
elif correctAnswers == wrongAnswers:
print("Well you broke even, same amount wrong as right.") #If they got the same amount wrong and right, it prints this
else:
print("Well you have more wrong than you do right, Your a Failure! ") #If they got more wrong than right, it prints this
playGame()

New Topic/Question
Reply



MultiQuote




|