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 Answers
New Answer1/20/2021 6:38:52 PM
Morteza15 Answers
New Answerthats 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?
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')
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.
( 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"
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.
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
You are correct but I don't know how to go next line and when i press enter the program will run.
SoloLearn Inc.
4 Embarcadero Center, Suite 1455Send us a message