小编gre*_*n20的帖子

基本Python问题(UnboundLocalError:赋值前引用的局部变量'normal')

我有一个非常基本的问题,我知道你们很容易发现错误.

现在我正在尝试编写一个计算加班费的脚本.我没有编写很多代码,所以我现在只是想坚持基本问题.我已经通过代码学院,我将以艰难的方式开始学习Python,但是我认为我需要制作更多的项目才能更好地理解.

这是我现在的代码.我很困惑为什么它认为变量尚未定义,因为我显然正在定义顶部需要的三个变量.

### California overtime payment calculator.


### Based on an 8 hour normal day, 1.5x day rate after 8 hours, and 2x pay after 12 hours.
### Enter your rate, then the number of hours you worked and you will get a result.



rate = raw_input("Enter your current rate:")

print "This is your rate: %s" % (rate)
normal = 0
overtime = 0
doubleOT = 0



def enteredHours():
        userInput = raw_input("Enter your hours for given day: ")

        if …
Run Code Online (Sandbox Code Playgroud)

python variables

0
推荐指数
1
解决办法
194
查看次数

标签 统计

python ×1

variables ×1