Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Beginner Python help
#1
# 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:

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")



I keep getting error messages with the code I have in.... if someone could guide me to my mistake I would appreciate it. Thank you
Reply
#2
Could you (beside putting code in Python code tags) post full error traceback message in error tags?
Reply
#3
File "hello.py", line 57
print ("I like your shoes")
^
IndentationError: expected an indented block
File "hello.py", line 57
print ("I like your shoes")
^
IndentationError: expected an indented block
File "hello.py", line 57
print ("I like your shoes")
^
IndentationError: expected an indented block
File "hello.py", line 57
print ("I like your shoes")
^
IndentationError: expected an indented block
0 Your code failed the following tests:
---------------------------------------



FOR A PERSON NAMED 'Amar'
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

*** You should have printed this: ***

What is your name?
Hello Amar :)
I like your shoes


*** But you actually printed this: ***



==================================================


FOR A PERSON NAMED 'Brandy'
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

*** You should have printed this: ***

What is your name?
Hello Brandy :)
You seem like a cool person


*** But you actually printed this: ***



==================================================


FOR A PERSON NAMED 'Charlie'
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

*** You should have printed this: ***

What is your name?
Hello Charlie :)


*** But you actually printed this: ***



==================================================


FOR A PERSON NAMED 'Dianne'
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

*** You should have printed this: ***

What is your name?
Hello Dianne :)


*** But you actually printed this: ***



==================================================
Reply
#4
Your code is correct, but you forgot the indentation that's it. Wink

After an if, elif or else statement, you must indent whatever is to be executed in the case that the condition were true.

Here is how it should be:
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")
This would work. Indentations are important in python as they are interpreted by the compiler.
Reply
#5
0 Your code failed the following tests:
---------------------------------------



FOR A PERSON NAMED 'Amar'
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

*** You should have printed this: ***

What is your name?
Hello Amar :)
I like your shoes


*** But you actually printed this: ***

What is your name?
Hello Amar :)
I like your shoes


==================================================


FOR A PERSON NAMED 'Brandy'
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

*** You should have printed this: ***

What is your name?
Hello Brandy :)
You seem like a cool person


*** But you actually printed this: ***

What is your name?
Hello Brandy :)
You seem like a cool person


==================================================


FOR A PERSON NAMED 'Charlie'
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

*** You should have printed this: ***

What is your name?
Hello Charlie :)


*** But you actually printed this: ***

What is your name?
Hello Charlie :)


==================================================


FOR A PERSON NAMED 'Dianne'
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

*** You should have printed this: ***

What is your name?
Hello Dianne :)


*** But you actually printed this: ***

What is your name?
Hello Dianne :)


==================================================


it still is saying I am incorrect....
Reply
#6
(Jun-20-2018, 03:47 PM)wak_stephanie Wrote: 0 Your code failed the following tests: --------------------------------------- FOR A PERSON NAMED 'Amar' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *** You should have printed this: *** What is your name? Hello Amar :) I like your shoes *** But you actually printed this: *** What is your name? Hello Amar :) I like your shoes ================================================== FOR A PERSON NAMED 'Brandy' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *** You should have printed this: *** What is your name? Hello Brandy :) You seem like a cool person *** But you actually printed this: *** What is your name? Hello Brandy :) You seem like a cool person ================================================== FOR A PERSON NAMED 'Charlie' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *** You should have printed this: *** What is your name? Hello Charlie :) *** But you actually printed this: *** What is your name? Hello Charlie :) ================================================== FOR A PERSON NAMED 'Dianne' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *** You should have printed this: *** What is your name? Hello Dianne :) *** But you actually printed this: *** What is your name? Hello Dianne :) ================================================== it still is saying I am incorrect....

The bot is faulty.. notice that the "should have" and "actually" are basically the same haha. But as for the objective, you've done it correctly.
Reply
#7
(Jun-20-2018, 03:37 PM)Nwb Wrote:
name = input("What is your name? ")
It has to match exactly. You have a space after your question mark, which isn't part of the prompt.
Reply
#8
(Jun-20-2018, 04:18 PM)nilamo Wrote:
(Jun-20-2018, 03:37 PM)Nwb Wrote:
name = input("What is your name? ")
It has to match exactly. You have a space after your question mark, which isn't part of the prompt.

That's true but notice that the other conditions were also passed as wrong, why would that be?
Reply
#9
Because you had the extra space every time it ran?
Reply
#10
You're right. XD
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020