+ 1

Can some one tell me how should I go to the next line? for solving this i used ";" but it doesn't work here.

20th Jan 2021, 6:38 PM
Morteza
Morteza - avatar
15 odpowiedzi
+ 5
thats correct, python uses new lines and indents, not semicolons it should go: age=input() name=input() if int(age) <5: print(name + ' is a child.') # see above how print is indented?
20th Jan 2021, 8:57 PM
Slick
Slick - avatar
+ 2
post your code so we can help please
20th Jan 2021, 6:52 PM
Slick
Slick - avatar
+ 1
Morteza I think that is because of the "if" that is not entered on the next line with its condition age = input() ; name = input() ; if int(age) < 5: print(name+'child')
21st Jan 2021, 3:46 AM
noteve
noteve - avatar
+ 1
Morteza ( 1 ) Do you mean typing the input? Then try it like this: 4 Myname # 4 will be assigned to "age" variable and Myname will be assigned to "name" variable. It is because semicolon means next line of the program.
21st Jan 2021, 6:19 AM
noteve
noteve - avatar
+ 1
( 2 ) Or if what you are trying to do is to get the input on the same line. For example like this: 4 Myname # Then you can use "Unpacking of values". - - - - - - - - - - - - - - - - - - - - age, name = input().split() string.split() converts the string to list by whitespace by default (you can split the string whatever character you want). For example: "4 Myname".split() >> [ "4", "Myname" ] Then we unpack this list age, name = [ "4", "Myname" ] age ---> "4" name ---> "Myname"
21st Jan 2021, 6:21 AM
noteve
noteve - avatar
+ 1
No , I meant when I want to write the codes, not inputs.
21st Jan 2021, 9:47 AM
Morteza
Morteza - avatar
0
age=input() ; name=input() ; if age<5:print(name+' is a child.') If i write like this an error happens. But age=input() name=input() if age<5:print(name + ' is a child.') Is correct.
20th Jan 2021, 8:14 PM
Morteza
Morteza - avatar
0
I don't know how to go next line and when i press enter the program will run.
20th Jan 2021, 8:16 PM
Morteza
Morteza - avatar
0
BTW , i'm using Python3
20th Jan 2021, 8:18 PM
Morteza
Morteza - avatar
0
Thank you but still if I write age=input() ; name=input() ; if int(age)<5:print(name+' is a child.') Still it doesn't work
20th Jan 2021, 9:18 PM
Morteza
Morteza - avatar
0
I don't know how to go next line and when i press enter the program will run.
20th Jan 2021, 9:19 PM
Morteza
Morteza - avatar
0
You are correct but I don't know how to go next line and when i press enter the program will run.
21st Jan 2021, 4:24 AM
Morteza
Morteza - avatar
0
How should i go to the next line?
21st Jan 2021, 4:24 AM
Morteza
Morteza - avatar
0
But thanks for the new tip
21st Jan 2021, 9:47 AM
Morteza
Morteza - avatar
0
You go to next line with '\n'
22nd Jan 2021, 7:53 AM
Aung Aung Soe
Aung Aung Soe - avatar