lundi 10 octobre 2016

Python Program that Prints Greeting + Entered Name, Special Cases

In this program, I 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 RULE

Two people are special: Amar and Brandy.

These two names should receive unique greetings (and smiley faces)

For a person named Amar, respond by saying:

Hi Amar :)

For a person named Brandy, respond by saying:

Ahoy Brandy :D

The robot grader will only mark my solution correct if my print statements match EXACTLY what was specified above.

Spelling, spacing, punctuation... all that stuff matters.

My input statement also matters. I must say it exactly like this:

"What is your name?"

Here is what I tried in a Live Python Editor

Name = ""
# Prompt user for user-defined information
Name = raw_input('What is your Name? ')
if "" = Amar:
    print ("Hi Amar :)")
if "" = Brandy:
    print ("Ahoy Brandy :D")
else: 
    print ("Hello + """) 

This code returned an error message on line four:

SyntaxError: invalid syntax (<string>, line 4)

How can I improve this code so that the error message goes away and the program runs as it's expected?

Thanks!

Aucun commentaire:

Enregistrer un commentaire