Most popular tags

306 questions

415 answers


329 users

Most active Members
this week:

    Recent Badges

    Notable Question
    - smartin -

    How do i use try and except, to make the user pick a number between 1-3?

    0 votes
    asked Nov 23, 2016 in Python by anonymous

    1 Answer

    +1 vote
    You would not use try and except for this.


    Try and except us used for trapping errors such as those generated when you try to convert a string to an int.

    You are trying to "range check" and input and you could use a while loop as below:

    while True:

        num = int(input ("get number"))

        if num > 0 and num < 3:     break


    If it works - please update the post and +1
    answered Sep 22, 2017 by smartin (10,770 points)
    Welcome to Selby Computing Q&A, where you can ask questions and receive answers from other students in Computer Science.