Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
help with list
#15
(Jan-31-2019, 11:04 AM)perfringo Wrote: Sloppy expression skills in spoken language translates into code with unexpected results. You wrote: "it gives "correct number a" instead of the other option". I demonstrated that this is not the case. You responded: 'so,it's wrong!'. How come? It was you who was wrong by stating that output is "correct number a".

If you are not able to express yourself in spoken language you are not able to express yourself in programming.

Regarding your problem: you should validate user input. This means that you have to ask user until answer is valid. There is while loop in Python to do so. Easiest way is to move validation to separate function but I don't know whether you know (or are allowed) how to use them.

i meant that since a=125 its out of range and it should give the "give again number a" answer.
as for validation,you mean something like that?

while True:
    try:
        a = int(input('a: '))
        if a < 100 or a > 121:
            raise ValueError
        break
    except ValueError:
        print("Invalid integer. The number must be in the range of 100-121.")
and one more while for number b?
Reply


Messages In This Thread
help with list - by sonedap - Jan-30-2019, 04:18 PM
RE: help with list - by perfringo - Jan-30-2019, 04:39 PM
RE: help with list - by sonedap - Jan-30-2019, 04:47 PM
RE: help with list - by perfringo - Jan-30-2019, 04:56 PM
RE: help with list - by sonedap - Jan-30-2019, 05:28 PM
RE: help with list - by ichabod801 - Jan-30-2019, 05:37 PM
RE: help with list - by sonedap - Jan-30-2019, 05:50 PM
RE: help with list - by ichabod801 - Jan-30-2019, 07:18 PM
RE: help with list - by nilamo - Jan-30-2019, 09:00 PM
RE: help with list - by sonedap - Jan-31-2019, 08:48 AM
RE: help with list - by sonedap - Jan-31-2019, 09:51 AM
RE: help with list - by perfringo - Jan-31-2019, 10:19 AM
RE: help with list - by sonedap - Jan-31-2019, 10:37 AM
RE: help with list - by perfringo - Jan-31-2019, 11:04 AM
RE: help with list - by sonedap - Jan-31-2019, 11:20 AM
RE: help with list - by perfringo - Jan-31-2019, 11:55 AM
RE: help with list - by sonedap - Jan-31-2019, 02:30 PM
RE: help with list - by perfringo - Jan-31-2019, 02:33 PM
RE: help with list - by sonedap - Jan-31-2019, 04:44 PM
RE: help with list - by perfringo - Jan-31-2019, 04:57 PM
RE: help with list - by sonedap - Feb-01-2019, 07:56 AM
RE: help with list - by ichabod801 - Feb-01-2019, 03:52 PM
RE: help with list - by sonedap - Feb-01-2019, 04:29 PM

Forum Jump:

User Panel Messages

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