Python Python Basics Types and Branching If, Else and Elif

error error errot

first_name = input("What is your first name? ") print("hello", first_name) if first_name == "craig": print(first_name, " is learning python") else first_name=="omair qasim": print(first_name, "Hey {} you are a great student".format(first_name)

3 Answers

Hi there Fahad,

You almost had it working! If you want for the program to include a specific exception aside from the one in your if statement you use elif. I also noticed that you forgot to close the print statement at the end of your code. Have a look at the example below; it should clear things up.

first_name = input("What is your first name? ") 
print("hello", first_name) 
if first_name == "craig": 
    print(first_name, " is learning python") 
elif first_name == "omair qasim": 
    print(first_name, "Hey {}, you are a great student".format(first_name))

Moderator Edit: Moved response from Comment section to Answers so it may be upvoted / mark as Best Answer

Tom Halff I am very thank full of you to solve my problem. You are a great person i am become your fan. Thanks, Thanks, Thanks.

Dylan Bailey
Dylan Bailey
574 Points

Hey there! Don't forget to check your parentheses when using methods; specifically the format() method.

print(first_name, "Hey {} you are a great student".format(first_name)

The above code is copied from your post. I had errors thrown at me, by forgetting that one parenthesis ?.

print(first_name, "Hey {} you are a great student".format(first_name))