+ 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.
15 ответов
+ 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?
+ 2
post your code so we can help please
+ 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')
+ 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.
+ 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"
+ 1
No , I meant when I want to write the codes, not inputs.
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.
0
I don't know how to go next line and when i press enter the program will run.
0
BTW , i'm using Python3
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
0
I don't know how to go next line and when i press enter the program will run.
0
You are correct but I don't know how to go next line and when i press enter the program will run.
0
How should i go to the next line?
0
But thanks for the new tip
0
You go to next line with '\n'