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.
You are not logged in. Please login or register.
AudioGames.net Forum → Developers room → What's wrong with this code?
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.
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.
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.
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)
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?
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.
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.
@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!
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.
What is this code supposed to do?
@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 blocksname = 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?
you basically add 4 spaces each time you open an inner block inside a block.
AudioGames.net Forum → Developers room → What's wrong with this code?
Generated in 0.026 seconds (41% PHP - 59% DB) with 12 queries