Isn't it funny that those businesses somehow stay in business? It's almost as if there's a demand for that kind of store... I'm sure they wouldn't pay people to work if there are no customers, so there must be enough customers to make it worthwhile. It could be people who work night shift who shop there or those who don't celebrate holidays.
If you don't like a store's open hours then you shouldn't shop there. If you don't like working at a store because of the schedule you should look for a different job. It's a contractual arrangement and it is voluntary.
It is on a volunteer basis, though, and it's not legal to “force” anyone to work on any day regardless of holiday. You can choose not to work for a business that doesn’t have your needs in mind and you can always negotiate a schedule.
Except if you don't do it, you likely lose your livelihood and potentially don't find another in time to avoid being homeless. That's not a choice, that's borderline extortion. People don't work those kinds of jobs because they want to, they do it because they don't have other options.
Data on time spent in retail overall is unreliable enough to not be worth talking about, but as of 2018 it was just over 2.5 years per retail position on average. That's to say nothing about why they left, or if they got fired, or anything of the sort.
If the days change, you would have to change that in both implementations.
But yes: In a real world app, you most likely would like to dynamically change the names of days (translation), when the week starts, which days are working days, the strings for "Working day"/"Holiday" and add additional holidays.
I propose introducing an AbstractDateGenerationStrategyFactory that can construct the concrete DateGenerationStrategy, which in turn generatres the days according to the stakeholders requirements using an Iterator pattern. To promote loose coupling we can then inject the concrete factory via our IoC container. That should really cover all use cases and the code will be reusable in other projects.
In can't even come up with a wacky idea of when this would be necessary. Like on a Mars rover? Why can't I still hard code it? Why does it need to know the days? Why is it running python???
import calendar
days = list(calendar.day_name)
for i, day in enumerate(days):
if i == 0:
print('Workingdays:')
if i == 5:
print("\nHolidays:")
print(day)
or
import calendar
days = list(calendar.day_name)
print("Workingdays:")
print("\n".join(days[:-2]))
print("\nHolidays:")
print("\n".join(days[-2:]))
Would be what I would go for that gets the same output as OP.
I suppose they were going for 'or' to catch the 'Sat' and 'Sun' case, but it's not necessary at all because the else clause is the only bit which is being run for every single day. Man, this is trash lol.
from itertools import count
days = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
for i, j in zip(count(), days):
if i == 0:
print('Workingdays:')
if i == 5:
print("\nHolidays:")
if i == 5 and i == 6:
print(j)
else:
print(j)
You're right, I was remembering wrong, it's actually the opposite. You can do line breaks with slashes, but only on new reddit, while the double space works in both old and new.
days = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"] # "Sun" can be moved to the start of the list for countries who consider Sunday the start of the week
for day in days:
if day in ("Sat", "Sun"):
print(f"{day}: Weekend")
else:
print(f"{day}: Working Day")
If you really wanted to use the List index to determine whether a day is a weekend or not, iterating over Python's built in enumerate method would probably be the best solution, e.g.:
for i, j in enumerate("Apple", "Banana", "Orange"):
print("{i}: {j}")
> 0: Apple
> 1: Banana
> 2: Orange
Surely it would be even easier to just keep two lists – one for weekdays and one for weekends. If you wanted to keep them both in the same place, you could make a dictionary:
That's all that matters if you're a corporate programmer, a bright future is ahead of this individual, especially if he applies this to being a game developer. More tricks like this, and he can target only those with high end gaming rigs, justify hardware upgrades, and milk them like the cash cows the wage slaves really are for the corporations.
I don’t there is an ideal for it without some kind of user input (correct me if im wrong). The program should first ask which is the starting of the week (locally for the user), and we take that as the beginning and then the first 5 (for i in days[0:5]) would be weekdays and the rest 2 are holidays.
Except for the unnecessary zip function, I would say it's just weird code, not bad code, it's readable, and not inefficient and seems like homework/practice problem anyways.
If you take that into account, we might consider that in the US, Canada and Australia, Sunday is the first day of the week and needs to be at Index 0 in that list.
To shift and unshift the items in the list you can use
days.insert(0,days.pop())# Shift right
days.append(days.pop(0))# Shift left
You can use this according the place, if the start if the week is sunday then we need to shift right else do nothing, or if it already shifted right then shift left if the start is Monday (if that makes any sense..).
At that point you'd surely not have a piece of code like this to write anyway... I was assuming the weekday list must be an input coming in from an outside source.
If it's static information, then this piece of code is garbage anyway and there's no saving it. You could reduce it to a single print() call:
Nope, we do not consider the last 2 days to be the weekend. The US and Australia and I'm sure more consider Sunday to be the first day of the week. So either way with this approach you're fucked in terms of localization.
426
u/an4s_911 Nov 27 '21
if i = 5 and i = 6 then clearly 5 = 6
299
u/xSilverMC Nov 27 '21
I'm either very unfamiliar with python or they forgot to reference a quantum mechanics library for i being 5 and 6 simultaneously
204
u/succjaw Nov 27 '21
Saturday and Sunday are holidays apparently
189
u/[deleted] Nov 27 '21
Just printing the string hardcoded, would have been shorter.
38
u/[deleted] Nov 27 '21
What about:
Or even better just a dictionary with hardcoded values?
34
u/sohang-3112 Nov 27 '21
what is this supposed to do:
if i == 5 and i == 6?? this will obviously never be True56
u/[deleted] Nov 27 '21
Image Transcription
How to print working days in Python?
Workingdays :
Mon
Tue
Wed
Thu
Fri
Holidays :
Sat
Sun
I'm a human volunteer content transcriber for Reddit and you could be too! If you'd like more information on what we do and why we do it, click here!
9
u/kristallnachte Nov 27 '21
Why would the weekend need its own
print(j)?6
u/CowboyBoats Nov 27 '21
Ah, now I know how to print workingdays in Python
8
u/vunop Nov 28 '21
uninvited overthinking alert²
¹ Conditions apply ² By reading it you consent to the terms of conditions ³ It may be that what i am describing is from germany⁴ ⁴ Recursion ³
17
u/TittySkittle Nov 27 '21 edited Nov 27 '21
IMO the cleanest way to do this is probably
If you really wanted to use the List index to determine whether a day is a weekend or not, iterating over Python's built in
enumeratemethod would probably be the best solution, e.g.:3
u/callmelucky Nov 28 '21
Worst thing about this code is using the name
jinstead ofday.Second worst is using
itertools.countinstead ofenumerate.2
u/PranshuKhandal Nov 28 '21
schrodinger's variables
2
u/Dellmar Nov 27 '21
Wait, in this case it won't print Mondays
1
u/wwelna Nov 27 '21
The one thing that everyone has forgotten...
It just works!
That's all that matters if you're a corporate programmer, a bright future is ahead of this individual, especially if he applies this to being a game developer. More tricks like this, and he can target only those with high end gaming rigs, justify hardware upgrades, and milk them like the cash cows the wage slaves really are for the corporations.
-2
u/an4s_911 Nov 27 '21 edited Nov 27 '21
I don’t there is an ideal for it without some kind of user input (correct me if im wrong). The program should first ask which is the starting of the week (locally for the user), and we take that as the beginning and then the first 5 (
for i in days[0:5]) would be weekdays and the rest 2 are holidays.-7
u/redddooot Nov 27 '21
Except for the unnecessary zip function, I would say it's just weird code, not bad code, it's readable, and not inefficient and seems like homework/practice problem anyways.
15
u/[deleted] Nov 27 '21
[removed] — view removed comment