Aug-10-2020, 06:41 PM
Hi folks,
Sorry for reviving this post - it was very interesting to read the answers etc. but i am actually very keen to know what way of formatting the strings would you recommend to stick with?
I use f-strings (new to python & thanks to my book) but you in this thread actually use the below e.g:
Btw, the below is my code (no string capitalisation as i actually have had all days in lower case hence lower() in code.)
Sorry for reviving this post - it was very interesting to read the answers etc. but i am actually very keen to know what way of formatting the strings would you recommend to stick with?
I use f-strings (new to python & thanks to my book) but you in this thread actually use the below e.g:
TRAIN = 'Go train {}'in connection with
return TRAIN.format(x)Is it perfectly valid in python3 - i mean is it just something that dates back to python2 or it will be still around along the python3 therefore worth of picking it up as another way of formatting strings?
Btw, the below is my code (no string capitalisation as i actually have had all days in lower case hence lower() in code.)
def get_workout_motd(day): """Return a value for the given day or warning message.""" day = day.lower() week_schedule = {'monday': 'chest & biceps', 'tuesday': 'back & shoulders', 'wednesday': 'neck & thighs', 'thursday': 'legs', 'friday': 'belly', 'saturday': 'rest', 'sunday': 'rest'} if day in week_schedule: if week_schedule[day] == 'rest': return 'Chill out!' else: return f'The day is {day.title()}, go train {week_schedule[day]}.' else: return 'Not a valid day!' # run it :) day = input("What day is it?: ") print(get_workout_motd(day))The code obviously does not strictly adhere to the requirements it is just my take at solving it..