Program to write a simple product delivery code

It will ask like, "Do you want to buy a product y/n". If y then it will get your device date and delivered after 2 days. Means if run program on Tuesday, the output will be "Order will be delivered on Thursday". But there's a twist, this company doesn't deliver products on Sunday.

So if you are running the program on Friday, the output should come, "Order will be delivered on Monday".

import datetime

weekDays = (
    "Monday",
    "Tuesday",
    "Wednesday",
    "Thursday",
    "Friday",
    "Saturday",
    "Sunday"
)

todaydate = datetime.date.today() + datetime.timedelta(days=2)
getweek = todaydate.weekday()
w = weekDays[getweek]

print("Do you want to buy a product y/n")
s = input()

while (-1):
    if (s == 'y'):
        if (w == 'Sunday'):
            a = todaydate + datetime.timedelta(days=1)
            b = a.weekday()
            c = weekDays[b]
            print("Your order will be delivered on", c)
            break
    elif (s == 'y'):
        if (w != 'Sunday'):
            print("Your order will be delivered on", w)
    elif (s == 'n'):
        break
    else:
        print("Invalid input")
        break

I tried this code but it's not even running.


Solution 1:

You could use this;

if buying_day in ['Thursday', 'Friday']: 
    delivery_day = 'Monday'
else: 
    delivery_date = todaydate + datetime.timedelta(days=2)
    delivery_day = delivery_date.weekday()

print('Your item will be delivered on', delivery_day)

I couldn't resist correcting your code, sorry;

# nothing else than this;
while True:
    s = input("Do you want to buy a product y/n")

    if s == 'y':
        todaydate = datetime.date.today()
        today = todaydate.weekday()

        if today in ['Thursday', 'Friday']: 
            delivery_day = 'Monday'
        else: 
            delivery_date = todaydate + datetime.timedelta(days=2)
            delivery_day = delivery_date.weekday()

        print('Your item will be delivered on', delivery_day)
        
    elif s == 'n'):
        break
    else:
        print("Invalid input")
        break