我仍然是超级新人。代码应该继续循环,直到/除非我输入而不输入值。它适用于2个循环,然后给出$currentDate = Get-Date
$lastDay = [DateTime]::DaysInMonth($currentDate.Year, $currentDate.Month)
$lastDayOfMonth = Get-Date ([DateTime]"$($currentDate.Month), $LastDay, $($currentDate.Year)") -Format 'dd/MM/yyyy'
Write-Host $lastDayOfMonth
错误。失意。请帮忙。我的代码:
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()
答案 0 :(得分:2)
除非明确指定return
值,否则python会返回None
作为默认值。由于您正在循环generateRecord()
的响应None
;所以你得到一个错误。尝试定义函数的返回值
答案 1 :(得分:1)
这是因为generateRecord()
没有返回任何内容。因此,创建的任何内容都不会保存。所以默认情况下它将是None
,无法迭代。将定义更改为以下
def generateRecord(Customers):
在该功能的末尾添加添加
return Customers
然后,这将更改函数范围之外的Customers字典...