I wrote my first Python code; example for newbie....
What are some creative small programs that you have coded using Python?
Python code examples?
Looking for some examples of "good" Python code to learn from?
Videos
So taking up suggestions from my "gibberish" post yesterday (thanks to all who replied, not sure why mods removed it), I decided to continue my days-old project of learning Python by actually sitting down to write my first code. Why not? Let's give it a try.
After learning about the # symbol and how it provides "commentary" for the lines of code, I decided to write down my proposed code within the # lines. I asked myself, what do I want the result to be? Here, I decided a friend says either they like my red shirt or doesn't say anything about the shirt if it is a color other than red. And then I asked myself, what are the steps to get there? Here, I said there has to be an action for what the friend will say (the print command determined by a "red or else" function) and also a variable that is fill-in-the-blank for either red or not red (the variable).
This took me several tries and I did encounter a few errors. These were syntax errors relating to the correct variable and function terminology. But otherwise about 10 minutes from beginning to successful end. I'm pretty proud of this. Hopefully this post helps another Python newbie out there.
# This code will have a friend say either one of two things in response to seeing me, depending upon the color of my shirt.
#
# If my shirt is red, my friend will say hello and say he likes my shirt.
#
# But if my shirt is not red, my friend will just say hello.
#
# My code needs these items: A fill-in-the-blank for the color of my shirt, red or otherwise.
# My code also needs some kind of function which determines what my friend will say depending upon the color of my shirt.
my_shirt_color_today = ["red"]
if my_shirt_color_today == ["red"]:
print("Hello friend, I like the color of your shirt! Red is my favorite")
else:
print("Hello friend! Why didn't you wear your red shirt today?")