文件“/Users//Desktop/A5/driverModule.py”,第22行,在控制器中 tripInfo() NameError:名称'tripInfo'未定义
好吧我真的卡住了,无法弄清楚为什么我会收到这个错误。任何帮助表示赞赏。
驱动程序模块
from TripInfoModule import *
def controller():
totalDrivingTime = 0
totalFuelCost = 0
totalAmountEarned = 0
totalNetIncome = 0
totalDistance = 0
totalFuelComsumed = 0
totalBreakTime = 0
input("Welcome to the updated trip income calculator. Press enter to continue: ")
i = "y"
while i == "y":
getDistance()
getEarningpPerMile()
getDrivingTime()
getBreakTime()
getFuelConsumed()
getCostperGallon()
tripInfo()
i = input("Would you like to add a new trip? Enter y to add a new trip, "
"or enter n to exit.")
print("Total fuel cost: $", format(totalFuelCost, '.2f'))
print("Total amount of fuel consumed:", format(totalFuelComsumed, '.2f'), "gallons")
print("Total miles driven:", format(totalDistance, '.2f'), "miles")
print("Total driving time:", format(totalDrivingTime, '.2f'), "hours")
print("Total break time:", format(totalBreakTime, '.2f'), "hours")
print("Total earned: $", format(totalAmountEarned, '.2f',))
print("Total net income: $", format(totalNetIncome, '.2f'))
def main():
controller()
main()
第2单元
from userInputModule import *
import driverModule
def tripInfo():
getNetIncome()
getTotalFuelConsumed()
getAmountEarned()
getNetIncome()
getTotalBreakTime()
getTotalDistance()
getTotalFuelConsumed()
getTotalDrivingTime()
def getFuelCost():
fuelConsumed = getFuelConsumed()
costPerGallon = getCostperGallon()
totalFuelCost = driverModule.controller()
gasUsed = float(fuelConsumed)
costPerGal = float(costPerGallon)
fuelCost = gasUsed * costPerGal
totalFuelCost += fuelCost
print("Your total fuel cost is:", format(fuelCost, '.2f'))
return fuelCost, totalFuelCost
def getAmountEarned():
distance = getDistance()
earnings = getEarningpPerMile()
totalAmountEarned = driverModule.controller()
distanceVar = float(distance)
earningsVar = float(earnings)
amountEarned = distanceVar * earningsVar
totalAmountEarned += amountEarned
print("Your earnings are:", format(amountEarned, '.2f'))
return amountEarned, totalAmountEarned
def getNetIncome():
totalNetIncome = driverModule.controller()
fuelConsumed = getFuelConsumed()
costPerGallon = getCostperGallon()
distance = getDistance()
earnings = getEarningpPerMile()
gasUsed = float(fuelConsumed)
costPerGal = float(costPerGallon)
distanceVar = float(distance)
earningsVar = float(earnings)
earnedIncome = distanceVar * earningsVar
fuelCost = gasUsed * costPerGal
taxAmount = earnedIncome * .08
netIncome = (earnedIncome - taxAmount) - fuelCost
totalNetIncome += netIncome
print("Your net income is:", format(netIncome, '.2f'))
return netIncome
def getTotalBreakTime():
breakTime = getBreakTime()
totalBreakTime = driverModule.controller()
breakTimeVar = float(breakTime)
totalBreakTime += breakTimeVar
return totalBreakTime
def getTotalDistance():
distance = getDistance()
totalDistance = driverModule.controller()
distanceVar = float(distance)
totalDistance += distanceVar
return totalDistance
def getTotalFuelConsumed():
fuelConsumed = getFuelConsumed()
totalFuelConsumed = driverModule.controller()
fuelConsumedVar = float(fuelConsumed)
totalFuelConsumed += fuelConsumedVar
return totalFuelConsumed
def getTotalDrivingTime():
drivingTime = getDrivingTime()
totalDrivingTime = driverModule.controller()
drivingTimeVar = float(drivingTime)
totalDrivingTime += drivingTimeVar
return totalDrivingTime
第1单元
def getDistance():
distance = input("Please enter the number of miles driven: ")
distanceStr = distance.replace(".", "")
while not distanceStr.isnumeric():
distance = input("Please enter a numeric distance "
"only that is non-zero: ")
distanceStr = distance.replace(".", "")
return distance
def getEarningpPerMile():
earningsPerMile = input("Please enter the amount earned per mile: ")
earningsPerMileStr = earningsPerMile.replace(".", "")
while not earningsPerMileStr.isnumeric():
earningsPerMile = input("Please enter a numeric number "
"only that is non-zero: ")
earningsPerMileStr = earningsPerMile.replace(".", "")
return earningsPerMile
def getDrivingTime():
totalDrivingTime = input("Please enter total driving time: ")
totalDrivingTimeStr = totalDrivingTime.replace(".", "")
while not totalDrivingTimeStr.isnumeric():
totalDrivingTime = input("Please enter a numeric number "
"only that is non-zero: ")
totalDrivingTimeStr = totalDrivingTime.replace(".", "")
return totalDrivingTime
def getBreakTime():
breakTime = input("Please enter the amount of break time taken: ")
breakTimeStr = breakTime.replace(".", "")
while not breakTimeStr.isnumeric():
breakTime = input("Please enter a numeric number "
"only that is non-zero: ")
breakTimeStr = breakTime.replace(".", "")
return breakTime
def getFuelConsumed():
fuelConsumed = input("Please enter the ammount of fuel consumed: ")
fuelConsumedStr = fuelConsumed.replace(".", "")
while not fuelConsumedStr.isnumeric():
fuelConsumed = input("Please enter a numeric number "
"only that is non-zero: ")
fuelConsumedStr = fuelConsumed.replace(".", "")
return fuelConsumed
def getCostperGallon():
costPerGallon = input("Please enter cost per gallon: ")
costPerGallonStr = costPerGallon.replace(".", "")
while not costPerGallonStr.isnumeric():
costPerGallon = input("Please enter a numeric number "
"only that is non-zero: ")
costPerGallonStr = costPerGallon.replace(".", "")
return costPerGallon
答案 0 :(得分:0)
这只是不鼓励*
导入的原因之一。首先明确在这里
from TripInfoModule import tripInfo, ...
如果该行无法找到tripInfo
,那么您可以更快地接近该错误。
现在tripInfo
在您称之为“Module2”
这个文件当然需要命名为“TripInfoModule”。确保没有可以加载的旧版本或.pyc
文件而不是您期望的文件