Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #47513 > unrolled thread
| Started by | eschneider92@comcast.net |
|---|---|
| First post | 2013-06-09 20:06 -0700 |
| Last post | 2013-06-11 00:25 -0700 |
| Articles | 4 — 3 participants |
Back to article view | Back to comp.lang.python
Simple program question. eschneider92@comcast.net - 2013-06-09 20:06 -0700
Re: Simple program question. Chris Angelico <rosuav@gmail.com> - 2013-06-10 13:33 +1000
Re: Simple program question. eschneider92@comcast.net - 2013-06-10 23:47 -0700
Re: Simple program question. russ.pobox@gmail.com - 2013-06-11 00:25 -0700
| From | eschneider92@comcast.net |
|---|---|
| Date | 2013-06-09 20:06 -0700 |
| Subject | Simple program question. |
| Message-ID | <af6709e3-b446-443a-abe1-5f80d0c30387@googlegroups.com> |
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()
[toc] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2013-06-10 13:33 +1000 |
| Message-ID | <mailman.2953.1370835216.3114.python-list@python.org> |
| In reply to | #47513 |
On Mon, Jun 10, 2013 at 1:06 PM, <eschneider92@comcast.net> wrote:
> 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
[toc] | [prev] | [next] | [standalone]
| From | eschneider92@comcast.net |
|---|---|
| Date | 2013-06-10 23:47 -0700 |
| Message-ID | <717c05d5-2e1b-41fd-9891-491441136f9a@googlegroups.com> |
| In reply to | #47513 |
No.
[toc] | [prev] | [next] | [standalone]
| From | russ.pobox@gmail.com |
|---|---|
| Date | 2013-06-11 00:25 -0700 |
| Message-ID | <9d040c46-b78e-4705-bc13-a486b5922825@googlegroups.com> |
| In reply to | #47513 |
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
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web