jeudi 10 décembre 2020

How do I recall an entire function when the user asks for it in Python?

I'm new to Python and I'm trying to figure out how to create and if loop to restart an entire function (in this case, the programOutput function) if the user enters "Y". Also if my use of Class and def are totally wrong then I am welcoming to help and constructive criticism. Thanks!

import math


class userEntry:
    userName = input("Enter Customer Name: ")
    userQuantityPurchased = int(input("Enter Quantity Purchased: "))
    userPrice = int(input("Enter Price per Unit: "))

class taxCalculator:
    stateTax = .09
    countyTax = .05
    discountRate = .1
    salesAmount = float(str(userEntry.userQuantityPurchased * userEntry.userPrice))
    stateCalculator = str(salesAmount * stateTax)
    countyCalculator = str(salesAmount * countyTax)
    totalTax = sum = float(stateCalculator) + float(countyCalculator)
    grossSales = sum = float(salesAmount) - float(totalTax)
    discount = sum = float(discountRate) * float(salesAmount)
    netSales = sum = float(grossSales) - float(discount)

    programOutput()
    

def programOutput():

    print("---------------------------------------")
    print("Here is your Net Sale!")
    print("---------------------------------------")
    print("Customer Name:  ", userEntry.userName)
    print("Sales Amount: ", "$", taxCalculator.salesAmount)
    print("Total Taxes: ", "$", taxCalculator.totalTax)
    print("---------------------------------------")
    print("\n")
    print("Gross Sales: ", "$", taxCalculator.grossSales)
    print("Discount: ", "$", taxCalculator.discount)
    print("\n")
    print("---------------------------------------")
    print("\n")
    print("Net Sales: ", "$", taxCalculator.netSales)
    print("---------------------------------------")
    print("---------------------------------------")
    print("\n")
    print("Thank you for your business!")
    print("\n")
    nextSale = input("Do you want to process another sale? (Y/N):   ")

    

    if nextSale == 'Y':
        programOutput()

Aucun commentaire:

Enregistrer un commentaire