September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
33
Task/24-game/Python/24-game-2.py
Normal file
33
Task/24-game/Python/24-game-2.py
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
import random, re
|
||||
chars = ["(",")","/","+","-","*"]
|
||||
while True:
|
||||
charsandints, ints = [], []
|
||||
for x in range(4):
|
||||
ints.append(str(random.randrange(1,10)))
|
||||
charsandints = chars + ints
|
||||
print "Numbers are:", ints
|
||||
guess = raw_input("Enter your guess:")
|
||||
if guess.lower() == "q":
|
||||
break
|
||||
elif guess.lower() == "|":
|
||||
pass
|
||||
else:
|
||||
flag = True
|
||||
for a in guess:
|
||||
if a not in charsandints or guess.count(a) > charsandints.count(a):
|
||||
flag = False
|
||||
if re.search("\d\d", guess):
|
||||
print "You cannot combine digits."
|
||||
break
|
||||
if flag:
|
||||
print "Your result is: ", eval(guess)
|
||||
if eval(guess) == 24:
|
||||
print "You won"
|
||||
break
|
||||
else:
|
||||
print "You lost"
|
||||
break
|
||||
else:
|
||||
print "You cannot use anthing other than", charsandints
|
||||
break
|
||||
print "Thanks for playing"
|
||||
Loading…
Add table
Add a link
Reference in a new issue