Feb-24-2020, 10:49 PM
Okay so, I created a hangman game, this is the code for the game
but I have 1 dilemas(actually I have quite a few but I'm only focusing on these one)
I have found that if the user clicks enter without typing in a letter the program still marks that as correct and gives the person a point,
Is there anyway that I can stop this, I'm not sure,if their is but I figured I would ask anyway
import time name = input("what is your name?: ") print("Hello, " +name +" , time to play hangman") time.sleep(2) print("This word has 4 letters, you will have to guess all 4 letter, \neven repeats, in order to win") print (" ") time.sleep(2) word = 'test' guesses =" " turns = 10 correct = 0 while turns > 0: guess = input("guess a character: \n") guesses += guess if guess in word: correct += 1 print("correct") print("You have " + str(correct) + ' out of ' + str(len(word)) + "letters" ) elif guess not in word: turns -= 1 print ("wrong") print ("you have", + turns, ' more guesses') if correct == 4: print("You win! \nthe word was test.") break elif turns == 0: print ("game over") breakand just like hangman the program asks the user for a character, if the letter they guess is in the word they gain a point, and if the letter they use is not in the game then they lose a turn. If you reach as many points as the letters in the word you win, (for example the word I used is test and there are 4 letters in that so when the user guesses the 4 letters correctly they win),
but I have 1 dilemas(actually I have quite a few but I'm only focusing on these one)
I have found that if the user clicks enter without typing in a letter the program still marks that as correct and gives the person a point,
Is there anyway that I can stop this, I'm not sure,if their is but I figured I would ask anyway