Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
error with variables 3.8
#1
i have a program that im working on to emulate a number of clicks over a user defined amount of time with a user defined delay seperation. im working on error checking for the variable type
heres the relevant code
def get_time():
    print("enter 1 for seconds")
    print("enter 2 for minutes")
    print("enter 3 for hours")
    timeTyp = input("please enter one of the coresponding numbers> ")
    timeLen = input("please enter how long you want to run> ")
    timeDel = input("please enter how long you want the delay between clicks in miliseconds or d for default> ")
    try:
        timeTyp = int(timeTyp)
        timeLen = int(timeLen)
        try:
            timeDel = float(timeDel*1000)
        except ValueError:
            if(timeDel.lower().strip(" ") == "d"):
                td = 1.0
            else:
                err = True
        if(timeTyp == 1):
            tl = timeTyp
        elif(timeTyp == 2):
            tl = timeTyp * 60
        elif(timeTyp == 3):
            tl = timeTyp * 3600
        if(err == True):
            raise ValueError
    except ValueError:
        print("invalid input. try again")
        tl, td = get_time()
    return tl, td
what am i doing wrong
i get an error of UnboundLocalError

also i forgot in global scope
err = False
Reply


Messages In This Thread
error with variables 3.8 - by jusrosetyler1123 - Dec-18-2019, 05:52 AM
RE: error with variables 3.8 - by buran - Dec-18-2019, 07:23 AM
RE: error with variables 3.8 - by jusrosetyler1123 - Dec-18-2019, 01:38 PM
RE: error with variables 3.8 - by buran - Dec-18-2019, 03:16 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  I want to multiply two variables, but I get an error LeqendFire 3 2,145 Aug-09-2020, 03:52 PM
Last Post: LeqendFire

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020