Values in if-else

179 Views Asked by At

I have directions for a programming assignment that says, all within a conditional, I need to prompt the user 7 times for their scores [hi,med,low]. I need to be able to use these values later so naturally I assigned them all to a value to be able to use later:

if title != '':
        visuals = input('Visuals [hi/med/lo]:')
        production = input('Production Design [hi/med/lo]:')
        music = input('Music [hi/med/lo]:')
        sound = input('Sound Design [hi/med/lo]:')
        story = input('Story [hi/med/lo]:')
        characters = input('Characters [hi/med/lo]:')
        genre_gameplay = input('Gameplay or Genre [hi/med/lo]:')
        scores_list.append(visuals[0].lower)

I am getting the error "unused variable" for each of the values like "music" that I used. Im guessing I cant declare a new value like this in a conditional, it needs to be already existing? or is there a better way to do this?

1

There are 1 best solutions below

0
On

Here's a breakdown of what you're doing and why you are getting those warnings (errors would raise exceptions, warnings merely alert you that something may be wrong).

You're creating a bunch of variables and assigning them the return value of the input() function, that value will be whatever the user types. Once you reach the end, every variable will have its own value, however you do something weird there.

When you use [index] on a string, you're accessing a single character (or set of characters) in that string. Furthermore, you're using .lower, but without parenthesis, so what you're actually appending to the scores_list list (which I assume has been defined previously) is a reference to the .lower method for strings. None of the other values are being used.

Assuming you want to store all of the values in the list, I'd recommend you store all of the categories in a list, and then use a for loop to go through them and add them to the scores_list list:

if title != '':
    # store categories
    questions = [
        "Visuals",
        "Production Design",
        "Music",
        "Sound Design",
        "Story",
        "Characters",
        "Gameplay or Genre"
    ]
    
    for question in questions:
        # ask each question
        answer = input(f'{question} [hi/med/lo]: ')
        scores_list.append(answer.lower())