#🔒 Problem using a variable inside a function as a conditional for a while loop
115 messages · Page 1 of 1 (latest)
@bitter swift
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.
What exactly is the full error? These lines look sketchy though:
incendio(bosque)
bosque=incendio(bosque)
You call the same function twice in a row with the same argument, and overwrite bosque only the second time?
That wouldn't cause that error alone, but it looks off.
burningtrees= incendio(bosque)
burningtrees=burningtrees[1]
while burningtrees>0:
#preguntarle al santi como era por que lo borre y me re olvide
bosque=incendio(bosque)
tiempo+=1
Hey @bitter swift!
It looks like you're trying to paste code into this channel.
Discord has support for Markdown, which allows you to post code with full syntax highlighting. Please use these whenever you paste code, as this helps improve the legibility and makes it easier for us to help you.
To do this, use the following method:
```py
print('Hello, world!')
```
This will result in the following:
print('Hello, world!')```
You can **edit your original message** to correct your code block.
rboles quemados: 0
Traceback (most recent call last):
File "c:\Users\Luciano\Desktop\Udesa\Pensamiento Computacional\Práctica\TP1\TP GOTY Edition.py", line 162, in <module>
bosque=incendio(bosque)
^^^^^^^^^^^^^^^^
File "c:\Users\Luciano\Desktop\Udesa\Pensamiento Computacional\Práctica\TP1\TP GOTY Edition.py", line 98, in incendio
vecino1=matriz2[columna-1][fila-1]
~~~~~~~~~~~~~~~~~~^^^^^^^^
TypeError: 'int' object is not subscriptable
PS C:\Users\Luciano\Desktop\Udesa\Pensamiento Computacional\Práctica>
there is it
return matriz3, burningtrees
burningtrees= incendio(bosque)
burningtrees=burningtrees[1]
while burningtrees>0:
#preguntarle al santi como era por que lo borre y me re olvide
bosque=incendio(bosque)
tiempo+=1```
there, when i made these last changes, i got the error
the first version of the code is the one that "works"
Show the full code that causes the error. I thought the code you showed was the broken code.
Here you've got me doubting my debugging ability since the code you posted can not cause that error as far as I could tell.
there is a problem with te vscode debugger
when it gets to the list comprehension
just skip to the next breakpoint
i discovered it with my teacher
return matriz3, burningtrees
bosque=incendio(bosque)
You're returning a tuple from the function, assigning that tuple to bosque, then treating that tuple as a matrix and passing the tuple as a matrix back in to incedio.
OHHHHHHHHH
i think i get it
i have to do
bosque=incendio(bosque[0])
something like this?
burningtrees in an int, so with vecino1=matriz2[columna-1][fila-1], the second subscript is attempting to subscript burningtrees.
And ya, or
matrix, burningtrees = incendio(matrix)
Or something like that using unpacking.
New errors/problems are typically at least progress.
yes
look
i think im getting there
the problem here is that it runs indefinitely
xd
Your loop is depedendant on burningtrees to stop (given the condition), but you never change burningtrees in the loop.
So if the loop is ever entered, it will run forever.
let me see how i can solve it
when it gets to the top line, wont it call the function again?
burningtrees=incendio(bosque)
sorry for the crop
incwendio returns a tuple still doesn't it? So bosque contains the burningtrees value, but you never actually reassign burningtrees there.
im getting another error
mixing languages in variable names :)
[0] is removing burningtrees before assigning it to bosque.
burningtrees, but bosque
i dont get it
the first words are English, the second word is Spanish
oh yes
thats bc i ran oout of variable names
and "arbolesquemando" was not really an atractive name
now you know why ppl usually write code in English :s
burnigtrees for the epic factor
yes
but this is for an assignment
but also should be snake_case
so at least burning_trees
im on my first year of engineering
GL
thanks bro
yup, thts on me
thanks @pliant hawk @crimson pendant
did you write the comments in the code?
I would not format them as they are
spaghetti at its finest
makes it hard to read
hm
just put one space after the #
also use them sparingly
thx bro
?
don't overuse them
yes
it's not really a helpful comment IMO
youre right
I can give some more "tips" if you want?
e.g
# FUEGO CENTRAL
centro = dimension // 2
for d_fila in (-1, 0, 1):
for d_columna in (-1, 0, 1):
bosque_vacio[centro + d_fila][centro + d_columna] = n
oh also sometimes you write this matriz2[columna][fila], which isn't actually correct
the "fila" should be first
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.