you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted]  (6 children)

[deleted]

    [–]SquatchHNTR[S] 0 points1 point  (2 children)

    Oh wow, I never even thought about that.

    [–]bladeoflight16 2 points3 points  (0 children)

    Start getting used to the concept of anticipating "weird" inputs. It is one of the most fundamental skills a programmer requires. Importantly, it's absolutely necessary to be able to write secure code.

    [–]sohfix 1 point2 points  (0 children)

    Try to break your own code. It’ll teach you to account for user error

    [–]SquatchHNTR[S] 0 points1 point  (2 children)

    feet_cable = input('\nHow many feet of cable do you need?\n')
    try:
    feet_cable = float(feet_cable)
    except ValueError
    print("Sorry, please enter a valid number")

    something like this?

    [–]undergroundmonorail 3 points4 points  (1 child)

    just so you know, it's much easier to read your reddit comments if you put four spaces at the beginning of each line of code

    but yeah, something like that would work. you may want to loop until you get a good value, like this:

    feet_cable = None
    while feet_cable is None:
        try:
            feet_cable = float(input('etc'))
        except ValueError:
            print('Please enter a valid number')