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:
|
|
||||||
print("You loose!")
|
if guesses == 5:
|
||||||
for value in number:
|
print("You loose!")
|
||||||
print(value, end=" ")
|
for value in number:
|
||||||
break
|
print(value, end=" ")
|
||||||
hint = [" ", " ", " "]
|
break
|
||||||
guess = input("Enter a three digit number:")
|
hint = [" ", " ", " "]
|
||||||
while len(guess) != 3:
|
|
||||||
guess = input("Enter a three digit number:")
|
guess = input("Enter a three digit number:")
|
||||||
|
while len(guess) != 3:
|
||||||
guess = list(guess)
|
guess = input("Enter a three digit number:")
|
||||||
if guess == number:
|
|
||||||
print("You win!")
|
guess = list(guess)
|
||||||
break
|
if guess == number:
|
||||||
for index, value in enumerate(guess):
|
print("You win!")
|
||||||
print(value, end=" ")
|
break
|
||||||
if value in number:
|
for index, value in enumerate(guess):
|
||||||
hint[index] = "P"
|
print(value, end=" ")
|
||||||
print("")
|
if value in number:
|
||||||
for index, value in enumerate(guess):
|
hint[index] = "P"
|
||||||
if number[index] == value:
|
print("")
|
||||||
hint[index] = "F"
|
for index, value in enumerate(guess):
|
||||||
print(hint[index], end=" ")
|
if number[index] == value:
|
||||||
guesses += 1
|
hint[index] = "F"
|
||||||
print("\n")
|
print(hint[index], end=" ")
|
||||||
|
guesses += 1
|
||||||
|
print("\n")
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
pass
|
Loading…
Reference in New Issue