0

I'm currently trying to make an aesthetic personality quiz type thing in repl.it using python. I have 4 different variables that all start at 0, and depending on the user input, the scores will go up by one. I'm having some trouble making it to where the code will add to all of the variables.

At the moment, I can add 1 to one of the scores, but none of the others. I was wondering how I would go about doing this? Here is my current code:

#aesthetics 
dark = 0
basic = 0
fantasy = 0
academia = 0

#inputs
if input("""
Choose a color scheme!
a  Black, Grey, Purple
b  Blue, Pink, White
c  Green, Grey, Yellow
d  Brown, Red, Orange
>> """) == "a":
  dark += 1
elif input == "b":
  basic += 1

If I input "a" and ask it to print the value of dark, it will output "1". However, if I input "b" and ask it to print the value of basic, it will output "0".

1 Answers1

0

Since you're not capturing the input but only using it in the if statement, that's what happens.

The very simplest fix for that: read the input into a variable (choice here), then compare it to the options available.

# aesthetics
dark = 0
basic = 0
fantasy = 0
academia = 0

choice = input("""
Choose a color scheme!
a  Black, Grey, Purple
b  Blue, Pink, White
c  Green, Grey, Yellow
d  Brown, Red, Orange
>> """)

if choice == "a":
    dark += 1
elif choice == "b":
    basic += 1
elif choice == "c":
    # ...
elif choice == "d":
    # ...
AKX
  • 152,115
  • 15
  • 115
  • 172
  • I actually didn't think of that. Thank you so much! – Zeril Stanford Oct 27 '21 at 05:23
  • You're welcome! A simple next improvement might be to wrap this into a function to make it easier to keep re-asking the same question if the user enters an invalid choice. – AKX Oct 27 '21 at 05:26