dimanche 29 mars 2015

If statement won't work in python 2.7.9

I'm writing a twitterbot, and for some reason I got a problem. here's the code (Ommitting my Access/Consumer keys of course). I based this off an earlier code of mine that worked so I don't see the problem. The first one is the new code...



while True:
choice1 = random.choice(choices)
choice2 = random.choice(choices)
api.update_status(status="Turn %s, Dice 1: %s, Dice 2: %s" % (turns, choice1, choice2)
**if choice1 == choice2:**
if doubles == 2:
api.update_status(status="I will not be able to tweet anymore, because I had to go to jail. I have served my purpose.")
break
else:
doubles = doubles + 1
else:
turns = turns + 1
doubles = 0
time.sleep(25)


And the second is the old one.



import random
turns = 1
doubles = 0
choices = [1, 2, 3, 4, 5, 6]
while True:
print 'Turn %s:' % (turns)
choice1 = random.choice(choices)
print choice1
choice2 = random.choice(choices)
print choice2
print ' '
if choice1 == choice2:
if doubles == 2:
print 'You got doubles three times! in a row! Go to jail!'
break
else:
doubles = doubles + 1
else:
turns = turns + 1
doubles = 0


The code that's glitching is nearly the same so I'm confused why it's not working.





Aucun commentaire:

Enregistrer un commentaire