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