Making a bus trip logger and I need help!!! | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Making a bus trip logger and I need help!!!

So basically I've written the basic part of my code that just asks the user for whether he wants to input 'new trip' or 'trip taken yesterday'. I have written the new trip block print ("this is the bus logger. this is to log down all the bus trips that i take, from location to location, and input money spent.\nplease input from location first, then location arrived, then money spent.") print ("please enter 'new trip' to input new trip\nplease enter 'trips taken yesterday' to see trips taken yesterday\n") user_input = input(':') if user_input == ("new trip"): location_from = input("location from:") location_to = input("location to:") cost = float(input("cost:")) tally = (location_from + ' to ' + location_to + ' total cost ' + '

#x27; + str(cost)) That's as far as my knowledge brings me as I am very new. I am lacking the 'trips taken yesterday' function as I have no idea how to do date and time. I want to maybe add tally into a list using append? Please give me tips on how to make my code more efficient/readable. I add string '
#x27; into tally before (cost) because i want the cost to show up with dollar sign instead of just numbers and if I type $1.20 or something into the input it cannot change it to a float because of the $ symbol. Is this ok? Thank you!

24th Dec 2018, 2:46 AM
Perryech Zx
Perryech Zx - avatar
2 Answers
+ 1
from datetime import datetime tally =[] while(int(input("If you want to continue, press 1 otherwise 0:"))): user_input = input("please enter 1 for New trip and 2 for trips taken yesterday:") if user_input == "1": travel_date = datetime.now().date() location_from = input("location from:") location_to =input("location to:") cost = input("cost:") tally.append("On {} {} to {} total cost is ${}".format(travel_date,location_from, location_to, cost)) else: enter_date = input("Enter date in YYYY-MM-DD format :").split("-") year, month, day = map(int, enter_date ) travel_date = datetime(year,month,day).date() location_from = input("location from:") location_to =input("location to:") cost = input("cost:") tally.append("On {} {} to {} total cost is ${}".format(travel_date,location_from, location_to, cost)) print("Trips taken:\n{}".format("\n".join(tally))) Tips: 1) Use triple quotes for longer strings. Then print them. 2) Save the tally in database or file. If you want to use it every day. Happy coding!!!
24th Dec 2018, 3:24 PM
KKendavar
KKendavar - avatar
+ 1
Ken Wow it seems like there are still quite a few functions I haven't learned yet, but I understand the general gist of your code and it is working great. Thank you Ken!!!
24th Dec 2018, 4:07 PM
Perryech Zx
Perryech Zx - avatar