Re: [Tutor] Help
On Tue, May 15, 2018 at 08:01:13PM -0500, boB Stepp wrote: > On Tue, May 15, 2018 at 7:51 PM, Steven D'Aprano wrote: > > > You also seem to be using Python 2. In Python 2, you should never use > > the input() function. Instead, use raw_input() instead. > > What are you seeing that suggests the OP is using Python 2? I am > missing what you are seeing/understanding. Excellent question :-) The traceback Sam posted says (in part): Move = input('What Will You Do? Fight or Run: ') File "", line 1, in NameError: name 'Run' is not defined so the failed line was the call to input(). In Python 3, it would return a string. In Python 2, input() evaluates whatever the user types as code, hence I infer Sam typed: Run and input() tries to evaluate it, which fails. Also, the following line says: if Move == Fight: pass If input() returned a string, as in Python 3, then the next line would run and Sam would have got a name error for Fight. This didn't happen. -- Steve ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help
On Tue, May 15, 2018 at 7:51 PM, Steven D'Aprano wrote: > You also seem to be using Python 2. In Python 2, you should never use > the input() function. Instead, use raw_input() instead. What are you seeing that suggests the OP is using Python 2? I am missing what you are seeing/understanding. -- boB ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help
On Tue, May 15, 2018 at 02:49:54PM -0500, Sam Hoffman wrote: > Traceback (most recent call last): > File "/Users/samhoffman/Documents/test.py", line 54, in > Battle() > File "/Users/samhoffman/Documents/test.py", line 41, in Battle > Move = input('What Will You Do? Fight or Run: ') > File "", line 1, in > NameError: name 'Run' is not defined You need to either define a value for Run: Run = 2468 or you need to quote it, making it a string. Same applies to your Fight: > if Move == Fight: > pass > elif Move == Run: Both of these ought to be "Fight" and "Run" in quotes. You also seem to be using Python 2. In Python 2, you should never use the input() function. Instead, use raw_input() instead. -- Steve ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help
Greetings! On Tue, May 15, 2018 at 2:49 PM, Sam Hoffman wrote: > Traceback (most recent call last): > File "/Users/samhoffman/Documents/test.py", line 54, in > Battle() > File "/Users/samhoffman/Documents/test.py", line 41, in Battle > Move = input('What Will You Do? Fight or Run: ') > File "", line 1, in > NameError: name 'Run' is not defined The Python interpreter believes that Run is a variable to which no value has been assigned. > > import time > import random > #Pokemon Stats > Bulbasaur = {'N' : 'Bulby', > 'HP' : 20, > 'Level' : 5, > 'Atk' : 8, > 'Def' : 9, > 'Spd' : 6} > > > Rattata = {'N' : 'Rattata', >'HP' : 15, >'Level' : 3, >'Atk' : 5, >'Def' : 6, >'Spd' : 4} > > #Move damages > BM = {'Vinewhip' : 45, > 'Tackle' : 40, > 'Razorleaf' : 55} > > > RM = {'Tackle' : 40, > 'Quick Attack' : 40, > 'Bite' : 60} > > > #Damage is (2xLevel)/5)+2)xPower)xAtk/Def)+2)/50 > > > > #Battle Function > def Battle(): > print('Wild '+Rattata['N']+' Appeared!') > time.sleep(1) > print('Go, '+Bulbasaur['N']+'!') > time.sleep(1) > print(Bulbasaur['N']+ ' is out.') > while Bulbasaur['HP'] >= 1 and Rattata['HP'] >= 1: > Move = input('What Will You Do? Fight or Run: ') > if Move == Fight: > pass > elif Move == Run: # This appears to be the problem. Make Run into a > string, "Run" or 'Run'. > RC = random.randint(1,3) > if RC == 1 or 3: # This probably does not do what you think it > does! > print('You Didn\'t Get Away!') > else: > print('You Got Away!') > break > else: > print('Typo') > break > Battle() HTH! -- boB ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Help
Traceback (most recent call last): File "/Users/samhoffman/Documents/test.py", line 54, in Battle() File "/Users/samhoffman/Documents/test.py", line 41, in Battle Move = input('What Will You Do? Fight or Run: ') File "", line 1, in NameError: name 'Run' is not defined import time import random #Pokemon Stats Bulbasaur = {'N' : 'Bulby', 'HP' : 20, 'Level' : 5, 'Atk' : 8, 'Def' : 9, 'Spd' : 6} Rattata = {'N' : 'Rattata', 'HP' : 15, 'Level' : 3, 'Atk' : 5, 'Def' : 6, 'Spd' : 4} #Move damages BM = {'Vinewhip' : 45, 'Tackle' : 40, 'Razorleaf' : 55} RM = {'Tackle' : 40, 'Quick Attack' : 40, 'Bite' : 60} #Damage is (2xLevel)/5)+2)xPower)xAtk/Def)+2)/50 #Battle Function def Battle(): print('Wild '+Rattata['N']+' Appeared!') time.sleep(1) print('Go, '+Bulbasaur['N']+'!') time.sleep(1) print(Bulbasaur['N']+ ' is out.') while Bulbasaur['HP'] >= 1 and Rattata['HP'] >= 1: Move = input('What Will You Do? Fight or Run: ') if Move == Fight: pass elif Move == Run: RC = random.randint(1,3) if RC == 1 or 3: print('You Didn\'t Get Away!') else: print('You Got Away!') break else: print('Typo') break Battle() ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor