#๐Ÿ”’ why aren't my calls working?

141 messages ยท Page 1 of 1 (latest)

dense matrixBOT
#

@latent dragon

Python help channel opened

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.

latent dragon
#
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...

latent dragon
#
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

lethal hatch
#

hi

latent dragon
#

U keen on python

latent dragon
#

yeah

lethal hatch
latent dragon
#

I've been on cialis for 3 years

lethal hatch
#

so let's say i input incendio
what is supposed to happen

latent dragon
#

if u spell it correctly.

lethal hatch
#

then 15 dmg to tom?

latent dragon
#

milkaveli == k and tom riddle loses the associated value

#

yes

lethal hatch
#

but the script under it runs with the if milkaveli

latent dragon
#

default damage for not entering a key in the dictionary is 15

lethal hatch
#

oh ok

latent dragon
#

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

lethal hatch
#

wait the script works

#

i tested it

latent dragon
#

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

lethal hatch
#

when I put incendio, tom's hp is 85

latent dragon
#

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)
lethal hatch
#
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))
latent dragon
#

maybe just for k in spells.items():

#

then i can do all the dictionary work on the line...

lethal hatch
#

how can both die?

latent dragon
#

yes... that's the question

#

death to all

#

mass genocide

#

I dont think they can both die lol

lethal hatch
#
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

latent dragon
#
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

lethal hatch
#

what does milkaveli mean?

latent dragon
#

!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)

dense matrixBOT
#

@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
latent dragon
#

@lethal hatch If the first code returns values for harry and tom...dependign on execution... why doesnt second call work...

lethal hatch
latent dragon
#

harry and tom start with values of 100

lethal hatch
#

yep

latent dragon
#

i set milkaveli to "incendio"

lethal hatch
#

ok

latent dragon
#

cos u cant do input here

lethal hatch
#

yep

latent dragon
#

!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)

dense matrixBOT
#

@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
latent dragon
#

i gotta do var harry?

lethal hatch
#

yeah

#

harry =

latent dragon
#

isntthat java?

lethal hatch
#

nah i just meant like

#

u have to define those variables

#

harry = 100
Tom_riddle = 100

#

but outside the function

latent dragon
#

i understand like an empty_list =[] before concatenation

lethal hatch
#

u can't call a variable that doesn't exist

latent dragon
#

veryimportant functions get their parameters to execute.

lethal hatch
#

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))
dense matrixBOT
#

@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
lethal hatch
#

!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))
latent dragon
#

!e ```py
this is code

dense matrixBOT
#

@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
latent dragon
#

!code

dense matrixBOT
#

@lethal hatch :white_check_mark: Your 3.12 eval job has completed with return code 0.

Harry: 100, Tom: 85
#
Formatting code on Discord

Here's how to format Python code on Discord:

```py
print('Hello world!')
```

These are backticks, not quotes. Check this out if you can't find the backtick key.

For long code samples, you can use our pastebin.

latent dragon
#

read dat^

lethal hatch
#

i see

lethal hatch
latent dragon
#

It would be cool if we made a quick in succession save from previous iteration

lethal hatch
#

!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))
dense matrixBOT
#

@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
latent dragon
#
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...

lethal hatch
#

harry = 100

harry = ask_prof_pooper(harry, Tom_riddle)

latent dragon
#

while harry > 0 and Tom_riddle > 0 :

lethal hatch
#

wait..

#

hold on

#

that's not right

#

lemme try

#

something

latent dragon
#

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

lethal hatch
#

u could put the health change inside the function

#

woah what did i come back to

latent dragon
#

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

lethal hatch
latent dragon
#

wdym

lethal hatch
#

im curious

latent dragon
#

29

lethal hatch
#

teacher?

latent dragon
#

-7

lethal hatch
#

ah

latent dragon
#

idk how old my teacher is.

lethal hatch
#

ur 22?

latent dragon
#

they probably spent like 10 years editing this.!

lethal hatch
#

i can't tell if ur trolling or not ๐Ÿ˜ญ

#

i like the health bars

#

it's pretty ingenious

#

wouldn't've thought of it

latent dragon
#

!close

dense matrixBOT
#
Python help channel closed

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.