-1

Here is my text:

def judgeScoreInput():
if int(input()) in range (11) == [0,1,2,3,4,5,6,7,8,9,10]:
  A = int(input("Enter Judge A Score: "))
  B = int(input("Enter Judge B Score: "))
  C = int(input("Enter Judge C Score: "))
  D = int(input("Enter Judge D Score: "))
  E = int(input("Enter Judge E Score: "))
judgeScoreInput()

I want the Judge score to have a range limit upon to 10 so user can't input more than 10, if they do it sends some sort if error message, how do I go about this?

Ersel Er
  • 731
  • 6
  • 22
  • you want a while loop – AJ123 Dec 14 '17 at 21:40
  • Possible duplicate of [Asking the user for input until they give a valid response](https://stackoverflow.com/questions/23294658/asking-the-user-for-input-until-they-give-a-valid-response) – ZF007 Dec 15 '17 at 12:04

1 Answers1

0

Here's one way of laying things out. Note that I avoid code duplication as much as possible, and take advantage of recursion to "re-ask" when the input is invalid

def get_score(name):
    score = int(input('Enter score for Judge {}: '.format(name)))
    if score not in range(11): # Note that we can't assign input to a variable and check that variable at the same time
        print('Please enter an integer score 0-10')
        return get_score(name)
    return score

def judge_score_input():
    judges = {}
    for judge in ('A', 'B', 'C', 'D', 'E'):
        judges[judge] = get_score(judge)
    return judges

judge_score_input will return a dictionary mapping the letters A-E to scores. In your original implementation, the local variables would have been discarded at the end of the function call.

Patrick Haugh
  • 59,226
  • 13
  • 88
  • 96
  • thanks 4 ur answer, im new to this so I just pasted ur code into python and on the first line it came up with invalid syntax? what do I need to do to fix this – Aarron Grigg Dec 14 '17 at 21:59
  • @AarronGrigg My bad, I missed a colon at the end of the first line. Try the fixed version – Patrick Haugh Dec 14 '17 at 22:07
  • I figured that bit but it returns with RESTART: and then my Mac info and also is blank when it runs.. any help is appreciated lol – Aarron Grigg Dec 14 '17 at 22:08
  • That doesn't seem to be related to this snippet of code. If you can't figure it out you should consider asking another question. – Patrick Haugh Dec 14 '17 at 22:11