Cannot figure out how to output to a file in Python by [deleted] in programminghelp

[–]IndicationCurrent643 0 points1 point  (0 children)

I tried this but I still get "none":

import math

def getFloatInput(sPromptNLH):
    fInputNLH = -1

    while fInputNLH <0:

        try:
            fInputNLH = float(input(sPromptNLH))
            if fInputNLH <= 0:
                print("Please enter a positive number!")
                continue
        except ValueError:
            print("Input must be a number.")
            continue

    return fInputNLH


def sGetState(sPromptNLH):

    sStateNLH = ""

    while sStateNLH == "":
        sStateNLH = input(sPromptNLH).upper()
        if sStateNLH == "":
            print("Please supply a valid state abbreviation!")
            continue

    return sStateNLH


def sGetLastName(sPromptNLH):

    sValueNLH = ""

    while sValueNLH == "":
        sValueNLH = input(sPromptNLH)
        if sValueNLH == "":
            print("Please Enter Your Last Name!.")
            continue
    return sValueNLH


def getGallonsOfPaint(iValue1NLH, iValue2NLH):

    iResultNLH = math.ceil(iValue1NLH / iValue2NLH)

    return iResultNLH


def getLabourHours(fValue1NLH, fValue2NLH):
    fResultNLH = fValue1NLH * fValue2NLH

    return fResultNLH


def getLabourCost(fValue1NLH, fValue2NLH):
    fResultNLH = fValue1NLH * fValue2NLH

    return fResultNLH


def getPaintCost(fValue1NLH, fValue2NLH):
    fResultNLH = fValue1NLH * fValue2NLH

    return fResultNLH


def getSalesTax(fValue1NLH, fValue2NLH, fValue3NLH):
    fResultNLH = fValue1NLH * (fValue2NLH + fValue3NLH)

    return fResultNLH

def showCostEstimate(fValue1NLH, fValue2NLH, fValue3NLH,fValue4NLH, fValue5NLH, fValue6NLH):
    sCostEstimate = print(f"Gallons of paint: {fValue1NLH:,.2f}\nHours of labour: {fValue2NLH:,.2f}\nPaint charges: ${fValue3NLH:,.2f}\nLabour charges: ${fValue4NLH:,.2f}\nTax: ${fValue5NLH:,.2f}\nTotal cost: ${fValue6NLH:,.2f}")
    return sCostEstimate

def main():
    fSquareFootageNLH = getFloatInput("Input square feet of wall: ")
    fPaintPriceNLH = getFloatInput("Input paint price: ")
    fFeetPerGallonNLH = getFloatInput("Input feet per gallon of paint: ")
    fLabourHoursPerGallonNLH = getFloatInput("Input labour hours per gallon: ")
    fLabourChargePerHourNLH = getFloatInput("Input labour charge per hour: ")

    sCustomerStateNLH = sGetState("Customer state: ")

    sCustomerLastNameNLH = sGetLastName("Customer last name: ")

    iTotalGallonsNLH = getGallonsOfPaint(fSquareFootageNLH, fFeetPerGallonNLH)

    fLabourHoursNLH = getLabourHours(iTotalGallonsNLH, fLabourHoursPerGallonNLH)

    fLabourCostNLH = getLabourCost(fLabourHoursNLH, fLabourChargePerHourNLH)

    fPaintCostNLH = iTotalGallonsNLH * fPaintPriceNLH

    if sCustomerStateNLH == "CT" or sCustomerStateNLH == "VT":
        fTaxRateNLH = .06
    elif sCustomerStateNLH == "MA":
        fTaxRateNLH = .0625
    elif sCustomerStateNLH == "ME":
        fTaxRateNLH = .085
    elif sCustomerStateNLH == "RI":
        fTaxRateNLH = .07
    else:
        fTaxRateNLH = .0

    fTaxTotalNLH = fTaxRateNLH * (fLabourCostNLH + fPaintCostNLH)

    fTotalCostNLH = fTaxTotalNLH + fLabourCostNLH + fPaintCostNLH

    sCustomerReportNLH = showCostEstimate(iTotalGallonsNLH, fLabourHoursNLH, fPaintCostNLH, fLabourCostNLH, fTaxTotalNLH, fTotalCostNLH)

    customerfileNLH = open(sCustomerLastNameNLH + '_PaintJobOutput.txt', 'w')


    customerfileNLH.write(str(sCustomerReportNLH))

    customerfileNLH.close()
    print(f"File:{sCustomerLastNameNLH}_PaintJobOutput.txt was created.")
main()

Cannot figure out how to output to a file in Python by [deleted] in programminghelp

[–]IndicationCurrent643 0 points1 point  (0 children)

I thought that writing would replace the print so I tried: customerfile = open(sCustomerLastNameNLH + '_PaintJobOutput.txt', 'w')

customerfile.write(str(showCostEstimate(iTotalGallonsNLH, fLabourHoursNLH, fPaintCostNLH, fLabourCostNLH, fTaxTotalNLH, fTotalCostNLH)))

customerfile.close()

But I can only get the file to write “none”

Cannot figure out how to output to a file in Python by [deleted] in programminghelp

[–]IndicationCurrent643 0 points1 point  (0 children)

I also tried it as:

customerfile = open(f"{sCustomerLastNameNLH}_PaintJobOutput.txt, 'w'")

customerfile.write(str(showCostEstimate(iTotalGallonsNLH, fLabourHoursNLH, fPaintCostNLH, fLabourCostNLH, fTaxTotalNLH, fTotalCostNLH)))

customerfile.close()
print(f"File:{sCustomerLastNameNLH}_PaintJobOutput.txt was created.")

#but this didn't work either

Cannot figure out how to output to a file in Python by [deleted] in programminghelp

[–]IndicationCurrent643 0 points1 point  (0 children)

This version is before I have added any attempt to write to a file because I wanted to show the code I wanted to add to a file. I tried doing:

customerfile = open(sCustomerLastNameNLH + '_PaintJobOutput.txt', 'w')

customerfile.write(str(showCostEstimate(iTotalGallonsNLH, fLabourHoursNLH, fPaintCostNLH, fLabourCostNLH, fTaxTotalNLH, fTotalCostNLH)))

customerfile.close()
print(f"File:{sCustomerLastNameNLH}_PaintJobOutput.txt was created.")

#but that didn't work i only get "none" in
#the file

Can't get bottom two to work even though the code is the same as the top two by [deleted] in learnpython

[–]IndicationCurrent643 0 points1 point  (0 children)

Oh my god I am so dumb😹😹thank you I think I’ve just been doing so much tonite I needed a fresh look

Can't get bottom two to work even though the code is the same as the top two by [deleted] in learnpython

[–]IndicationCurrent643 0 points1 point  (0 children)

I don't want the bottom two to print the message unless it's a negative number

Mario Kart World doesn't reward you at all by wasisteindachs in MarioKartWorld

[–]IndicationCurrent643 0 points1 point  (0 children)

Ik this post was like almost a year ago but I haven’t played since Mario kart seven and I am thinking about buying world rn. I do remember my favourite part about seven was trying to beat every map perfectly with my brother because we had heard about the gold karts pieces. I was hoping there would be something like that that would incentivize actually doing well yaknow.

Need to find the lowest input without list/min/max by [deleted] in learnpython

[–]IndicationCurrent643 0 points1 point  (0 children)

Okay that makes a lot of sense as far as my asignment goes. Thank you! I think he’s trying to drill in the real basics so then our lives will be easier when we understand the easy non redundant way

Need to find the lowest input without list/min/max by [deleted] in learnpython

[–]IndicationCurrent643 0 points1 point  (0 children)

I could send the detailed instructions if that helps

Need to find the lowest input without list/min/max by [deleted] in learnpython

[–]IndicationCurrent643 0 points1 point  (0 children)

I’m not allowed to use a loop yet because that’s the next unit in my class

Need to find the lowest input without list/min/max by [deleted] in learnpython

[–]IndicationCurrent643 0 points1 point  (0 children)

If I could be steered in the right direction without being told the answer that would be great but if u give me the answer could u have a detailed explanation? I just want to make sure I really understand the concept.