python - 不断收到非类型错误

标签 python nonetype python-3.6

我对此还很陌生。该代码应该继续循环,直到/除非我按回车键而不输入值。它进行了 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/

相关文章:

python - PySimpleGUI 表元素。如何读取选定的行?

python - Pyspark 中的 lambda 函数无法识别全局变量

python - “NoneType”对象不可下标-数据生成器

python - 在返回最后一次迭代的for循环中生成字典

algorithm - 遍历值为整数列表的字典并重新排序

python - 从旧数据框创建子列

python - 如何测试字典是否包含某些键

python - 终止 IronPython 脚本

python - 检查 PyObject 是否为 None

python - 如何消除 double_click_input() 操作的延迟?