Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Python 

Undefined syntax and indent error

Does anyone have advice on how to string blocks of code together?

What I have now all works when blocks of code are isolated.

But what I define in those blocks are coming up as undefined
Would you be able to post your code so far so we can help you better and to get better context to what you mean?
First of all, I hope you use proper IDE such as PyCharm/Visual Code/Atom or whatever,
don't use notepad or notepad++ to write python, it will get you a hard time if you don't know what you are doing.

If you want us to help you, you gotta share your code.

Your errors related to basically not understanding the fundamentals of Python,
you can define your indentation, but once you define it you gotta keep using it for the whole code.

and yes, there is a difference between a 'space' indentation and a 'Tab' indentation, even if the code looks aligned
Dude .
Incorrect usage of scope?

Here’s a snippet of code from my program
Code
n = set()
N = set()
k = [n]
for n in N:
    a = set((k[n]) == k[n] in set(0, 1))
print(a)

I’m wondering how to print a
At least that’s what I’m saying on here
(Damn firewall)
(Jul 27, 2021 09:23 AM)simmer Wrote:  Incorrect usage of scope?

Here’s a snippet of code from my program
Code
n = set()
N = set()
k = [n]
for n in N:
    a = set((k[n]) == k[n] in set(0, 1))
print(a)

I’m wondering how to print a
At least that’s what I’m saying on here
(Damn firewall)

It's quite hard to understand you, that snippet is a 100% mess.
I don't even know where to start, what's the obsession with set()?

You can't iterate over an empty collection, N is empty -> 'for' loop will not happen -> a is not defined.
You can't iterate over N with n, I'm not sure what you tried to do here, but that param you define for the iteration should be a completely new param,
so saying " for n in N" make no sense here, I mean the param will be n, it will get each value
in N, but it will not be related to the first "n = set()" you defined at the beginning.

also, set() is a function, the base idea of that function is to take a list and return a set,
so far so good, but if you look into set() function you will see it get at most 1 argument,
which means set(0,1) make no sense, the correct way will be set([0,1]), but why even use set here? just type "[0,1]" it 100% percent the same effect here
and even in a more efficient way.

That's an achievement for sure, that 6 lines of code is like having 10 typos in a word that only have 2 chars.
Go back to basics, learn Python from the very beginning.

Also, I have no clue what "firewall" is related to here?
I'm so confused
Dude .
Ok so I shouldn’t have taken a single line directly from my code (it caused a lot of confusion)

This:
Code
for x in range(10):
    x

print x

is similar
(Jul 28, 2021 02:39 PM)simmer Wrote:  Ok so I shouldn’t have taken a single line directly from my code (it caused a lot of confusion)

This:
Code
for x in range(10):
    x

print x

is similar

Again, get decent IDE, as suggested above. At least it will show syntax and some of logical errors.
Also, no idea what you trying to do with this loop. It will always print last value.
That’s what I intended

I guess the problem is something else


Possibly Related Threads...
Thread / Author Replies Views Last Post
[C] by oh9odSep 16, 2020 04:24 PM 5 181 Sep 16, 2020 04:24 PM
Last Post: omboml
[Python] by ZakMay 2, 2018 05:26 AM 2 115 May 2, 2018 05:26 AM
Last Post: F.A.S.T
[Python] by OliFlawJul 24, 2017 09:44 AM 10 197 Jul 24, 2017 09:44 AM
Last Post: OliFlaw