Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #imports the necessary modules
- def wordImport(currentWord, openDoc, new, word):
- import random
- openDoc = open("Walrus.txt", "r")
- currentWord = []
- new = ""
- for i in range(0,random.randrange(0,70)):
- word = openDoc.readline()
- for i in range(0,int(len(word)-1)):
- currentWord.append(word[i])
- new = new + word[i]
- word = new
- import random
- import turtle
- turtle.speed(0)
- turtle.hideturtle()
- turtle.setx(0)
- turtle.sety(0)
- turtle.pd()
- #sets the variables
- letterCheck = 0
- lives = 10
- #opens the wordbank
- openDoc = open("Walrus.txt", "r")
- #defines the word as an array
- wordlist = []
- #makes a variable that is a random word
- ranWord = random.randrange(1,70)
- #reads the doc at the random line
- for i in range(0,ranWord):
- word = openDoc.readline()
- #makes a variable for the word length
- wordLength = int(len(word)-1)
- #makes an array for the word
- for i in range(0,wordLength):
- wordlist.append(word[i])
- #an array of the current word
- currentWord = wordlist
- length = len(word)
- #makes the array of hidden letters
- asterixArray = []
- length = len(word) - 1
- while length > 0:
- length = length - 1
- asterixArray.append("*")
- #compresses the array and shows the hidden word
- print ("This is the word:", ' '.join(asterixArray))
- #if the user is playing this will be one
- playing = 1
- #initiates a list to see what letter the user has put in
- letterList = []
- while playing == 1:
- letterCheck = 0
- print("You have", lives, "lives left ")
- #user inputs their guess
- userInput = input("What letter do you choose? ")
- userInput = userInput.lower()
- if userInput == "show":
- print(word)
- if len(userInput) == 1:
- #runs a comparison of the users guess to an array of previous guesses
- for i in letterList:
- if userInput == i:
- #changes if the user has inputted that letter before
- letterCheck = 1
- #runs the rest of the program if the users input is valid
- if letterCheck != 1:
- letterList.append(userInput)
- ticker = -1
- correct = 0
- #checks if it is correct
- for i in currentWord:
- #so I know how many times the loop has completed
- ticker = ticker + 1
- if userInput == i:
- asterixArray[ticker] = userInput
- correct = 1
- if correct > 0:
- print("Correct!")
- if correct != 1:
- print ("Incorrect!")
- lives = lives - 1
- if lives == 9:
- turtle.rt(180)
- turtle.fd(100)
- elif lives == 8:
- turtle.bk(30)
- turtle.rt(90)
- turtle.fd(200)
- elif lives == 7:
- if done8 == 0:
- turtle.rt(90)
- turtle.fd(100)
- done8 = 1
- elif lives == 6:
- turtle.bk(25)
- turtle.rt(90)
- turtle.fd(25)
- elif lives == 5:
- turtle.rt(90)
- circle=1
- while circle<55:
- turtle.fd(3)
- turtle.lt(10)
- circle=circle+1
- elif lives == 4:
- turtle.rt(90)
- turtle.fd(70)
- elif lives == 3:
- turtle.rt(30)
- turtle.fd(40)
- turtle.bk(40)
- elif lives == 2:
- turtle.lt(60)
- turtle.fd(40)
- turtle.bk(40)
- elif lives == 1:
- turtle.rt(30)
- turtle.bk(50)
- turtle.rt(40)
- turtle.fd(35)
- turtle.bk(35)
- elif lives == 0:
- turtle.lt(80)
- turtle.fd(35)
- turtle.bk(35)
- turtle.rt(40)
- elif lives == 0:
- #checks to see if you win
- print("You lose! The word was:", word)
- playing = 0
- print ("This is the word:", ' '.join(asterixArray))
- #checks to see if you won
- numberOfAsterix = asterixArray.count("*")
- if numberOfAsterix == 0:
- print("Congratulations, you win!")
- playing = 0
- #Tells the user they have already inputted a letterList
- else:
- print("You have already input that letter. Try again")
- else:
- print("You can only enter one letter!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement