|
1 |
| -This problem was descrived by [] |
| 1 | +# ================= Problem Description ================= |
| 2 | +# This script calculates and displays the delivery time or date based on the order time. |
| 3 | +# The delivery time is determined as follows: |
| 4 | +# - If the order time is less than 6 hours, the delivery time is the current date. |
| 5 | +# - If the order time is 6 hours or more, the delivery date is the following day. |
| 6 | +# |
| 7 | +# 1. Prompts the user to input the order time in hours. |
| 8 | +# 2. Calculates the delivery time or date based on the order time. |
| 9 | +# 3. Displays the result. |
| 10 | +# 4. Asks the user if they want to retry or quit. |
| 11 | +# |
| 12 | +# The program continues to prompt for new order times until the user decides to quit or provides invalid input. |
| 13 | +# |
| 14 | +# ================= Input ================= |
| 15 | +# - Order time (integer value representing hours). |
| 16 | +# |
| 17 | +# ================= Output ================= |
| 18 | +# - Delivery time or date based on the order time. |
| 19 | +# - Option to retry or quit after each result. |
| 20 | +# |
| 21 | +# Example: |
| 22 | +# Input: |
| 23 | +# Enter order time: 3 |
| 24 | +# Output: |
| 25 | +# Delivery time is: 2024-09-16 |
| 26 | +# Do you want to retry? (y/q): n |
| 27 | +# ========================================================= |
2 | 28 |
|
3 | 29 | from datetime import datetime, timedelta
|
4 | 30 |
|
5 | 31 | # Get the current time without microseconds
|
6 | 32 | current_date = datetime.now().strftime('%Y-%m-%d')
|
7 | 33 | next_day_date = datetime.now().date() + timedelta(days=1)
|
8 | 34 |
|
9 |
| - |
10 |
| - |
11 |
| - |
12 |
| -def deliveryTimer (orderTime): |
13 |
| - if orderTime < 6 : |
14 |
| - print("Delivary time is : " + current_date) |
15 |
| - |
16 |
| - retry = input("Do you want to retry? (y/q): ").lower() |
17 |
| - if retry != "y": |
18 |
| - quit() |
| 35 | +def delivery_timer(order_time): |
| 36 | + if order_time < 6: |
| 37 | + print(f"Delivery time is: {current_date}") |
19 | 38 | else:
|
20 |
| - print("Delivary date is : " + str(next_day_date)) |
21 |
| - |
22 |
| - retry = input("Do you want to retry? (y/q): ").lower() |
23 |
| - if retry != "y": |
24 |
| - quit() |
25 |
| - |
26 |
| - |
| 39 | + print(f"Delivery date is: {next_day_date}") |
27 | 40 |
|
| 41 | + retry = input("Do you want to retry? (y/q): ").lower() |
| 42 | + if retry != "y": |
| 43 | + quit() |
28 | 44 |
|
29 | 45 | while True:
|
30 |
| - orderTime = input("Enter order time : ") |
31 |
| - if orderTime.isnumeric(): |
32 |
| - orderTime = int(orderTime) |
33 |
| - deliveryTimer(orderTime) |
| 46 | + order_time = input("Enter order time (in hours): ") |
| 47 | + if order_time.isnumeric(): |
| 48 | + order_time = int(order_time) |
| 49 | + delivery_timer(order_time) |
34 | 50 | else:
|
35 | 51 | print("Not a valid input")
|
36 | 52 | retry = input("Do you want to retry? (y/q): ").lower()
|
37 | 53 | if retry != "y":
|
38 | 54 | break
|
39 |
| - |
|
0 commit comments