Excited - Check Simple Code - Anything Unnecessary?


#1

Hello all!

So I am newer to coding (only like 30% through the Python courses) and well just in doing it this is one of the first things I hit that I got really excited about. I took some notes from the first couple of lessons and I did my own thing just to play around… and well I wanted to show my girlfriend when I got home, but on some websites the code has a syntax error and on others it works fine. That brought me here. Is there a better way to type the code below? If so could you type it in a reply just so I can compare and contrast? I just want to do it the most efficient way and learn/know if I am doing an extra step I should not. Thanks all, I appreciate the help. :slight_smile:

compliment = (raw_input)

def compliment(x):
if x == “Nino” or x == “nino”:
return “You are beautiful”
elif x == “Chris” or x == “chris”:
return “You are creative”
elif x == “Mark” or x == “mark”:
return “You are very nice”
else:
return “I don’t know you.”

print compliment(raw_input("To whom am I speaking? "))

New note: So I think that the “compliment = (raw_input)” part is unnecessary (granted I am new at this).
Also wanted to add a clarifying statement. I am asking for an exemplar of this to compare/contrast with just for insight and curiosity. I am not asking for a curb for my enthusiasm or advice to ignore a question stuck in my mind.

P.S. Additional question… I tried typing my code with correct indentation in here but it did not show. I have seen some other posts where the indentation and colors show… how do I do that on the forums?
Thanks in advance. :smiley:


#2

At this stage, rather than experimenting, keep going on the track lessons and build up your knowledge. For us to pick away at your code above would be a waste of time, both yours and ours. Stick to the lesson plan and complete the track. Then go back and review every unit, redoing the exercises and at that time, experimenting and reading up on each concept so you learn the variations.


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.