2018-10-23 23:22:49

Although the code seems true, i can't understand why it shows me an error.

Code:
for i in range(-1000, 1000):
     for v in range(-1000, 1000):
     if k is v:
     print(k)
code:

How will i privent this from happenning in the future?


Thanks.

2018-10-24 00:20:02

what language is this in?
If it's a case-sensitive language, the first line has a capital C while the last line does not.  The print line is missing a colon but all of the other lines have one.

- Aprone
Please try out my games and programs:
Aprone's software

2018-10-24 03:25:31

It's python. Aprone nailed it. If you read the rather descriptive error, you´ll know exactly what happened.

NameError: name 'k' is not defined

So make sure you pay heed to differences in case. either change the loop to "k", or the print statement to "K", it really doesn't matter.

In the future, include your error so people who don't have a copy of the language installed might be able to pinpoint the issue without much of a guessing game.

2018-10-24 13:35:17 (edited by kianoosh 2018-10-24 13:35:53)

And indentations. You haven't put any higher indentation levels after the second for loop. You have to indent the codes after a for loop in a higher level, Same with if-else conditions which you didn't. So the correct form of code would be like this:
for i in range(-1000, 1000):
     for v in range(-1000, 1000):
          #Here I change k to i since k does not exist
          if i is v:
               print(k)

---
Co-founder of Sonorous Arts.
Check out Sonorous Arts on github: https://github.com/sonorous-arts/
my Discord: kianoosh.shakeri2#2988

2018-10-24 15:20:00 (edited by Turkce_Rap 2018-10-24 15:37:24)

kianoosh wrote:

And indentations. You haven't put any higher indentation levels after the second for loop. You have to indent the codes after a for loop in a higher level, Same with if-else conditions which you didn't. So the correct form of code would be like this:
for i in range(-1000, 1000):
     for v in range(-1000, 1000):
          #Here I change k to i since k does not exist
          if i is v:
               print(k)



Where didn't i indent? there is one indentation before the if case.

Do you mean i should press more than 4 times to space key if i  need indentation for second time?

Edit: should  i put k as a variable you meant i guess, such as k = (1000, -1000
= like that?

2018-10-24 15:22:17

cartertemm wrote:

It's python. Aprone nailed it. If you read the rather descriptive error, you´ll know exactly what happened.

NameError: name 'k' is not defined

So make sure you pay heed to differences in case. either change the loop to "k", or the print statement to "K", it really doesn't matter.

In the future, include your error so people who don't have a copy of the language installed might be able to pinpoint the issue without much of a guessing game.



i m more of a jaws guy, don't know how to copy that error with Nvda.

2018-10-24 15:23:18

Aprone wrote:

what language is this in?
If it's a case-sensitive language, the first line has a capital C while the last line does not.  The print line is missing a colon but all of the other lines have one.



Yea python.

2018-10-24 16:58:04

@5 yes.
Each thime you enter in a new block with python you have to indent.
It's your choice whether you want to use 4 spaces, 8 spaces or 1 space. But when you start with whatever indent level, that has to be constant. Which means that if you indent with 4 spaces, all the indentations have to be of 4 spaces.
Since my communicating skills suck I'll provide an Example:
# Example with indented blocks

name = str(input("enter your name"))
while True:
    # Since here you opened a block with the while statement, all the inner statements in the while functions have to be indented.
    if name == 'name':
        if 'n' in name:
            print(name)
As you can observe, when I opened if blocks and I wanted to put code that would follow the if statements I had to indent. This time I used 4 spaces indentation which is the one recommended from the PEP8, but I generally use 1 space, since I find 4 spaces a pain.
Hope you understood what I said, if you didn't do not worry, is known that my communicating skills are horrible.
@6
With NVDA you have 2 options.
1. Execute the script from CMD, and if it speaks the output copy it with speech history.
2. from the CMD execute the script, and if you want to copy the entire output do as follow:
press alt space, go in edit and press select all.
Repeat the same process but this time press copy. Go in a notepad or whatever file and paste.
Go at the end of the file and press up arrow a few times and you should be able to read your error.
Have fun coding!

Paul

2018-10-24 17:09:47

actually, so many people seem to forget speech viewer. if you open that before exicuting your script, speech viewer will capture it all. when in the viewer, you can do anything with the text just as if it were a web site, just remember it's read only.

2018-10-24 22:15:59

What is this code supposed to do?

Bitcoin Address:
1MeNca7h6m8du4TV3psN4m4X666p6Y36u5m

2018-10-26 14:33:20

pauliyobo wrote:

@5 yes.
Each thime you enter in a new block with python you have to indent.
It's your choice whether you want to use 4 spaces, 8 spaces or 1 space. But when you start with whatever indent level, that has to be constant. Which means that if you indent with 4 spaces, all the indentations have to be of 4 spaces.
Since my communicating skills suck I'll provide an Example:
# Example with indented blocks

name = str(input("enter your name"))
while True:
    # Since here you opened a block with the while statement, all the inner statements in the while functions have to be indented.
    if name == 'name':
        if 'n' in name:
            print(name)
As you can observe, when I opened if blocks and I wanted to put code that would follow the if statements I had to indent. This time I used 4 spaces indentation which is the one recommended from the PEP8, but I generally use 1 space, since I find 4 spaces a pain.
Hope you understood what I said, if you didn't do not worry, is known that my communicating skills are horrible.
@6
With NVDA you have 2 options.
1. Execute the script from CMD, and if it speaks the output copy it with speech history.
2. from the CMD execute the script, and if you want to copy the entire output do as follow:
press alt space, go in edit and press select all.
Repeat the same process but this time press copy. Go in a notepad or whatever file and paste.
Go at the end of the file and press up arrow a few times and you should be able to read your error.
Have fun coding!



as i see you put more than 4 spaces for the second if case, so does it mean should i put more spaces for second if and for cases/oops?

2018-10-26 14:58:16

you basically add 4 spaces each time you open an inner block inside a block.

Paul