我的python程序有一些问题

我的python程序有一些问题,python,Python,下面是我的账单脚本,当我运行它时,我得到一个TypeError # the main function def main(): endProgram = 'no' endProgram = raw_input('Do you want to end program? (Enter no or yes): ') #declare Variables priceOfParts = 0 hours = 0 shopRate = 0 #Func

下面是我的账单脚本,当我运行它时,我得到一个
TypeError

# the main function
def main():
    endProgram = 'no'
    endProgram = raw_input('Do you want to end program? (Enter no or yes): ')

    #declare Variables
    priceOfParts = 0
    hours = 0
    shopRate = 0

    #Function calls
    tax=(taxes)
    taxableTotal(priceOfParts, hours, shopRate)
    totalBill(taxableTotal, taxes)
    outputTotalBill(totalBill)

#Password Function
count = 0
while count < 3:
    password = raw_input('Please enter a password: ')
    if password != 'spyderPC':
        count = count + 1;
    print 'You have entered invalid password %i times.' % (count)
    if count == 3:
        print 'Access Denied'
        break
    else:
        print 'Access Granted'
        break

# hours function
def hours(hours):
    hours = input("hours worked")
    while hours <0 or hours >80:
        print 'Hours cannot be a negative or over 80 per job'
    return hours

# shop Rate function
def shopRate(shopRate):
    shopRate = input("Shop rate")
    while shopRate<0:
        print 'Shop rate cannot be a negative'
    return shopRate

#Price of parts function
def priceOfParts(priceOfParts):
    priceOfParts = input("total Price of Parts")
    return priceOfParts

#taxable total Function
def taxableTotal(hours, shopRate, priceOfParts):
    taxableTotal = float (hours) * shopRate + priceOfParts
    return taxableTotal

# Calculate Taxes function
def taxes(taxableTotal ):
    taxes= float(taxeableTotal)*.08
    return taxes

# calculate total bill
def totalBill(taxableTotal, tax):
    totalBill = taxableTotal + taxes
    return totalBill

#out put bill to file
def outPut_totalBill(hours, shopRate, priceOfParts , taxableTotal, taxes, totalBill):
    outFile = open('Bill.txt', 'a')
    print >> outFile, 'The bill for services is $'
    outFile.write('hours' + '\n')
    outFile.write('shopRate'+ '\n')
    outFile.write('priceOfParts' + '\n')
    outFile.write('taxableTotal' + '\n')
    outFile.write('taxes' + '\n')
    outFile.write('totalBill' + '\n')
    outfile.close

main()
但是,我得到了这些错误:

Traceback (most recent call last):
  File "C:\Users\school pc\Desktop\myProgram.py", line 89, in  <module>
   main()
  File "C:\Users\school pc\Desktop\myProgram.py", line 20, in main
   totalBill(taxableTotal, taxes)
  File "C:\Users\school pc\Desktop\myProgram.py", line 74, in totalBill
   totalBill = taxableTotal + tax
TypeError: unsupported operand type(s) for +: 'function' and 'function'
回溯(最近一次呼叫最后一次):
文件“C:\Users\school pc\Desktop\myProgram.py”,第89行,在
main()
文件“C:\Users\school pc\Desktop\myProgram.py”,第20行,主目录
账单总额(应纳税总额、税金)
totalBill第74行的文件“C:\Users\school pc\Desktop\myProgram.py”
账单总额=应纳税总额+税款
TypeError:+:“function”和“function”的操作数类型不受支持

这是一个已清理的版本:

from   __future__ import print_function
import sys

if sys.hexversion < 0x3000000:
    # Python 2.x
    inp = raw_input
else:
    # Python 3.x
    inp = input

def get_login(max_tries=3):
    for try_ in range(max_tries):
        password = inp('Please enter a password: ')
        if password == 'spyderPC':
            print("Access granted")
            return True
    else:
        print("You have entered an incorrect password {} times.".format(max_tries))
        return False

def get_number(prompt, low=None, high=None, type_=float):
    while True:
        try:
            number = type_(inp(prompt))
            if low is not None and number < low:
                print("Value must be >= {}".format(low))
            elif high is not None and high < number:
                print("Value must be <= {}".format(high))
            else:
                return number
        except ValueError:
            pass

def get_yn(prompt, default=None, yeses={'y','yes'}, noes={'n','no'}):
    while True:
        s = inp(prompt).strip().lower() or default
        if s in yeses:
            return True
        elif s in noes:
            return False

def get_hours(max_hours=80):
    return get_number("Hours worked: ", 0., max_hours)

def get_shop_rate():
    return get_number("Shop rate: ", 0.)

def get_parts_price():
    return get_number("Total price of parts: ", 0.)

def calc_taxes(before_taxes, tax_rate=0.08):
    return before_taxes * tax_rate

def write_bill(outf):
    # get inputs
    shop_rate    = get_shop_rate()
    hours        = get_hours()
    parts        = get_parts_price()
    # calculate results
    labor        = shop_rate * hours
    before_taxes = labor + parts
    taxes        = calc_taxes(before_taxes)
    after_taxes  = before_taxes + taxes
    # write results
    outf.write(
        "\n"
        "The bill is\n"
        "  Hours    {hours:6.2f}  h\n"
        "  @Rate  $ {shop_rate:6.2f} /h\n"
        "                    == {labor:8.2f}\n"
        "  Parts                {parts:8.2f}\n"
        "                     ----------\n"
        "                       {before_taxes:8.2f}\n"
        "                + Tax  {taxes:8.2f}\n"
        "                     ----------\n"
        "               Total $ {after_taxes:8.2f}\n"
        .format(**locals())
    )

def main():
    print("Create a bill!")

    if get_login():
        with open("Bill.txt", "a") as outf:
            while True:
                write_bill(outf)
                if not get_yn("Do another bill? [Y/n] ", default='y'):
                    break

if __name__=="__main__":
    main()

您使用
taxabletottal
作为函数名和变量——选择一个并重命名另一个。以及
shopRate
priceOfParts
。调用返回要保存的值的函数时,通常需要将其存储在不同名称的变量中。i、 e.
totalsaddable=taxable总计(零件价格、工时、购物价格)
,而
billtoatal=totalBill(totalsaddable,税费)
更为正确(除了
税费
未定义)。
from   __future__ import print_function
import sys

if sys.hexversion < 0x3000000:
    # Python 2.x
    inp = raw_input
else:
    # Python 3.x
    inp = input

def get_login(max_tries=3):
    for try_ in range(max_tries):
        password = inp('Please enter a password: ')
        if password == 'spyderPC':
            print("Access granted")
            return True
    else:
        print("You have entered an incorrect password {} times.".format(max_tries))
        return False

def get_number(prompt, low=None, high=None, type_=float):
    while True:
        try:
            number = type_(inp(prompt))
            if low is not None and number < low:
                print("Value must be >= {}".format(low))
            elif high is not None and high < number:
                print("Value must be <= {}".format(high))
            else:
                return number
        except ValueError:
            pass

def get_yn(prompt, default=None, yeses={'y','yes'}, noes={'n','no'}):
    while True:
        s = inp(prompt).strip().lower() or default
        if s in yeses:
            return True
        elif s in noes:
            return False

def get_hours(max_hours=80):
    return get_number("Hours worked: ", 0., max_hours)

def get_shop_rate():
    return get_number("Shop rate: ", 0.)

def get_parts_price():
    return get_number("Total price of parts: ", 0.)

def calc_taxes(before_taxes, tax_rate=0.08):
    return before_taxes * tax_rate

def write_bill(outf):
    # get inputs
    shop_rate    = get_shop_rate()
    hours        = get_hours()
    parts        = get_parts_price()
    # calculate results
    labor        = shop_rate * hours
    before_taxes = labor + parts
    taxes        = calc_taxes(before_taxes)
    after_taxes  = before_taxes + taxes
    # write results
    outf.write(
        "\n"
        "The bill is\n"
        "  Hours    {hours:6.2f}  h\n"
        "  @Rate  $ {shop_rate:6.2f} /h\n"
        "                    == {labor:8.2f}\n"
        "  Parts                {parts:8.2f}\n"
        "                     ----------\n"
        "                       {before_taxes:8.2f}\n"
        "                + Tax  {taxes:8.2f}\n"
        "                     ----------\n"
        "               Total $ {after_taxes:8.2f}\n"
        .format(**locals())
    )

def main():
    print("Create a bill!")

    if get_login():
        with open("Bill.txt", "a") as outf:
            while True:
                write_bill(outf)
                if not get_yn("Do another bill? [Y/n] ", default='y'):
                    break

if __name__=="__main__":
    main()
The bill is
  Hours     18.00  h
  @Rate  $  65.00 /h
                    ==  1170.00
  Parts                  231.46
                     ----------
                        1401.46
                + Tax    112.12
                     ----------
               Total $  1513.58

The bill is
  Hours     12.00  h
  @Rate  $  88.00 /h
                    ==  1056.00
  Parts                  451.19
                     ----------
                        1507.19
                + Tax    120.58
                     ----------
               Total $  1627.77