Exercise 2: Good Morning Sir | Python Tutorial – Day #15
![*](https://i0.wp.com/allprowebdesigns.com/wp-content/uploads/2024/05/1716784811_maxresdefault.jpg?resize=840%2C430&ssl=1)
Video Title: Exercise 2: Good Morning Sir | Python Tutorial – Day #15
We’re back for ‘Bend Over Backwards’ challenge Because is today’s video I’m gonna give you another exercise And in this exercise you’ve to use (if/else) statement You’ll know what is the exactly practical use of (if/else) statement We’ll use a ‘time’ module Let’s move to the computer screen. And let me quickly tell you about this exercise [ [S [ST [STA [STAR [START [STARTI [STARTIN [STARTING [STARTING [STARTING T [STARTING TH [STARTING THE [STARTING THEM [STARTING THEME [STARTING THEME] So as you can see I’ve now moved to my computer screen And this exercise’s name is "Good morning sir" Yes you heard that right We have to create a Python Program which will greet the user Good morning/afternoon/evening Depending upon the time And in this we’re going to use ‘time’ module I’ve given you a link and what you have to do is It’s quite simple…. And some of you might think it as cheating Because the thing I’m about to tell you is going to be a very big hint So I want you to solve this without this hint Look I’ve given a hint here, and I’d suggest you to not to look at this program Don’t look at this program & try to challenge yourself "I don’t have to look at this program" You don’t have to be in a hurry to solve this exercise first You should be proud of yourself too You should be proud of yourself for solving this exercise "and I’ve confidence" So you need that feeling, that’s why try to avoid this program The question is… You have to write a program to greet the user Good morning/afternoon/evening depending upon the time So give it a shot Pause this video here and write that program And watch this video after posting your Repl Now for the people who are a little bit confused and they don’t know enough about ‘modules’ or ‘pip’ So this is for the people who are getting trouble while solving this problem and they want hint So let me tell you… Try to run this sample program And ‘time’ module is a built-in module so we don’t need ‘pip’ Run this sample program…. OK! We have imported ‘time’ module And we have printed time in different manners ‘strftime’ is a function which provides minutes and hours And look, if you’re running this program in Replit, so you’ll be in USA time zone Because these Repls of yours are running in USA Remember this And if you’re running these on your local computer so it’ll function as per your local computer Whatever the time you’ll see or whatever the greeting you’ll see, will be based on your local time If you’re running these program on your local computer Now let me show you an example If I write "Python" here… Or… Sorry "Python3" because I’m using MacBook If I write "Python3" here and run this program Or if I open my VScode And by pressing ( Ctrl + N ) & ( Ctrl + s ) and then if I save it with name "main.py" And then if I copy this & paste it here So just simply pay attention I’m using ‘Code Runner’ extension And I have to fix it a little bit because it is saying "command not found: Python" So let me tell you the correct way to fix it Go to settings… And search for "code runner" And in "code runner" open "edit settings.json" So wherever the "python" is written I’ll change that with "Python3" So let me check "python -u" is written so I’ll change it with "python3 -u" And this should do the trick Now I’ll run it… so look here it is Now it is giving me the local time (11:34) So this is my local time Now what am I doing here is… I’m printing hours, minutes & seconds In this format that… Hours will be in place of (%H) minutes on (%M) and seconds on (%S) This will only give ‘Hours’ and this will only give me ‘Minutes’ And obviously I’m using ‘strftime’ module And this will give me seconds I hope you understood this How we can get minutes, hours & seconds And if you want to know more about this then do (Ctrl + click) on this link you’ll get brief info It’s quite simple & nothing like rocket science And now I’m about to give the biggest hint after this even a child can solve this Listen this only if you’re completely stuck on this Else just post your Repl first and then you can listen to this There’s no big issue And the biggest hint is…. I’m about to tell you "Use ‘Int’ function" Because this won’t be an ‘Integer’ if you’re trying to manage it with greater than or less than So you cannot manage greater than or less than with ‘String’ Few things will be problematic for you That’s why you have to convert this into ‘Integer’ and you can do it like this ‘int()’ This was quite a big hint because it was the catch for the whole question And look I’ve converted this into ‘int()’ So this is now displayed as an ‘Integer’ and I’ll press ( Ctrl + Z ) So that you won’t be disturbed And if you haven’t accessed the playlist yet so make sure to do it That’s it for this video guys Thank you so much guys for watching this video 🙂 And I’ll see you next time
-
Sale!
Wireless WIFI Repeater Extender Amplifier Booster 300Mbps
$29.99$14.99 Add to cartWireless WIFI Repeater Extender Amplifier Booster 300Mbps
Categories: Electronics, Wi-Fi Router, Wireless Wi-Fi Extender Tags: 300Mbps, 802.11N, Amplifier, Booster, Extender, mobile wi-fi booster, Remote, WIFI, Wireless, Wireless WIFI, Wireless WIFI Repeater, Wireless WIFI Repeater Extender, Wireless WIFI Repeater Extender Amplifier, Wireless WIFI Repeater Extender Amplifier Booster, Wireless WIFI Repeater Extender Amplifier Booster 300Mbps$29.99$14.99 -
Sale!
Full RGB Light Design Gaming Headset Headphones with Mic
$24.99$14.99 Add to cartFull RGB Light Design Gaming Headset Headphones with Mic
Categories: Electronics, Gaming, Gaming Headsets Tags: Design, Full, Full RGB Light Design Gaming Headset, Full RGB Light Design Gaming Headset Headphones, Full RGB Light Design Gaming Headset Headphones with Mic, Gamer, Gaming, Gaming Headset Headphones, gaming headset wireless, Headphone, Headphones, Headset, Light, Mic, Package, RGB$24.99$14.99 -
Sale!
Wireless BlueTooth Multi-Device Keyboard Mouse Combo
$39.99$19.99 Add to cartWireless BlueTooth Multi-Device Keyboard Mouse Combo
Categories: Electronics, Gaming, Gaming Keyboards, Keyboard Mouse Combos Tags: Combo, Keyboard, keyboard mouse combos, Mouse, MultiDevice, Set, WireKeyboard Mouse Combo, Wireless, Wireless BlueTooth Keyboard Mouse Combo, Wireless BlueTooth Keyboard Mouse Combos, Wireless BlueTooth Multi-Device Keyboard Mouse Combo, Wireless BlueTooth Multi-Device Keyboard Mouse Combos$39.99$19.99 -
Sale!
High Back Leather Executive Adjustable Swivel Gaming Chair with Headrest and Lumbar
$199.99$139.99 Add to cartHigh Back Leather Executive Adjustable Swivel Gaming Chair with Headrest and Lumbar
Categories: Gaming, Gaming Chairs Tags: Adjustable, Chair, computer chairs, Desk, Executive, Gaming, Girl, Headrest, High, High Back Leather Executive Adjustable Swivel Gaming Chair, High Back Leather Executive Adjustable Swivel Gaming Chair with Headrest, High Back Leather Executive Adjustable Swivel Gaming Chair with Headrest and Lumbar, High Back Leather Executive Adjustable Swivel Gaming Chairs, Leather, Lumbar, Office, Racing, Swivel$199.99$139.99 -
Sale!
Professional LED Light Wired Gaming Headphones with Noise Cancelling Microphone
$29.99$19.99 Select optionsProfessional LED Light Wired Gaming Headphones with Noise Cancelling Microphone
SKU: N/A Categories: Electronics, Gaming, Gaming Headsets Tags: Cancelling, Gaming, Gaming Headphones with Noise Cancelling Microphone, gaming headset, Headphones, Headset, LED, Light, Mic, Microphone, Noise, Professional, Professional LED Light Wired Gaming Headphones, Professional LED Light Wired Gaming Headphones with Noise Cancelling Microphone, Wired, Wired Gaming Headphones, Wired Gaming Headphones with Noise Cancelling Microphone$29.99$19.99 -
Sale!
Gaming Desk with LED Lights USB Power Outlets and Charging Ports
$349.99$249.99 Select optionsGaming Desk with LED Lights USB Power Outlets and Charging Ports
SKU: N/A Categories: Computer Desk, Gaming, Gaming Desk Tags: and Charging Ports, Charging, Desk, Desks, Gaming, gaming desk with led lights, Gaming Desks with LED Lights, Home, LED, Lights, Monitor, Office, Outlets, Port, Power, Room, Stand, USB, USB Power Outlets, White, Workstation$349.99$249.99 -
Sale!
Wired Mixed Backlit Anti-Ghosting Gaming Keyboard
$99.99$79.99 Add to cartWired Mixed Backlit Anti-Ghosting Gaming Keyboard
Categories: Electronics, Gaming, Gaming Keyboards Tags: Antighosting, Backlit, Blue, brown, Gaming, Gaming Keyboard, gaming keyboards, gaming keyboards and mouse, Keyboard, Laptop, Switch, Wired, Wired Mixed Backlit Anti-Ghosting Gaming Keyboard, Wired Mixed Backlit Anti-Ghosting Gaming Keyboards, Wired Mixed Backlit Gaming Keyboard$99.99$79.99 -
Sale!
Wireless Bluetooth 5.3 ANC Noise Cancellation Hi-Res Over the Ear Headphones Headset
$119.99$59.99 Add to cartWireless Bluetooth 5.3 ANC Noise Cancellation Hi-Res Over the Ear Headphones Headset
Categories: Electronics, Gaming, Gaming Headsets Tags: 5.3 ANC Noise Cancellation Hi-Res Over the Ear Headphones Headset, ANC, Audio, Bluetooth, Cancellation, Ear, Earphone, gaming headset, Headphones, Headset, Hi-Res Over the Ear Headphones Headset, HiRes, Noise, Wireless, Wireless Bluetooth 5.3 ANC Noise Cancellation Hi-Res Headphones, Wireless Bluetooth 5.3 ANC Noise Cancellation Hi-Res Over the Ear Headphones Headset, Wireless Bluetooth 5.3 ANC Noise Cancellation Hi-Res Over the Ear Headphones Headsets$119.99$59.99 -
Sale!
Wired Sports Gaming Headset Earbuds with Microphone
$19.99$9.99 Select optionsWired Sports Gaming Headset Earbuds with Microphone
SKU: N/A Categories: Gaming, Gaming Headsets Tags: Accessories, Earbud, Earphone, Earphones, Gaming, gaming headset with microphone, Headphones, Headset, IOS, Microphone, Sports, Wired, Wired Sports Gaming Headset Earbuds, Wired Sports Gaming Headset Earbuds with Microphone, Wired Sports Headset Earbuds$19.99$9.99 -
Sale!
150W Universal Multi USB Fast Charger 16 Port MAX Charging Station
$49.99$29.99 Add to cart150W Universal Multi USB Fast Charger 16 Port MAX Charging Station
Categories: Charging Stations, Electronics Tags: 150W, 150W Charging Station, 150W Universal Multi USB Charging Station, 150W Universal Multi USB Fast Charger 16 Port MAX Charging Station, 150W Universal Multi USB Fast Charger 16 Port MAX Charging Stations, 150W Universal Multi USB MAX Charging Station, 16 Port MAX Charging Station, 3.5A, Charger, Charging, Fast, laptop charging stations, Max, Multi, Port, Stand, Station, Universal, USB$49.99$29.99
Attendance please! 😀
import time
Times = time.strftime('%H:%M:%S')
t = int(time.strftime('%H'))
if 3 <= t < 12:
print('Good Morning, Piyush sir')
elif 12 <= t < 15:
print('Good Afternoon, Piyush sir')
elif 15 <= t < 20:
print('Good Evening, Piyush sir')
else:
print('Good Night, Piyush sir')
print('The time is',Times)
5/25
done and tq for hint sir
import time
time1 = time.strftime('%H:%M:%S')
print(time1)
time1 = float(input("Enter the time:"))
if (time1 > 0.00 and time1< 11.59):
print("Good Morning")
elif(time1 >= 12 and time1 < 16):
print("Good afternoon")
elif(time1 >= 16 and time1 < 20):
print("Good evening")
else:
print("Good Night")
Hi @CodeWithHarry if it seems gud or ok pls revert
exercise completed!!!!!!
Thank you Harry bhaiya…
#HarryBhai
# Exercise 2: Good Morning Sir
'''create a python program capable of greeting you with Good Morning, Good Afternoon and
Good Evening. Your program should use time module to get the current hour.'''
# Solution:
import time
Hour = int(time.strftime(" %H"))
print(Hour)
if(Hour >= 3 and Hour < 5):
print("brahma muhurta")
elif(Hour >= 5 and Hour < 12):
print("Namskaram ,Good Morning ")
elif(Hour >= 12 and Hour < 16):
print("Namskaram ,Good Afternoon")
elif(Hour >= 16 and Hour < 19):
print("Namskaram ,Good Evening")
elif(Hour >= 19 and Hour < 22):
print("Namskaram ,Good Night")
else:
print("Mid Night")
a = int(input("enter recent time"))
print("recent time is",a)
if(a<12):
print("good morring")
else:
print("after noon")
easy and simple 😇😇
👍🏻👍🏻
Day 15 done ✅
Bhai Boldete yay ime.strftime('%H:%M:%S') "STR" return korta hai 🙂
import time
Time = time.strftime('%H:%M:%S')
print(Time)
Hour = int(time.strftime('%H'))
print(Hour)
Minutes= int(time.strftime('%M'))
print(Minutes)
seconds= int(time.strftime('%S'))
print(seconds)
if Hour <= 12:
print("Good Morning")
elif Hour <= 17:
print("Good Afternoon")
elif Hour <= 24:
print("Good Evening")
a=float(input("Enter your time please: "))
if(a>=12):
if(18>a>=12):
print("Good afternoon Sir")
elif(24>a>=18):
print('Good evening sir')
else:
print('Good morning sir')
Sr error a rha h. In vs code
Sir visual studio code ME time module is not accessed error aa raha hai to how to solve this error please tell me
time=int(input("Enter The Time In Hour: "))
if (time>=5 and time<=12):
print("Good Morning Sir")
elif (time>=12 and time<=17):
print("Good Afternoon Sir")
elif (time>=17 and time<=21):
print("Good Evening Sir")
else:
print("Good Night Sir")
Thanks bhaiya
time = int(input("Enter the time: "))
if time >=6 and time < 12:
print("GOOD MORNING")
elif time >= 12 and time < 16:
print("GOOD AFTERNOON")
if time >= 16 and time < 20:
print("GOOD EVENING")
elif time >=20 and time < 24:
print("GOOD NIGHT")
else:
print("GO TO SLEEP")
i'll try to make out with this problem according to the video but for now this is what it is !
import time
# Get the current hour
current_hour = time.localtime().tm_hour
# Greet based on the current hour
if 5 <= current_hour < 12:
print("Good Morning!")
elif 12 <= current_hour < 18:
print("Good Afternoon!")
else:
print("Good Evening!")
100 VIDEOS IN A SINGLE DAY BUT ON 9TH DAY PRESENT SIR FROM PAKISTAN
My Solution to Exercise 2
#Solution
import time
timestamp = time.strftime("%H:%M:%S")
print(timestamp)
timestamph = int(time.strftime("%H"))
print(timestamph)
timestampm = int(time.strftime("%M"))
print(timestampm)
timestamps = int(time.strftime("%S"))
print(timestamps)
if timestamph <= 10 :
print("Good Morning")
elif timestamph <= 16 :
print("Good Afternoon")
elif timestamph < 20 :
print("Good Evening")
else :
print("Good Night")
Per bhai hum tho abhi beginners ha apne nah yeh kabhi padhya hamko humko kese pata lagega ki time.strftime module lagega seriously bhai ,simple bolke bhot alag exercise dedete ho
sir pls hlp ye jo time.strrft command he ye pta kese lge ga ke ye use krni pls detail vid on moduls pip
import time
name=input("PLEASE ENTER YOUR NAME:")
recent= time.strftime("%H:%M:%S")
Recent= int(time.strftime("%H"))
if(Recent>=5 and Recent<=11):
print("Good Morning",name.capitalize(),"the time is",recent)
elif(Recent>=12 and Recent<16):
print("Good Morning",name.capitalize(),"the time is",recent)
elif(Recent>=16 and Recent<19):
print("Good evening",name.capitalize(),"the time is",recent)
elif(Recent>=19 and Recent<=4):
print("Good Night",name.capitalize(),"the time is",recent)
print("HELLO ",name,"this is a simple calculator")
x=input("ENTER THE FIRST NUMBER:")
y=input("ENTER THE SECOND NUMBER:")
print("addition of a+b is =",int(x)+int(y))
print("subtraction of a-b is =",int(x)-int(y))
print("multipicaton of a*b is =",int(x)*int(y))
print("division of a/b is =",int(x)/int(y))
#By this u can run caluculator + your greetings ex.1 and ex.2 both in single one
import time
gettime = time.strftime('%I:%M:%S:%p')
print(gettime)
gettime = time.strftime('%I')
print(gettime)
gettime = time.strftime('%M')
print(gettime)
gettime = time.strftime('%S')
print(gettime)
if gettime >= "4:00:00" and gettime <= "11:00:00":
print("Good Morning Sir")
elif gettime >= "12:00:00" and gettime <= "17:00:00":
print("Good After Noon Sir")
else:
print("Good Evening Sir")
import time
Name= input("Enter your name")
Complete_Time= time.strftime("%H: %M: %S")
Time= int(time.strftime("%H"))
print("The Time is:")
print("Running Hour:",time.strftime("%H"))
Hour= Time
print("Running Minute:",time.strftime("%M"))
print("Running Second:",time.strftime("%S"))
if( 5 <= Hour <= 12):
print("Good Morning", Name)
elif( 12 <= Hour <= 17 ):
print("Good Afternoon")
elif( 17 <= Hour <= 21):
print("Good Evening")
elif(21 <= Hour <= 5):
print("Good Night")
import time
ts = time.strftime('%H:%M:%S')
print(ts)
ts = int(time.strftime('%H'))
if ts>0.00 and ts<5.00:
print("very early moring")
elif ts>5.00 and ts<9.00:
print("Good morning")
elif ts>9.00 and ts<12.00:
print("Good after morning")
elif ts>12.00 and ts<17.00:
print("good after noon")
elif ts>17.00 and ts<20.00:
print("good evening")
elif ts>20.00 and ts<24.00:
print("good night")
else:
print("Something is going to be wrong")
import time
print("This is Time function check your time")
timefirst = time.strftime("%H : %M : %S")
print(timefirst)
hourse = int(time.strftime("%H"))
if(hourse >= 1 and hourse <= 12):
print("Alexa, GOOD MORNING! Bro")
elif(hourse > 12 and hourse <= 17):
print("Alexa, GOOD AFTRNOON! Bro")
elif(hourse > 17 and hourse <= 21):
print("Alexa, GOOD EVENING! Bro")
else:
print("Alexa, GOOD NIGHT! Bro")
Here's the code without changing the time into integers. I had used nested if-else condition just to make it more challenging, you guys can skip that part if you want to. Hope it will help you guys. Cheers
import time
time= time.strftime('%H:%M:%S')
print(time)
if (time>='06:00:00' and time<='11:59:59'):
print('Good Morning')
if time<='07:00:00':
print("You are up early, break-fast will be ready soon")
elif time>='07:00:01' and time<'09:00:00':
print('Do you want to have break-fast?')
elif time<='09:30:00':
print('You barely made for break-fast')
else:
print('You are late! Break-fast time is over')
elif time >= '12:00:00' and time<='15:59:59':
print('Good Afternoon')
if time<='02:00:00':
print('Do you want to have some tea/coffee?')
else:
print('It is lunch-time, can I serve you lunch?')
elif time >='16:00:00' and time<='19:29:59':
print('Good Evening')
if time<'17:00:00':
print('Do you want tea?')
elif time>'17:00:00' and time<'19:00:00':
print("Let's go to the gym")
else:
print("Let's have some fun")
elif time >='19:30:00' and time<='22:00:00':
print('Good Night')
if time<'20:29:59':
print("It's fun time")
else:
print("It's Dinner time, let's eat!")
else:
print('''Good Night!
Sleep Time,
Go to bed''')
import time
# Get current time
timestamp = time.strftime('%H:%M:%S')
print(timestamp)
# Get individual components of the time
hour = int(time.strftime('%H'))
minute = int(time.strftime('%M'))
second = int(time.strftime('%S'))
print(hour)
print(minute)
print(second)
# Determine the greeting based on the hour
if hour < 12:
print("Good Morning")
elif hour < 15:
print("Good Afternoon")
elif hour < 18:
print("Good Evening")
else:
print("Good Night")
The perfect solution for the perfect question!
import time
# Get the current time formatted as 'HH:MM:SS TimezoneName UTCOffset'
realtime = time.strftime('%H:%M:%S %Z%z')
# print(realtime)
# Extract and convert the hour part of the current time to an integer
timeHour = int(time.strftime('%H'))
# print(timeHour)
# Extract and convert the minute part of the current time to an integer
timeMinute = int(time.strftime('%M'))
# print(timeMonth)
# Extract and convert the second part of the current time to an integer
timeSecond = int(time.strftime('%S'))
# print(timeSecond)
# Conditionals to print greetings based on the current hour
if(timeHour >= 4 and timeHour < 12):
print("Good Morning Buddy") # Print greeting for morning
elif(timeHour >= 12 and timeHour < 17):
print("Good Afternoon Buddy") # Print greeting for afternoon
elif(timeHour >= 17 and timeHour < 20):
print("Good Evening Buddy") # Print greeting for evening
elif(timeHour >= 20 or timeHour < 0): # Updated condition for time range between 20 and 24
print("Good Night Buddy") # Print greeting for late night
elif(timeHour >= 0 and timeHour < 4):
print("Its Midnight, Good Night Buddy") # Print greeting for midnight to early morning
else:
print("Invalid Time") # Handle any unexpected hour values
Hope You like that approach, give a thumbsup to encourage me!!
for changing the timezone just import ptzy module…….