Click here to Skip to main content
15,891,837 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
# INSTRUCTIONS
#
# In this program, you must ask the user:
# "What is your name?"
#
# And then respond by printing out a personalized greeting.


# GENERAL RULE
#
# For a person named Maria, respond by printing:
# Hello Maria :)
#
# For a person named Wally, respond by printing:
# Hello Wally :)
#
# ...etc.
#
# In general, for a person named <name>, respond by printing:
# Hello <name>


# SPECIAL NAMES
#
# Two people are special: Amar and Brandy.
# A person named Amar or Brandy should receive an additional comment after you say hello
#
# For a person named Amar, respond by saying:
# Hello Amar :)
# I like your shoes
#
# For a person named Brandy, respond by saying:
# Hello Brandy :)
# You seem like a cool person


# Note that the robot grader will only mark your solution correct if your
# print statements match EXACTLY what was specified above.
#
# Spelling, spacing, punctuation... all that stuff matters.
#
# Your input statement also matters. You must say it exactly like this:
# What is your name?


# --------------------------------------------------------------------


# Put your Python code here:

What I have tried:

Python
name = input("What is your name? ")
print("Hello",name+" :)")

if name == 'Amar':
  print ("I like your shoes")
elif name == 'Brandy':
    print ("You seem like a cool person")
Posted
Updated 20-Jun-18 16:58pm
v2
Comments
Richard MacCutchan 20-Jun-18 12:21pm    
I have run your code and it does not show any errors. What error messages are you seeing?
CPallini 20-Jun-18 16:54pm    
"You seem like a cool person"
:-)
Richard MacCutchan 21-Jun-18 2:55am    
:)

1 solution

This is kind of interesting. When I tested your code in windows command prompt it failed with your script:
Python
name = input("What is your name? ")
print("Hello",name+" :)")
if name == 'Amar':
  print ("I like your shoes")
elif name == 'Brandy':
    print ("You seem like a cool person")


Command and Result:
# windows
> echo Brandy | python hello.py
What is your name? Hello Brandy  :)


But it successfully ran on linux:
$ echo Brandy | python3.6 hello.py
What is your name? Hello Brandy :)
You seem like a cool person


Reason is in windows name also contains new line; in linux it does not.

Solution:
Python
name = input("What is your name? ")
name = name.strip()
print("Hello",name+" :)")
if name == 'Amar':
  print ("I like your shoes")
elif name == 'Brandy':
    print ("You seem like a cool person")
 
Share this answer
 
Comments
Richard MacCutchan 21-Jun-18 2:56am    
Excellent analysis.
Mohibur Rashid 21-Jun-18 8:11am    
:) thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900