From d65066053445a86632f2710b6422616311f6fa07 Mon Sep 17 00:00:00 2001 From: Jan Tuomi Date: Tue, 7 Aug 2018 19:08:19 +0300 Subject: Add openpyxl for loading and saving excel files --- pizza.py | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 50 insertions(+), 9 deletions(-) (limited to 'pizza.py') diff --git a/pizza.py b/pizza.py index 2b4b46d..7b2bc3c 100644 --- a/pizza.py +++ b/pizza.py @@ -1,14 +1,55 @@ -distance = float(input ("Give me your round trip distance in miles: ")) -wear = 0.1 -print(distance * wear) -print = float(input ("How much is the order: ")) -price = input -print = float(input ("Give me the total amount given to you: ")) -amount = input -print (amount - price) -print = ("After gas and wear-n-tear, your net tip is " + 2.6 / 30 * distance ) #price per gallon / mpg * distance +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +import datetime +import openpyxl +# Let's call the excel file "data.xlsx" +filename = 'data.xlsx' +try: + # Try opening the file + wb = openpyxl.load_workbook(filename) + # If it exists, get the active worksheet + sheet = wb.active +except FileNotFoundError: + # If the file didn't exist, create it + wb = openpyxl.Workbook() + sheet = wb.active + # Append some header data + sheet.append(['Timestamp', 'Total price', 'Amount given', 'Tip', 'Trip distance', 'Net tip']) +# Rename the sheet +sheet.title = 'Delivery tracker' + +# Save the file +wb.save(filename) + +gas_cost = 0.08 #how much it costs to drive 1 mile +wear_tear = 0.1 #estimated 10 cents per mile in tire and engine wear +mpg = 30 # my car gets 30 miles per gallon +delivery_charge = 1.25 # dominos pays the driver $1.25 each delivery + +while True: + now = datetime.datetime.now() + print("|||WELCOME TO TIP TRACKER. ALL OF THE DATA SHOWN IS BASED ON 30 MPG AT $2.60/GALLON AND 10ยข OF WEAR'N'TEAR EACH MILE|||") + total_price = float(input('Total Price: ')) #Total price of order + amt_given = float(input('Amount Given: ')) #Total amount of money received from customer + tip = amt_given - total_price #This is your total Gross Tip + print('Tip given = {}'.format(tip)) #This prints your tip and saves the tip as a variable ( I think..lol) + trip_distance = float(input('Miles: ')) # This is your round trip distance in miles + print ("Your net tip is...") + + net_tip = tip + delivery_charge -(gas_cost + wear_tear * trip_distance) #This prints your Net Tip after factoring in the delivery charge, gas, and wear n tear + print (net_tip) + + timestamp = now.strftime("%Y-%m-%d %H:%M:%S") + print ("Current date and time : ") + print (timestamp) + + # Store the data in a new row in the file + sheet.append([timestamp, total_price, amt_given, tip, trip_distance, net_tip]) + + # Save the document + wb.save(filename) -- cgit v1.3