#๐ help for an assignment
42 messages ยท Page 1 of 1 (latest)
@echo sinew
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
So, have you made any kind of start? And code? Or a bullet list of the steps that would need to be done by the code? @echo sinew
yeah one min
deptmin= int(input('Enter departure time [in minutes]: '))
arrtime=int(input('Enter arrival time [in hours]: '))
arrmin=int(input('Enter arrival time [in minutes]: '))
deptmin=(depttime*60)+deptmin
arrmin=(arrtime*60)+arrmin
triptime= arrtime-depttime
depttime=deptmin/60
arrtime=arrmin/60
print('Departure time :', depttime,':',deptmin, 'Arrival time :', arrtime,':',arrmin, 'The trip duration :', triptime)```
Please edit that message to put a ```py line above the code and a ``` line below
``` (backticks) not ''' (apostrophes)
... on a line on its own
This sounds fun why you wrecking the fun
This code looks kind of ok. Got a specific question?
Nicer. But the ```py should be "one word", on a line of its own. Better syntax highlighting.
I don't think you have to make the departure time and arrival vlaues you can enter do you?
Like use a list or dict.
or variables
the user inputs them
Right but it doesn't ask for it. You do you. This seems fun. Whats the error
Well the questions says reads. Personally I'd take that to mean input(). But from the question I'd expect to read a time like "10:25" rather than the 10 and 25 separately.
You can read from lists, dicts, dataclasses, variables, etc. But input works. When I think train schedules. I think multiple trains. But I'm veering us off course. What's the error?
the problem i have is with converting the mintues to hours again. and the trip time
kinda stuck
So I would change how you're doing time. make it one thing like cameron said. Then do the math. Also, are departure and arrival same timezone?
yes same timezone
I would take it as a string and prompt the format to be like 10:25. This is kind of wh y isaid I'd steer away from inputs but inputs are fine
take it as a string and transform it then math it out
I don't want to take away hhe fun. If you figure it out it'l make way more sense
so taking an input as an integer will be more complicated?
I look at it like - the person entering is gonna be dumb
Like
from datetime import datetime
# Get input as strings
departure_str = input("Enter departure time (HH:MM): ")
arrival_str = input("Enter arrival time (HH:MM): ")
# Convert to time objects
departure_time = datetime.strptime(departure_str, "%H:%M").time()
arrival_time = datetime.strptime(arrival_str, "%H:%M").time()
i'd try this way if i had more time tbh ๐ญ i have to turn it in in like 10 mins
thanks alott
That isn't all of it but it's a start.
yeah
I'm not trying to be mean.
and it seams easier
its ok u r not being mean
that is what i really need actually
shhh
from datetime import datetime, timedelta
# Get input as strings
departure_str = input("Enter departure time (HH:MM): ")
arrival_str = input("Enter arrival time (HH:MM): ")
# Convert to datetime objects (using a dummy date)
fmt = "%H:%M"
departure_dt = datetime.strptime(departure_str, fmt)
arrival_dt = datetime.strptime(arrival_str, fmt)
# Handle if trip crosses midnight
if arrival_dt < departure_dt:
arrival_dt += timedelta(days=1)
# Compute duration
trip_duration = arrival_dt - departure_dt
# Output
print(f"Trip time: {trip_duration}")
!close and read through that. Good luck.
This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.