Simple program question.

E

eschneider92

How do I make it so I only have to type in 'parry' once?

import random
words=['hemisses', 'hestabsyou']
randomizer=random.choice(words)
if input()!=('duck', 'parry'):
print('try again')
if input()=='duck':
print(randomizer)
if randomizer=='hemisses':
results=['you should have ran', 'you win']
randomresult=random.choice(results)
print('do you wanna run or fight?')
if input()=='fight':
print(randomresult)
sys.exit()
if randomizer=='hestabsyou':
print('you done fail')
sys.exit()
words2=['you parry his blow', 'he stabs you right behind the clavicle']
randomizer2=random.choice(words2)
if input()=='parry':
print(randomizer2)
if randomizer2=='you parry his blow':
results2=['you should have run away', 'you wins!']
randomresult2=random.choice(results2)
print('do you wanna run or fight?')
if input()=='fight':
print(randomresult2)
sys.exit()
if randomizer2=='he stabs you right behind the clavicle':
print('Clavicle stab does 100 damage')
sys.exit()
 
C

Chris Angelico

if input()!=('duck', 'parry'):
if input()=='duck':
if input()=='parry':

Every time you call input(), it waits for you to type something. You
want to record what the person typed and then use it in each place.
Have you been taught a means of doing this?

ChrisA
 
R

russ.pobox

input() is a function which returns a string. You can assign this return value to a variable. That's what variables are for.

option = input()

Now you can use the variable named option in place of all those calls to input().

i.e:

....instead of..

if input() == 'parry':
# etc

....do this...

option = input()
if option == 'parry':
# etc
elif option == 'whatever':
# etc
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,778
Messages
2,569,605
Members
45,238
Latest member
Top CryptoPodcasts

Latest Threads

Top