Python - Indentation Error

Python - Indentation Error
0.0 0

#1

Hello all -

Long shot, but I am having a heck of a time figuring out what I am doing wrong here. Any help would be greatly appreciated.

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 :slight_smile:

For a person named Wally, respond by printing:

Hello Wally :slight_smile:

…etc.

In general, for a person named , respond by printing:

Hello

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 :slight_smile:

I like your shoes

For a person named Brandy, respond by saying:

Hello Brandy :slight_smile:

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?

Here is what I have so far, and I am getting an indentation error:

Put your Python code here:
name = input(“What is your name?”)
print(“Hello” ,name,":)")
for name in[“Brandy”]:
print(“you seem like a cool person”)
for name in[“Amar”]:
print(“I like your shoes”)

INSTRUCTIONS

For each number between 1 and 100…

If the number is odd, then simply print it out.

BUT if the number is even, then print the word “Steven” instead.

When I run your program, I should see the following output:

1

Steven

3

Steven

5

97

Steven

99

Steven

Note that you shold start at 1 (not 0), and that the 100 must be INCLUDED.

In other words, the last number should be 100, not 99.

--------------------------------------------------------------------

Thanks so much for your feedback!


#2

For the first one, the code should look something like this:

https://repl.it/HAq6/0


#3

Second one like this:

https://repl.it/HAqm/4


#4

The second one can be simplified as follows (Python3):

for count in range(1,101):
  print(count if count&1 else "Steven")

#5

That’s nice. I changed mine to reflect a more spelled out version of yours.


#6

Python is my favorite language outside of Ruby.


#7

Thanks for you help!
It didn’t quite work though. It is for Python 2.


#8

Which version of Python 2?


#9

It is for version 2.7


#10

Just remove the parenthesis on the print statements:

https://repl.it/HAsR/0


#11

When I run my solution on Python 2.7 it works for me. Can you post a screen shot of what you get on Python 2.7?


#12

For the first one you’ll have to have raw_input instead of input:

https://repl.it/HAsU/3


#13

It worked.
Thank you!!


#14

Oh the 1st one. I thought you meant the second one. If you want a more optimized version (specifically for Python 2.7) of the 2nd one that I wrote above then the following is more efficient:

for count in xrange(1,101):
  print count if count&1 else "Steven"

Note 1: You can actually use the parentheses or not for print in Python 2.7

Note 2: xrange is more efficient than range in Python 2.7. In Python 3, range is the equivalent of xrange of 2.7

There are several key differences between the two versions of Python which you need to be aware. A web search will yield these differences.