0

what time of day is it ? [morning/afternoon/evening/night]

#example: a = day() print("The time is ") + a 

Should Output

 The time is Morning/evening/afternoon/night 

2 Answers 2

4

You can use the datetime module for that

from datetime import datetime def get_time_of_day(time): if time < 12: return "Morning" elif time < 16: return "Afternoon" elif time < 19: return "Evening" else: return "Night" now = datetime.now() print("It's currently:", get_time_of_day(now.hour)) 
Sign up to request clarification or add additional context in comments.

Comments

0

It's kinda easy!

Code:

import datetime as dt def day(han): #find what time of day is it? t = han.datetime.now() h = t.strftime("%H") h = int(h) if h < 12: return "morning" h = 0 t = 0 if h < 16: return "afternoon" h = 0 t = 0 if h < 19: return "evening" h = 0 t = 0 if h < 24: return "night" h = 0 t = 0 return "midnight" h = 0 t = 0 a = day(dt) print("The time is " + dt) 

1 Comment

Exactly what i wanted! thanx

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.