Weekend Project - Weekend Emotion
Welcome to another awesome weekend and starting today every weekend we are going to do some fun projects and today we are going to do something related to weekend. First of all create an empty python file with the name weekend_emotons.py , it is very important to keep the extension of the file as py which will tell the interpreter that this is a python scrpt file. Save the file in the path of you choice (for my machine the path is ~/PycharmProjects/untitled). Paste/type the following code into this file -
def weekn(day):
say_like = ""
if day == "Saturday":
say_like = "HURRAY it's weeknd :D:D"
print(say_like)
elif day == "Weekday":
say_like = ":( :("
print(say_like)
elif day == "Friday":
say_like = "Yeeeee :D :D"
print(say_like)
today = "Saturday"
weekn(today)
Save the file and then open the command prompt and type python3 weekend_emotons.py and if you are in linux or weekend_emotons.py if you are in windows and voila you will get the desired message depending on the day you have passed in the variable today.
What the code does?
We created a function weekn which takes in a parameter day. The code checks what day it is, if it’s saturday then it prints the appropriate message and if it’s some other day then it prints the required message. In the variable today we pass the day we want and the function returns the required message to us.
What else now?
Now that you have run the above code and successfully generated the message why not make the code more dynamic? Why not improve it to make it more shorter? So go ahead play around the code an you can post your version in the comment section below.
Subscribe to my youtube channel to watch new python programming tips and tutorials ..
If you wanna get started in learning Python then why not get started with the python basics chapter. Check out this link to access the Python Basic Chapter for free.
If you want to download a copy of the chapter then purchase the chapter by clicking on the following link.
def weekn(day):
say_like = ""
if day == "Saturday":
say_like = "HURRAY it's weeknd :D:D"
print(say_like)
elif day == "Weekday":
say_like = ":( :("
print(say_like)
elif day == "Friday":
say_like = "Yeeeee :D :D"
print(say_like)
today = "Saturday"
weekn(today)
|
If you wanna get started in learning Python then why not get started with the python basics chapter. Check out this link to access the Python Basic Chapter for free.
If you want to download a copy of the chapter then purchase the chapter by clicking on the following link.
Comments
Post a Comment