#๐ why aren't my calls working?
141 messages ยท Page 1 of 1 (latest)
@latent dragon
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
spells = {'expelliarmus': 20, 'incendio': 15, 'stupefy': 10, 'confringo': 15, 'rictusempra' : 5}
def ask_prof_pooper(harry, Tom_riddle):
milkaveli = input("spell name?")
Harry = 100
Tom_riddle = 100
for (k,v) in spells.items():
if milkaveli == k:
Tom_riddle = 100-v
return Tom_riddle
else:
Harry = 100-v
return Harry
ask_prof_pooper(100,100)
Like for instance I type in 'incendio' and it takes off the value marked with the key pair expelliarmus...
spells = {'expelliarmus': 20, 'incendio': 15, 'stupefy': 10, 'confringo': 15, 'rictusempra' : 5}
def ask_prof_pooper(harry, Tom_riddle):
milkaveli = input("spell name?")
if harry!= 0 or Tom_riddle !=0:
for (k,v) in spells.items():
if milkaveli == k:
Tom_riddle -= v
return Tom_riddle
if milkaveli != k:
Harry -= 15
return Harry
ask_prof_pooper(20,100)
---> 10 Harry -= 15
11 return Harry
UnboundLocalError: cannot access local variable 'Harry' where it is not associated with a value
spells = {'expelliarmus': 20, 'incendio': 15, 'stupefy': 10, 'confringo': 15, 'rictusempra' : 5}
def ask_prof_pooper(harry, Tom_riddle):
milkaveli = input("spell name?")
if harry!= 0 or Tom_riddle !=0:
for (k,v) in spells.items():
if milkaveli == k:
Tom_riddle -= v
return Tom_riddle
if milkaveli not in k:
harry -= 15
return harry
if harry == 0 and Tom_riddle == 0:
print("Both die")
elif harry == 0 and Tom_riddle > 0:
print("Tom Riddle Lives, you lose!")
elif harry > 0 and Tom_riddle == 0:
print("Harry Potter lives, Tom Riddle dies")
exit()
ask_prof_pooper(15,100)
@lethal hatch Hi
hi
U keen on python
Case sensitivity
yeah
ofc
I've been on cialis for 3 years
so let's say i input incendio
what is supposed to happen
if u spell it correctly.
then 15 dmg to tom?
but the script under it runs with the if milkaveli
oh ok
are u suggesting a reversal of the conditional?
or simply suggesting the second one should be elif
as they both relate to the overarching variable
for some reason its just taking away harry's last health points
also now i kinda want to watch the entire harry potter saga
but you have legion's ayree disease
@lethal hatch It only works for expellarmius
which means we aren't getting to iterate through the k, v pairs in the dictionary
when I put incendio, tom's hp is 85
maybe the function isn't getting the values and i should pull the dicitonary into the definition
that's good
when i put I get zero
ask_prof_pooper(15,100)
this is my call ^
it works now...
wait nvm
its broken
def ask_prof_pooper(harry, Tom_riddle):
spells = {'expelliarmus': 20, 'incendio': 15, 'stupefy': 10, 'confringo': 15, 'rictusempra' : 5}
milkaveli = input("spell name?")
if harry!= 0 or Tom_riddle !=0:
for (k,v) in spells.items():
if milkaveli == k:
Tom_riddle -= v
return Tom_riddle
elif milkaveli not in k:
harry -= 15
return harry
if harry == 0 and Tom_riddle == 0:
print("Both die")
elif harry == 0 and Tom_riddle > 0:
print("Tom Riddle Lives, you lose!")
elif harry > 0 and Tom_riddle == 0:
print("Harry Potter lives, Tom Riddle dies")
exit()
ask_prof_pooper(15,100)
Harry = 100
Tom_riddle = 100
spells = {'expelliarmus': 20,
'incendio': 15,
'stupefy': 10,
'confringo': 15,
'rictusempra': 5}
def ask_prof_pooper(H, T):
milkaveli = input('spell name? ')
for (k,v) in spells.items():
if milkaveli == k:
T -= v
print('t')
return T
if milkaveli not in k:
H -= 15
return H
print(ask_prof_pooper(Harry,Tom_riddle))
maybe just for k in spells.items():
then i can do all the dictionary work on the line...
how can both die?
yes... that's the question
death to all
mass genocide
I dont think they can both die lol
spells = {'expelliarmus': 20,
'incendio': 15,
'stupefy': 10,
'confringo': 15,
'rictusempra': 5}
def ask_prof_pooper(Harry, Tom_riddle):
milkaveli = input("spell name? ")
if Harry!= 0 or Tom_riddle !=0:
for (k,v) in spells.items():
if milkaveli == k:
Tom_riddle -= v
if milkaveli not in spells:
Harry -= 15
if Harry == 0 and Tom_riddle == 0:
print("Both die")
elif Harry == 0 and Tom_riddle > 0:
print("Tom Riddle Lives, you lose!")
elif Harry > 0 and Tom_riddle == 0:
print("Harry Potter lives, Tom Riddle dies")
else:
print(Harry, Tom_riddle)
exit()
print(ask_prof_pooper(100,100))
script works
def ask_prof_pooper(harry, Tom_riddle):
spells = {'expelliarmus': 20, 'incendio': 15, 'stupefy': 10, 'confringo': 15, 'rictusempra' : 5}
milkaveli = input("spell name?")
if harry!= 0 and Tom_riddle !=0:
for (k,v) in spells.items():
if k == milkaveli:
Tom_riddle -= v
return Tom_riddle
if milkaveli not in spells.keys():
harry -= 15
return harry
yes my script works.
lets' create the new spotify
so.. solved
what does milkaveli mean?
random artist
!e ```py
def ask_prof_pooper(harry, Tom_riddle):
spells = {'expelliarmus': 20, 'incendio': 15, 'stupefy': 10, 'confringo': 15, 'rictusempra' : 5}
milkaveli = "incendio"
if harry!= 0 and Tom_riddle !=0:
for (k,v) in spells.items():
if k == milkaveli:
Tom_riddle -= v
print(Tom_riddle)
return Tom_riddle
if milkaveli not in spells.keys():
harry -= 15
print(harry)
return harry
ask_prof_pooper(100,100)
why no output???
!e ```py
def ask_prof_pooper(harry, Tom_riddle):
spells = {'expelliarmus': 20, 'incendio': 15, 'stupefy': 10, 'confringo': 15, 'rictusempra' : 5}
milkaveli = "incendio"
if harry!= 0 and Tom_riddle !=0:
for (k,v) in spells.items():
if k == milkaveli:
Tom_riddle -= v
print(Tom_riddle)
return Tom_riddle
if milkaveli not in spells.keys():
harry -= 15
print(harry)
return harry
ask_prof_pooper(100,100)
ask_prof_pooper(harry,Tom_riddle)
!e ```py
def ask_prof_pooper(harry, Tom_riddle):
spells = {'expelliarmus': 20, 'incendio': 15, 'stupefy': 10, 'confringo': 15, 'rictusempra' : 5}
milkaveli = "incendio"
if harry!= 0 and Tom_riddle !=0:
for (k,v) in spells.items():
if k == milkaveli:
Tom_riddle -= v
print(Tom_riddle)
return harry, Tom_riddle
if milkaveli not in spells.keys():
harry -= 15
print(harry)
return harry, Tom_riddle
ask_prof_pooper(100,100)
ask_prof_pooper(harry,Tom_riddle)
@latent dragon :x: Your 3.12 eval job has completed with return code 1.
001 | 85
002 | Traceback (most recent call last):
003 | File "/home/main.py", line 15, in <module>
004 | ask_prof_pooper(harry,Tom_riddle)
005 | ^^^^^
006 | NameError: name 'harry' is not defined
@lethal hatch If the first code returns values for harry and tom...dependign on execution... why doesnt second call work...
I'm sorry I don't understand what u mean
harry and tom start with values of 100
yep
i set milkaveli to "incendio"
ok
cos u cant do input here
yep
!e ```py
def ask_prof_pooper(harry, Tom_riddle):
spells = {'expelliarmus': 20, 'incendio': 15, 'stupefy': 10, 'confringo': 15, 'rictusempra' : 5}
milkaveli = "incendio"
if harry!= 0 and Tom_riddle !=0:
for (k,v) in spells.items():
if k == milkaveli:
Tom_riddle -= v
print(Tom_riddle)
return harry, Tom_riddle
if milkaveli not in spells.keys():
harry -= 15
print(harry)
return harry, Tom_riddle
ask_prof_pooper(100,100)
ask_prof_pooper(harry,Tom_riddle)
@latent dragon :x: Your 3.12 eval job has completed with return code 1.
001 | 85
002 | Traceback (most recent call last):
003 | File "/home/main.py", line 15, in <module>
004 | ask_prof_pooper(harry,Tom_riddle)
005 | ^^^^^
006 | NameError: name 'harry' is not defined
u didn't define var harry and tom riddle
i gotta do var harry?
isntthat java?
nah i just meant like
u have to define those variables
harry = 100
Tom_riddle = 100
but outside the function
i understand like an empty_list =[] before concatenation
u can't call a variable that doesn't exist
veryimportant functions get their parameters to execute.
wdym
how do i use this !e
!e
spells = {'expelliarmus': 20,
'incendio': 15,
'stupefy': 10,
'confringo': 15,
'rictusempra': 5}
def ask_prof_pooper(Harry, Tom):
spell = input('Spell name? ')
for (k,v) in spells.items():
if k == spell:
Tom -= v
return f'Harry: {Harry}, Tom: {Tom}'
if spell not in spells.keys():
Harry -= 15
return f'Harry: {Harry}, Tom: {Tom}'
print(ask_prof_pooper(100, 100))
@lethal hatch :x: Your 3.12 eval job has completed with return code 1.
:warning: Note: input is not supported by the bot :warning:
001 | Spell name? Traceback (most recent call last):
002 | File "/home/main.py", line 17, in <module>
003 | print(ask_prof_pooper(100, 100))
004 | ^^^^^^^^^^^^^^^^^^^^^^^^^
005 | File "/home/main.py", line 8, in ask_prof_pooper
006 | spell = input('Spell name? ')
007 | ^^^^^^^^^^^^^^^^^^^^^
008 | EOFError: EOF when reading a line
!e
spells = {'expelliarmus': 20,
'incendio': 15,
'stupefy': 10,
'confringo': 15,
'rictusempra': 5}
def ask_prof_pooper(Harry, Tom):
spell = 'incendio'
for (k,v) in spells.items():
if k == spell:
Tom -= v
return f'Harry: {Harry}, Tom: {Tom}'
if spell not in spells.keys():
Harry -= 15
return f'Harry: {Harry}, Tom: {Tom}'
print(ask_prof_pooper(100, 100))
!e ```py
this is code
@latent dragon :x: Your 3.12 eval job has completed with return code 1.
001 | Traceback (most recent call last):
002 | File "/home/main.py", line 1, in <module>
003 | py
004 | ^^
005 | NameError: name 'py' is not defined
@lethal hatch :white_check_mark: Your 3.12 eval job has completed with return code 0.
Harry: 100, Tom: 85
read dat^
i see
it doesn't work because in this instance, the variables harry and Tom_riddle don't exist so you're calling on nothing
It would be cool if we made a quick in succession save from previous iteration
!e
spells = {'expelliarmus': 20,
'incendio': 15,
'stupefy': 10,
'confringo': 15,
'rictusempra': 5}
def ask_prof_pooper(Harry, Tom):
spell = 'incendio'
for (k,v) in spells.items():
if k == spell:
Tom -= v
return f'Harry: {Harry}, Tom: {Tom}'
if spell not in spells.keys():
Harry -= 15
return f'Harry: {Harry}, Tom: {Tom}'
print(ask_prof_pooper(100, 100))
Harry = 100
Tom = 100
print(ask_prof_pooper(Harry, Tom))
@lethal hatch :white_check_mark: Your 3.12 eval job has completed with return code 0.
001 | Harry: 100, Tom: 85
002 | Harry: 100, Tom: 85
harry = 100
Tom_riddle =100
def ask_prof_pooper(harry, Tom_riddle):
spells = {'expelliarmus': 20, 'incendio': 15, 'stupefy': 10, 'confringo': 15, 'rictusempra' : 5}
milkaveli = "incendio"
if harry!= 0 and Tom_riddle !=0:
for (k,v) in spells.items():
if k == milkaveli:
Tom_riddle -= v
return harry, Tom_riddle
if milkaveli not in spells.keys():
harry -= 15
return harry, Tom_riddle
print(ask_prof_pooper(harry,Tom_riddle))
while harry > 0 and Tom_riddle > 0 :
print(ask_prof_pooper(harry,Tom_riddle))
how we make it save 85
so 002 should be 60...
harry = 100
harry = ask_prof_pooper(harry, Tom_riddle)
while harry > 0 and Tom_riddle > 0 :
wat
wait..
hold on
that's not right
lemme try
something
oh wait u wanna look at the answer
he
he
import time
import math
# initialize Harry and Voldemort's HPs
harry = 100
voldemort = 100
# create a spell dictionary, where key is spell, value is damage to voldemort
spells = {'expelliarmus': 20, 'incendio': 15, 'stupefy': 10, 'confringo': 15, 'rictusempra': 5}
print('Finally! Harry Potter!')
time.sleep(1) # sleep for 1s (optional)
# iterate while both Harry and Voldemort have HPs > 0
while harry > 0 and voldemort > 0:
print('\b' * 1000) # clean the system output (optional)
# HP bar printing (optional)
print('Voldemort HP\t\t\t\tHarry HP')
print('โ' + 'โ' * 20 + 'โ' + '\t' + 'โ' + 'โ' * 20 + 'โ')
print('โ' + 'โ' * max(0,(voldemort // 5)) + ' ' * (20 - max(0,math.ceil(voldemort / 5)))+ 'โ' + '\t' + 'โ' + ' ' * (20 - max(0,math.ceil(harry / 5))) + 'โ' * max(0,(harry // 5)) + 'โ')
print('โ' + 'โ' * 20 + 'โ' + '\t' + 'โ' + 'โ' * 20 + 'โ')
harry_spell = input('Cast a spell! ') # Ask Harry to type in a spell
if harry_spell.lower() in spells: # check if the spell typed(in lower case because of case insensitive) is in the dictionary
voldemort -= spells[harry_spell.lower()] # if so, HP of Voldemort decrease by the damage
print("Ouch harmed!\n") # Some bluffing
time.sleep(1) # sleep for 1s (optional)
else: # the spell is not in dictionary
harry -= 15 # Harry's HP reduces by 15
print("You suck") # Some mocking
time.sleep(1) # sleep for 1s (optional)
print('\b' * 1000) # clean the system output (optional)
# HP bar printing (optional)
print('Voldemort HP\t\t\t\tHarry HP')
print('โ' + 'โ' * 20 + 'โ' + '\t' + 'โ' + 'โ' * 20 + 'โ')
print('โ' + 'โ' * max(0,(voldemort // 5)) + ' ' * (20 - max(0,math.ceil(voldemort / 5)))+ 'โ' + '\t' + 'โ' + ' ' * (20 - max(0,math.ceil(harry / 5))) + 'โ' * max(0,(harry // 5)) + 'โ')
print('โ' + 'โ' * 20 + 'โ' + '\t' + 'โ' + 'โ' * 20 + 'โ')
if harry > 0: # Harry survives
print("")
else: # Voldemort survives
print("Muahaha.!")
damn they went above and beyond I feel like im about to enter the fucking baldur's gate of hogwarts legacy
THIS IS EPIC
This is my teacher's solution
HAhaha
let's justlook at the basic code
harry_spell = input('Cast a spell! ') # Ask Harry to type in a spell
if harry_spell.lower() in spells: # check if the spell typed(in lower case because of case insensitive) is in the dictionary
voldemort -= spells[harry_spell.lower()] # if so, HP of Voldemort decrease by the damage
how old r u
wdym
im curious
29
teacher?
-7
ah
idk how old my teacher is.
ur 22?
they probably spent like 10 years editing this.!
i can't tell if ur trolling or not ๐ญ
i like the health bars
it's pretty ingenious
wouldn't've thought of it
!close
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.
