Add keyboard interrupt
This commit is contained in:
parent
f09d4ba213
commit
20d5499bf9
|
@ -4,30 +4,33 @@ random.seed()
|
|||
number = random.randrange(100, 999)
|
||||
number = list(str(number))
|
||||
guesses = 0
|
||||
while True:
|
||||
|
||||
if guesses == 5:
|
||||
print("You loose!")
|
||||
for value in number:
|
||||
print(value, end=" ")
|
||||
break
|
||||
hint = [" ", " ", " "]
|
||||
guess = input("Enter a three digit number:")
|
||||
while len(guess) != 3:
|
||||
try:
|
||||
while True:
|
||||
|
||||
if guesses == 5:
|
||||
print("You loose!")
|
||||
for value in number:
|
||||
print(value, end=" ")
|
||||
break
|
||||
hint = [" ", " ", " "]
|
||||
guess = input("Enter a three digit number:")
|
||||
|
||||
guess = list(guess)
|
||||
if guess == number:
|
||||
print("You win!")
|
||||
break
|
||||
for index, value in enumerate(guess):
|
||||
print(value, end=" ")
|
||||
if value in number:
|
||||
hint[index] = "P"
|
||||
print("")
|
||||
for index, value in enumerate(guess):
|
||||
if number[index] == value:
|
||||
hint[index] = "F"
|
||||
print(hint[index], end=" ")
|
||||
guesses += 1
|
||||
print("\n")
|
||||
while len(guess) != 3:
|
||||
guess = input("Enter a three digit number:")
|
||||
|
||||
guess = list(guess)
|
||||
if guess == number:
|
||||
print("You win!")
|
||||
break
|
||||
for index, value in enumerate(guess):
|
||||
print(value, end=" ")
|
||||
if value in number:
|
||||
hint[index] = "P"
|
||||
print("")
|
||||
for index, value in enumerate(guess):
|
||||
if number[index] == value:
|
||||
hint[index] = "F"
|
||||
print(hint[index], end=" ")
|
||||
guesses += 1
|
||||
print("\n")
|
||||
except KeyboardInterrupt:
|
||||
pass
|
Loading…
Reference in New Issue