+ 3
Python help!
Help me with this code because an error has occured and i dont know how to solve it! please tell me how to solve it please! https://code.sololearn.com/cisPoGmb5Do9/?ref=app
16 ответов
+ 3
Your problem is:
if x and y and w and q == True:
print("This is a Valid IP Adress")
else:
print("This is not a Valid IP Adress")
It should be indented with at least one space like this...
if x and y and w and q == True:
print("This is a Valid IP Adress")
else:
print("This is not a Valid IP Adress")
EDIT: Also if you want you can change the if statements e.g.
if x>0 and x<255:
into
if x in range(0, 255):
It's just more readable
+ 3
Link to their code:
https://code.sololearn.com/cisPoGmb5Do9/#py
+ 2
As Turtle said, fix your indentation. As well, you used your variables BEFORE you declared them, so just swap around that section at the top.
:::: CORRECTED VERSION :::::
#Is That A Valid IP Adress?
x= int(input("give the 1st number"))
y= int(input("give the 2nd number"))
w= int(input("give the 3rd number"))
q= int(input("give the 4th number"))
0<x<255
0<y<255
0<w<255
0<q<255
if x>0 and x<255: True
if y>0 and y<255: True
if w>0 and w<255: True
if q>0 and q<255: True
if x and y and w and q == True:
print("This is a Valid IP Adress")
else:
print("This is not a Valid IP Adress")
+ 2
thanks a lot!!!!
+ 2
Sorry, didn't think you all would respond back so fast. :D
As Turtle said, you'll want to use "\n" inside of your string literal.
\n = new line
Example based on your code:
x= int(input("give the 1st number\n"))
y= int(input("give the 2nd number\n"))
w= int(input("give the 3rd number\n"))
q= int(input("give the 4th number\n"))
Although they don't teach it here (I think?), HCI (human-computer interface) is by far one of the most important aspects of design and programming. You could have the best, most functional program on the face of the planet, but if your HCI is poorly designed, no one will want to use your program. End users want something that's functional, easy to use and something they can jump into without having to learn a bunch of stuff in order to use it. As such, you'll want to use common standards that people expected and provide a user-friendly interfacing system for them to use.
In the case of this code, you're just providing them with the means of being able to properly read the console output based upon common rules we use in written language.
PS - break is something that's used when dealing with loops. It breaks the loops and continues the code after that loop. Think of the break command as an exit point for loops.
+ 1
guys check out again the code because it occures an error that i have never seen before. sorry if i am asking so many questions and searching for solves but this is my first program....
+ 1
@xLeva I ran the code it works fine for me
+ 1
@xLeva
I ran your code again and it works flawlessly (as far as logic) after you've made the changes that Turtle & I suggested to you. Only change I'd make is in regard to the presentation of the output - add in line breaks so output isn't jumbled up together.
+ 1
This \n
+ 1
After the input text like so ... input("give first number: \n")
+ 1
Put the \n inside the string
0
Jakob Marley do you mean the break command?
0
where shpuld i put it in? (i need to redo the python leasson)(i have already started tho...)
0
TurtleShell take a look at my code
0
TurtleShell please write me the code cause i have to leave. thanks a lot bro
0
bro you are the best thanknyou