#๐Ÿ”’ help for an assignment

42 messages ยท Page 1 of 1 (latest)

echo sinew
#

thats the question i have an issue with : Write a program that reads the departure time (hours and minutes) of a train and the
arrival time (hours and minutes) and computes and displays the trip time.
(Example: for Departure time 10:50 and Arrival time 12:10 the trip time will be
1 hr and 20 min)

tired surgeBOT
#

@echo sinew

Python help channel opened

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.

hollow estuary
#

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

echo sinew
#

yeah one min

echo sinew
# hollow estuary So, have you made any kind of start? And code? Or a bullet list of the steps tha...
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)```
hollow estuary
#

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

next solstice
#

This sounds fun why you wrecking the fun

hollow estuary
hollow estuary
next solstice
#

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

next solstice
#

Right but it doesn't ask for it. You do you. This seems fun. Whats the error

hollow estuary
next solstice
#

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?

echo sinew
#

the problem i have is with converting the mintues to hours again. and the trip time

#

kinda stuck

next solstice
#

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?

next solstice
#

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

echo sinew
#

so taking an input as an integer will be more complicated?

next solstice
#

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()
echo sinew
next solstice
#

That isn't all of it but it's a start.

echo sinew
#

yeah

next solstice
#

I'm not trying to be mean.

echo sinew
#

and it seams easier

next solstice
#

Im really not

#

Just want to get you thinking

echo sinew
#

its ok u r not being mean

echo sinew
next solstice
#

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.

tired surgeBOT
#
Python help channel closed for inactivity

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.