I have a hangman code(you don't have to read it all):
import random
import sys
guess = ''
guess2 = 0
guess3 = 0
guess4 = 0
guess5 = 0
guess6 = 0
guess7 = 0
guess8 = 0
guess9 = 0
guess10 = 0
guess11 = 0
guess12 = 0
guess13 = 0
guess14 = 0
guess15 = 0
guess16 = 0
guess17 = 0
guess18 = 0
guess19 = 0
guess20 = 0
guess21 = 0
aa1 = 0
aa2 = 0
aa3 = 0
aa4 = 0
aa5 = 0
aa6 = 0
aa7 = 0
aa8 = 0
aa9 = 0
aa10 = 0
aa11 = 0
aa12 = 0
aa13 = 0
aa14 = 0
aa15 = 0
aa16 = 0
aa17 = 0
rong = [ ]
lis = [ ]
uy = 'jrekghqegherwgbeuihrweig'
choice = 'bhekvvvvvfaktgrwekubfhdbvbvdvbd'
z = 'bqhjrfqfbrqkqbg'
s = 'ksl'
s_space = 'bhks'
li = [ ]
a1a = None
a2a = None
a3a = None
a4a = None
a5a = None
a6a = None
a7a = None
a8a = None
a9a = None
a10a = None
a11a = None
a12a = None
a13a = None
a14a = None
a15a = None
a16a = None
a17a = None
a1 = a1a
a2 = a2a
a3 = a3a
a4 = a4a
a5 = a5a
a6 = a6a
a7 = a7a
a8 = a8a
a9 = a9a
a10 = a10a
a11 = a11a
a12 = a12a
a13 = a13a
a14 = a14a
a15 = a15a
a16 = a16a
a17 = a17a
correct = 0
dup = 0
t = list(s)
hangman = """
+---+
| |
|
|
|
|
=========
"""
hangman1 = """
+---+
| |
O |
|
|
|
=========
"""
hangman2 = """
+---+
| |
O |
| |
|
|
=========
"""
hangman3 = """
+---+
| |
O |
|/ |
|
|
=========
"""
hangman4 = """
+---+
| |
O |
\|/ |
|
|
=========
"""
hangman5 = """
+---+
| |
O |
\|/ |
| |
|
=========
"""
hangman6 = """
+---+
| |
O |
\|/ |
| |
\ |
=========
"""
hangman7 = """
+---+
| |
O |
\|/ |
| |
/ \ |
=========
Game Over.
"""
hangman0 = hangman
animals = ['llama']
animals2 = [ 'bear', 'Giraffe', 'Tiger', 'Lion', 'Panda', 'Penguin', 'Gorilla', 'Chimpanzee', 'Monkey', 'Owl', 'Gorilla', 'Zebra', 'Koala', 'Jaguar', 'Hippopotamus', 'Kangaroo', 'Swan', 'Rhinoceros', 'Moose', 'Camel', 'Horse', 'Dog', 'Meerkat', 'Orangutan', 'Peacock', 'Badger', 'Sloth', 'Seal', 'Deer', 'Alligator', 'Crocodile', 'Skumk', 'Leopard', 'Lizard', 'Bat', 'Snake', 'Okapi', 'Birds', 'Turtle', 'Fox', 'Tortoise', 'Dolphin', 'Panther', 'Cheetah', 'Buffalo', 'Cougar', 'Hawk', 'Cat', 'Ostrich', 'Frog', 'Lemur', 'Duck', 'Walrus', 'Goat', 'Warthog', 'llama', 'Parrot', 'Baboon', 'Emu', 'Toad', 'Goose', 'Emu', 'Crane', 'Vulture', 'Squirrel', 'Raccoon', 'Sheep']
space = ['astronomy', 'gas', 'nebula', 'planet', 'Earth', 'sun', 'space', 'star', 'Venus', 'Mars', 'Mercury', 'Pluto', 'Neptune', 'Uranus', 'ice', 'Jupiter', 'Saturn', 'asteroid', 'comet', 'Kepler', 'ISS', 'station', 'quasar', 'galaxy', 'Andromeda', 'moon', 'Phobios', 'Demios', 'orbit', 'gravity', 'matter']
food = ['pizza', 'bagel', 'donut', 'candy', 'cake', 'casserole', 'salmon', 'bacon', 'caviar', 'apple', 'bannana', 'orange', 'acai', 'pomegranete', 'pear', 'cheese', 'turkey', 'steak', 'Cabbage', 'Calorie', 'Carbohydrate', 'Casserole', 'Caterer', 'Celery', 'Chef', 'Chewy', 'Chicken', 'Chicory', 'Chipotle', 'Chips', 'Chocolate', 'Chocolatier', 'Choice', 'Chutney', 'Cocoa', 'Coffee', 'Condiment', 'mango', 'Crackers', 'Croutons', 'Crunchy', 'Cucumbers', 'potato', 'sandwich']
chemicals = ['alum', 'sodium', 'titin', 'Bichrome', 'Azurite', 'Borax', 'Calomel', 'Gypsum', 'graphite', 'hypo', 'lime', 'acetone', 'pollen', 'Aluminium', 'starch', 'soap', 'calcium', 'alchohol', 'seltzer', 'aspirin', 'bronze', 'chalk', 'diamond', 'marble', 'quartz', 'sand', 'silicon', 'vinegar', 'carbon', 'nitrogen', 'vapor', 'oxide', 'phosphorus', 'magnesium', 'acid', 'chemical', 'ackey']
print 'Welcome to hangman!'
import time
time.sleep(3)
print 'Pick a topic:'
print '1.Animals'
print '2.Space'
print '3.Food'
print '4.Chemicals'
topic = str(raw_input('Choose a topic(1/2/3/4):'))
while not topic.isalpha():
if topic == '1':
choice = animals
print 'animals'
break
elif topic == '2':
choice = space
print 'space'
break
elif topic == '3':
choice = food
print 'food'
break
elif topic == '4':
choice = chemicals
print 'chemicals'
break
else:
print 'Invalid Input'
topic = str(raw_input('Choose a topic(1/2/3/4):'))
if topic != '1' or '2' or '3' or '4':
print 'Invalid Input'
topic = str(raw_input('Choose a topic(1/2/3/4):'))
if choice == animals:
word = random.choice(animals)
if choice == food:
word = random.choice(food)
if choice == space:
word = random.choice(space)
if choice == chemicals:
word = random.choice(chemicals)
word = word.lower()
length = len(word)
if length == 3:
s = '_ _ _'
a1a = word[0]
a2a = word[1]
a3a = word[2]
lis = [a1a, a2a, a3a]
if length == 4:
s = '_ _ _ _'
a1a = word[0]
a2a = word[1]
a3a = word[2]
a4a = word[3]
lis = [a1a, a2a, a3a, a4a]
if length == 5:
s = '_ _ _ _ _'
a1a = word[0]
a2a = word[1]
a3a = word[2]
a4a = word[3]
a5a = word[4]
lis = [a1a, a2a, a3a, a4a, a5a]
if length == 6:
s = '_ _ _ _ _ _'
a1a = word[0]
a2a = word[1]
a3a = word[2]
a4a = word[3]
a5a = word[4]
a6a = word[5]
lis = [a1a, a2a, a3a, a4a, a5a, a6a]
if length == 7:
s = '_ _ _ _ _ _ _'
a1a = word[0]
a2a = word[1]
a3a = word[2]
a4a = word[3]
a5a = word[4]
a6a = word[5]
a7a = word[6]
list = [a1a, a2a, a3a, a4a, a5a, a6a, a7a]
if length == 8:
s = '_ _ _ _ _ _ _ _'
a1a = word[0]
a2a = word[1]
a3a = word[2]
a4a = word[3]
a5a = word[4]
a6a = word[5]
a7a = word[6]
a8a = word[7]
lis = [a1a, a2a, a3a, a4a, a5a, a6a, a7a, a8a]
if length == 9:
s = '_ _ _ _ _ _ _ _ _'
a1a = word[0]
a2a = word[1]
a3a = word[2]
a4a = word[3]
a5a = word[4]
a6a = word[5]
a7a = word[6]
a8a = word[7]
a9a = word[8]
lis = [a1a, a2a, a3a, a4a, a5a, a6a, a7a, a8a, a9a]
if length == 10:
s = '_ _ _ _ _ _ _ _ _ _'
a1a = word[0]
a2a = word[1]
a3a = word[2]
a4a = word[3]
a5a = word[4]
a6a = word[5]
a7a = word[6]
a8a = word[7]
a9a = word[8]
a10a = word[9]
lis = [a1a, a2a, a3a, a4a, a5a, a6a, a7a, a8a, a9a, a10a]
if length == 11:
s = '_ _ _ _ _ _ _ _ _ _ _'
a1a = word[0]
a2a = word[1]
a3a = word[2]
a4a = word[3]
a5a = word[4]
a6a = word[5]
a7a = word[6]
a8a = word[7]
a9a= word[8]
a10a = word[9]
a11a = word[10]
lis = [a1a, a2a, a3a, a4a, a5a, a6a, a7a, a8a, a9a, a10a, a11a]
if length == 12:
s = '_ _ _ _ _ _ _ _ _ _ _ _'
a1a = word[0]
a2a = word[1]
a3a = word[2]
a4a = word[3]
a5a = word[4]
a6a = word[5]
a7a = word[6]
a8a = word[7]
a9a = word[8]
a10a = word[9]
a11a = word[10]
a12a = word[11]
lis = [a1a, a2a, a3a, a4a, a5a, a6a, a7a, a8a, a9a, a10a, a11a, a12a]
if length == 13:
s = '_ _ _ _ _ _ _ _ _ _ _ _ _'
a1a = word[0]
a2a = word[1]
a3a = word[2]
a4a = word[3]
a5a = word[4]
a6a = word[5]
a7a = word[6]
a8a = word[7]
a9a = word[8]
a10a = word[9]
a11a = word[10]
a12a = word[11]
a13a = word[12]
lis = [a1a, a2a, a3a, a4a, a5a, a6a, a7a, a8a, a9a, a10a, a11a, a12a, a13a]
if length == 14:
s = '_ _ _ _ _ _ _ _ _ _ _ _ _ _'
a1a = word[0]
a2a = word[1]
a3a = word[2]
a4a = word[3]
a5a = word[4]
a6a = word[5]
a7a = word[6]
a8a= word[7]
a9a= word[8]
a10a = word[9]
a11a = word[10]
a12a = word[11]
a13a = word[12]
a14a = word[13]
lis = [a1a, a2a, a3a, a4a, a5a, a6a, a7a, a8a, a9a, a10a, a11a, a12a, a13a, a14a]
if length == 15:
s = '_ _ _ _ _ _ _ _ _ _ _ _ _ _ _'
a1a = word[0]
a2a = word[1]
a3a = word[2]
a4a = word[3]
a5a = word[4]
a6a = word[5]
a7a = word[6]
a8a = word[7]
a9a = word[8]
a10a = word[9]
a11a = word[10]
a12a = word[11]
a13a = word[12]
a14a = word[13]
a15a = word[14]
lis = [a1a, a2a, a3a, a4a, a5a, a6a, a7a, a8a, a9a, a10a, a11a, a12a, a13a, a14a, a15a]
if length == 16:
s = '_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _'
a1a = word[0]
a2a = word[1]
a3a = word[2]
a4a = word[3]
a5a = word[4]
a6a = word[5]
a7a = word[6]
a8a = word[7]
a9a = word[8]
a10a = word[9]
a11a = word[10]
a12a = word[11]
a13a = word[12]
a14a = word[13]
a15a = word[14]
a16a = word[15]
lis = [a1a, a2a, a3a, a4a, a5a, a6a, a7a, a8a, a9a, a10a, a11a, a12a, a13a, a14a, a15a, a16a]
if length == 17:
s = '_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _'
a1a = word[0]
a2a = word[1]
a3a = word[2]
a4a = word[3]
a5a = word[4]
a6a = word[5]
a7a = word[6]
a8a = word[7]
a9a = word[8]
a10a = word[9]
a11a = word[10]
a12a = word[11]
a13a = word[12]
a14a = word[13]
a15a = word[14]
a16a = word[15]
a17a = word[16]
lis = [a1a, a2a, a3a, a4a, a5a, a6a, a7a, a8a, a9a, a10a, a11a, a12a, a13a, a14a, a15a, a16a, a17a]
while hangman != hangman7 or s_space != word:
correct = 0
print """
"""
print hangman
print s
guess = str(raw_input('Enter a letter:'))
if guess20 == guess:
guess21 = guess
if guess19 == guess:
guess20 = guess
if guess18 == guess:
guess19 = guess
if guess17 == guess:
guess18 = guess
if guess16 == guess:
guess17 = guess
if guess15 == guess:
guess16 = guess
if guess14 == guess:
guess15 = guess
if guess13 == guess:
guess14 = guess
if guess12 == guess:
guess13 = guess
if guess11 == guess:
guess12 = guess
if guess10 == guess:
guess11 = guess
if guess9 == guess:
guess10 = guess
if guess8 == guess:
guess9 = guess
if guess7 == guess:
guess8 = guess
if guess6 == guess:
guess7 = guess
if guess5 == guess:
guess6 = guess
if guess4 == guess:
guess5 = guess
if guess3 == guess:
guess4 = guess
if guess2 == guess:
guess3 = guess
if guess == guess:
guess2 = guess
if guess == guess:
guess0 = guess
li = [guess, guess2, guess3, guess4, guess5, guess6, guess7, guess8, guess9, guess10, guess11, guess12, guess13, guess14, guess15, guess16, guess17, guess18, guess19, guess20, guess21]
if guess.isalpha():
if not guess in lis:
print 'Try again'
inc = guess
if hangman == hangman6:
hangman = hangman7
incorrect = guess
rong.append(incorrect)
print s
print 'incorrect:'
print rong
print hangman7
print ('The word was', word)
sys.exit(" ")
elif hangman == hangman5:
hangman = hangman6
incorrect = guess
rong.append(incorrect)
print s
print 'incorrect:'
print rong
elif hangman == hangman4:
hangman = hangman5
incorrect = guess
rong.append(incorrect)
print s
print 'incorrect:'
print rong
elif hangman == hangman3:
hangman = hangman4
incorrect = guess
rong.append(incorrect)
print s
print 'incorrect:'
print rong
elif hangman == hangman2:
hangman = hangman3
incorrect = guess
rong.append(incorrect)
print s
print 'incorrect:'
print rong
elif hangman == hangman1:
hangman = hangman2
incorrect = guess
rong.append(incorrect)
print s
print 'incorrect:'
print rong
elif hangman == hangman0:
hangman = hangman1
incorrect = guess
rong.append(incorrect)
print s
print 'incorrect:'
print rong
else:
gue = 'hi'
abc = list(lis)
if guess in lis:
if guess == a1a:
correct = a1a
t = list(s)
t[0] = guess
s = "".join(t)
print guess
s_0 = s.replace(" ","")
elif guess == a2a:
correct = a2a
t = list(s)
t[2] = guess
s = "".join(t)
print hangman
print guess
s_0 = s.replace(" ","")
elif guess == a3a:
correct = a3a
t = list(s)
t[4] = guess
s = "".join(t)
print guess
s_0 = s.replace(" ","")
elif guess == a4a:
correct = a4a
t = list(s)
t[6] = guess
s = "".join(t)
print guess
s_0 = s.replace(" ","")
elif guess == a5a:
correct = a5a
t = list(s)
t[8] = guess
s = "".join(t)
print guess
s_0 = s.replace(" ","")
elif guess == a6a:
correct = a6a
t = list(s)
t[10] = guess
s = "".join(t)
print guess
s_0 = s.replace(" ","")
elif guess == a7a:
correct = a7a
t = list(s)
t[12] = guess
s = "".join(t)
print guess
s_0 = s.replace(" ","")
elif guess == a8a:
correct = a8a
t = list(s)
t[14] = guess
s = "".join(t)
print guess
s_0 = s.replace(" ","")
elif guess == a9a:
correct = a9a
t = list(s)
t[16] = guess
s = "".join(t)
print guess
s_0 = s.replace(" ","")
elif guess == a10a:
correct = a10a
t = list(s)
t[18] = guess
s = "".join(t)
print guess
s_0 = s.replace(" ","")
elif guess == a11a:
correct = a11a
t = list(s)
t[20] = guess
s = "".join(t)
print guess
s_0 = s.replace(" ","")
elif guess == a12a:
correct = a12a
t = list(s)
t[22] = guess
s = "".join(t)
print guess
s_0 = s.replace(" ","")
elif guess == a13a:
correct = a13a
t = list(s)
t[24] = guess
s = "".join(t)
print guess
s_0 = s.replace(" ","")
elif guess == a14a:
correct = a14a
t = list(s)
t[26] = guess
s = "".join(t)
print guess
s_0 = s.replace(" ","")
elif guess == a15a:
correct = a15a
t = list(s)
t[28] = guess
s = "".join(t)
print guess
s_0 = s.replace(" ","")
elif guess == a16a:
correct = a16a
t = list(s)
t[30] = guess
s = "".join(t)
print guess
s_0 = s.replace(" ","")
elif guess == a17a:
correct = a17a
t = list(s)
t[32] = guess
s = "".join(t)
print guess
s_0 = s.replace(" ","")
print hangman
print s
if s_0 == word:
print s_0
print 'You Won!'
import time
time.sleep(3)
print ' This program was written using Python, by Slass33'
break
co = raw_input('Do you want to play again?(yes/no):')
if co == 'yes':
print """
"""
elif co == 'no':
sys.exit
else:
co = raw_input('Do you want to play again?(yes/no):')
sys.exit
My problem is that, when I run the program, if the word has, say, 2 a
s, or multiple b
s, it only prints one of the b
s, or a
s(these letters are examples). My problem might be here:
abc = list(lis)
if guess in lis:
if guess == a1a:
correct = a1a
t = list(s)
t[0] = guess
s = "".join(t)
print guess
s_0 = s.replace(" ","")
elif guess == a2a:
correct = a2a
t = list(s)
t[2] = guess
s = "".join(t)
print hangman
print guess
s_0 = s.replace(" ","")
elif guess == a3a:
correct = a3a
t = list(s)
t[4] = guess
s = "".join(t)
print guess
s_0 = s.replace(" ","")
elif guess == a4a:
correct = a4a
t = list(s)
t[6] = guess
s = "".join(t)
print guess
s_0 = s.replace(" ","")
elif guess == a5a:
correct = a5a
t = list(s)
t[8] = guess
s = "".join(t)
print guess
s_0 = s.replace(" ","")
elif guess == a6a:
correct = a6a
t = list(s)
t[10] = guess
s = "".join(t)
print guess
s_0 = s.replace(" ","")
elif guess == a7a:
correct = a7a
t = list(s)
t[12] = guess
s = "".join(t)
print guess
s_0 = s.replace(" ","")
elif guess == a8a:
correct = a8a
t = list(s)
t[14] = guess
s = "".join(t)
print guess
s_0 = s.replace(" ","")
elif guess == a9a:
correct = a9a
t = list(s)
t[16] = guess
s = "".join(t)
print guess
s_0 = s.replace(" ","")
elif guess == a10a:
correct = a10a
t = list(s)
t[18] = guess
s = "".join(t)
print guess
s_0 = s.replace(" ","")
elif guess == a11a:
correct = a11a
t = list(s)
t[20] = guess
s = "".join(t)
print guess
s_0 = s.replace(" ","")
elif guess == a12a:
correct = a12a
t = list(s)
t[22] = guess
s = "".join(t)
print guess
s_0 = s.replace(" ","")
elif guess == a13a:
correct = a13a
t = list(s)
t[24] = guess
s = "".join(t)
print guess
s_0 = s.replace(" ","")
elif guess == a14a:
correct = a14a
t = list(s)
t[26] = guess
s = "".join(t)
print guess
s_0 = s.replace(" ","")
elif guess == a15a:
correct = a15a
t = list(s)
t[28] = guess
s = "".join(t)
print guess
s_0 = s.replace(" ","")
elif guess == a16a:
correct = a16a
t = list(s)
t[30] = guess
s = "".join(t)
print guess
s_0 = s.replace(" ","")
elif guess == a17a:
correct = a17a
t = list(s)
t[32] = guess
s = "".join(t)
print guess
s_0 = s.replace(" ","")
To try and fix this, I added:
if len(lis) != len(set(list)):
dup = collections.counter(lis)
if dup != 0:
if dup == a17a:
correct1 = a17a
ts = list(s)
ts[32] = dup
s = "".join(ts)
print dup
s_0 = s.replace(" ","")
elif dup == a16a:
correct1 = a16a
ts = list(s)
ts[30] = dup
s = "".join(ts)
print dup
s_0 = s.replace(" ","")
elif guess == a15a:
correct = a15a
ts = list(s)
ts[28] = guess
s = "".join(ts)
print guess
s_0 = s.replace(" ","")
elif guess == a14a:
correct = a14a
ts = list(s)
ts[26] = guess
s = "".join(ts)
print guess
s_0 = s.replace(" ","")
elif guess == a13a:
correct = a13a
ts = list(s)
ts[24] = guess
s = "".join(ts)
print guess
s_0 = s.replace(" ","")
elif guess == a12a:
correct = a12a
ts = list(s)
ts[22] = guess
s = "".join(ts)
print guess
s_0 = s.replace(" ","")
elif guess == a11a:
correct = a11a
ts = list(s)
ts[20] = guess
s = "".join(ts)
print guess
s_0 = s.replace(" ","")
elif guess == a10a:
correct = a10a
ts = list(s)
ts[18] = guess
s = "".join(ts)
print guess
s_0 = s.replace(" ","")
elif guess == a9a:
correct = a9a
ts = list(s)
ts[16] = guess
s = "".join(ts)
print guess
s_0 = s.replace(" ","")
elif guess == a8a:
correct = a8a
ts = list(s)
ts[14] = guess
s = "".join(ts)
print guess
s_0 = s.replace(" ","")
elif guess == a7a:
correct = a7a
ts = list(s)
ts[12] = guess
s = "".join(ts)
print guess
s_0 = s.replace(" ","")
elif guess == a6a:
correct = a6a
ts = list(s)
ts[10] = guess
s = "".join(ts)
print guess
s_0 = s.replace(" ","")
elif guess == a5a:
correct = a5a
ts = list(s)
ts[8] = guess
s = "".join(ts)
print guess
s_0 = s.replace(" ","")
elif guess == a4a:
correct = a4a
ts = list(s)
ts[6] = guess
s = "".join(ts)
print guess
s_0 = s.replace(" ","")
elif guess == a3a:
correct = a3a
ts = list(s)
ts[4] = guess
s = "".join(ts)
print guess
s_0 = s.replace(" ","")
elif guess == a2a:
correct = a2a
ts = list(s)
ts[2] = guess
s = "".join(ts)
print hangman
print guess
s_0 = s.replace(" ","")
elif guess == a1a:
correct = a1a
ts = list(s)
ts[0] = guess
s = "".join(ts)
print guess
s_0 = s.replace(" ","")
This didn't work. Any help please?
Aucun commentaire:
Enregistrer un commentaire