我对此还很陌生。该代码应该继续循环,直到/除非我按回车键而不输入值。它进行了 2 个循环,然后给出了 NoneType
错误。沮丧的。请帮忙。我的代码:
import random
hourly = 70
CustomerID = random.randint(100000,999999)
Customers = {}
characters = ['a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I,J,K,L,,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z']
def generateRecord():
cusName = input('Enter customer name:')
cusIncome = int(input('Enter customer annual income:'))
consulTime = int(input('Enter Consultation time in minutes:'))
if cusIncome <= 25000:
CustRate = (.4)
print('Rate = 40% for time over 30 minutes')
if cusIncome > 25000:
CustRate = (.7)
print('Rate = 70% for time over 20 minutes')
if CustRate ==.4 and consulTime< 30:
CustRate == 0
if CustRate==.7 and consulTime <20:
CustRate == 0
billingAmt = hourly*CustRate*(consulTime/60)
CustomerID
print('Customer ID is '+str(CustomerID))
Customers[CustomerID] = [cusName, cusIncome, consulTime, CustRate, billingAmt]
def generateBillAmount():
cusIncome = int(input('Enter customer annual income:'))
consulTime = int(input('Enter Consultation time in minutes:'))
if cusIncome <= 25000:
CustRate = .4
print('Rate = 40% for time over 30 minutes')
else:
CustRate = .7
print('Rate = 70% for time over 20 minutes')
if CustRate ==.4 and consulTime< 30:
CustRate = 0
if CustRate==.7 and consulTime <20:
CustRate = 0
billingAmt = int(hourly*CustRate*(consulTime/60))
if CustRate==.4 and consulTime>30:
billingAmt = int(hourly*CustRate*((consulTime-30)/60))
if CustRate==.7 and consulTime>20:
billingAmt = int(hourly*CustRate*((consulTime-20)/60))
print('Customer total is ' +str(billingAmt)+' dollars.')
generateRecord()
for cusName in generateRecord():
for character in cusName:
if cusName == '\n':
print(Customers)
break
else:
generateRecord()
generateBillAmount()
以下是它通常返回的内容:
Enter customer name:jake
Enter customer annual income:15000
Enter Consultation time in minutes:15
Rate = 40% for time over 30 minutes
Customer ID is 594578
Enter customer name:trix
Enter customer annual income:45000
Enter Consultation time in minutes:45
Rate = 70% for time over 20 minutes
Customer ID is 594578
Traceback (most recent call last):
File "C:/Users/Hammad/GenerateRecords.py", line 45, in <module>
*for cusName in generateRecord():
TypeError: 'NoneType' object is not iterable*
最佳答案
除非显式指定返回
值,否则Python默认返回None
。由于您正在循环 generateRecord()
的响应,该响应为 None
;所以你得到一个错误。尝试为函数定义一个返回值
关于python - 不断收到非类型错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42534885/