+ 2

Can anyone help me with if statement?

Name= input () If Name : Solly print ( Name) I tried this šŸ‘† and gave input as Solly but it is giving me an error . Can anybody explain me what is the mistake done by me . I will be thankful for the explanation šŸ™

26th Aug 2022, 1:59 PM
Solly
Solly - avatar
4 Answers
+ 3
Name : Solly => Solly is not declared variable still so error unknown Solly. What are you trying by this statement? invalid it is. Do you checking input is "Solly" ? Then do like if Name == "Solly" : #comparing print( Name ) Add else part to other case like else : print ( "Input is : " Name)
26th Aug 2022, 2:05 PM
Jayakrishna šŸ‡®šŸ‡³
+ 2
Solly That is not a write syntax. Learn about syntaxes first.
26th Aug 2022, 2:08 PM
AĶ¢J
AĶ¢J - avatar
+ 2
In this case Solly is a string. Use " " for it. And ":" is not true. When you want to say "if something is equal to something else" you should use "==" It means your code should be like: Name = input() If Name == "solly" : Print("your name is solly) else: Print("your name is not solly") #for example
28th Aug 2022, 8:23 AM
The Strange One
The Strange One - avatar
+ 1
Hey Solly, I just checked your script. May be this one is which fix your problem? Name = input () if Name == "Solly": print ("Your name is: "+Name) else: print("Another Name") It works for me. Prints "Your name is: Solly" or "Another Name" if you give different input than Solly
27th Aug 2022, 1:15 AM
Nazareno Mancinelli
Nazareno Mancinelli - avatar