I just finished learning python basics from CS50 and I am now trying to make a small game program for practice. Halfway thru I ran into a potential problem.
To sum the game up it is like:
- User inputs 5 numbers from 0-9
- The game is programmed with multiple fixed patterns for the 5 numbers
- Match the user input with the patterns
- Based on what it matches (or none) give a score
Example:
User will enter - 1,2,3,4,5 Types of possible patterns - a,a+1,a+2,a+3,a+4 1 point - a,a+2,a+4,a+6,a+8 2 points - a,a+1,a+3,a+5,a+7 3 points
So in this case the user gets 1 points.
My current problem is, I am trying to make a lot of different patterns (Like 20), but the only way I know as of now is to use a if statement for each pattern like this
if .....
if .....
if .....
but if I am going to do this for many times it feels wrong. I tried searching for ways to reduce multiple if but methods like using jump table (dictionaries) does not seem to work here. Thanks in advance