Python 3.x 未定义名称“是”

Python 3.x 未定义名称“是”,python-3.x,debugging,logic,Python 3.x,Debugging,Logic,当我进一步了解代码时,它告诉我没有定义Yes。代码询问用户他们工作了多长时间并计算代码 我试着对那句话做了一些小改动。它给了我同样的结果 当用户回答“是”时;我想要代码来计算工资总额 Overtimeflag = 50 if Overtimeflag == 50: Overtimeflag = True Else: Overtimeflag = False Name = input('Whats your first and last name') Address = inpu

当我进一步了解代码时,它告诉我没有定义Yes。代码询问用户他们工作了多长时间并计算代码

我试着对那句话做了一些小改动。它给了我同样的结果

当用户回答“是”时;我想要代码来计算工资总额

Overtimeflag = 50

if Overtimeflag == 50: 

 Overtimeflag = True

Else:

Overtimeflag = False


Name = input('Whats your first and last name')

Address = input('Whats your address')

HoursWorked=float(input('How many years have you been working here'))

Overtime=float(input('how long did you work today'))

if HoursWorked > 40:

   print('You are qualified for overtime pay')

elif Overtime >= 2:

    Overtime = HoursWorked - 40

else:

    print('In order to earn overtime, the user must have worked for at least 2 years')

grossPay =float(input('Whats your hourly rate'))

Overtimeflag =input('Did you work 50 hours this week')

##Calculate the gross pay with the following formula

if grossPay == Yes:

    Overtime2 * grossPay * 2 + HoursWorked - Overtimeflag * grossPay

else:

    print('You do not earn overtime due to lack of years of service')


Yes必须是字符串,因为前面没有定义它

输出:


如果你发布你的实际代码,这会有所帮助。。。我们不是魔术师。你的代码还有其他问题。您将grossPay与Yes进行比较,但grossPay是一个浮动输入“您的小时费率是多少”。什么是超期?
Overtimeflag = 50

if Overtimeflag == 50: 
 Overtimeflag = True
else:
    Overtimeflag = False


Name = input('Whats your first and last name')

Address = input('Whats your address')

HoursWorked=float(input('How many years have you been working here'))

Overtime=float(input('how long did you work today'))

if HoursWorked > 40:
   print('You are qualified for overtime pay')
elif Overtime >= 2:
    Overtime = HoursWorked - 40
else:
    print('In order to earn overtime, the user must have worked for at least 2 years')
grossPay =float(input('Whats your hourly rate'))
Overtimeflag3 =input('Did you work 50 hours this week')
##Calculate the gross pay with the following formula

if Overtimeflag3 == "Yes":
    Overtime2 = grossPay * 2 + HoursWorked - Overtimeflag * grossPay
    print("Overtime pay: ",Overtime2 )
else:
    print('You do not earn overtime due to lack of years of service')

Whats your first and last namecd scsd
Whats your addresscsd
How many years have you been working here9
how long did you work today99
Whats your hourly rate9
Did you work 50 hours this weekYes
Overtime pay:  18.0