lis = []
class Budget:
def __init__(self):
while True:
categories = input("Enter a category or type \"done\": ")
if categories.lower() == "done":
break
else:
lis.append(categories)
print(lis)
continue
while True:
try:
self.monthly_income = float(input("Enter your monthly income after taxes: "))
break
except ValueError:
print("Invalid Input : Please enter a number")
continue
while True:
print("Enter desired percentage of income spent for each category (do not include %): ")
try:
self.wants_perc = float(input("Wants: "))
self.needs_perc = float(input("Needs: "))
self.food_perc = float(input("Food: "))
if self.wants_perc + self.needs_perc + self.food_perc not in range(95, 105):
print("Invalid Input : Must add to 100%")
continue
else:
break
except ValueError:
print("Invalid Input : Please enter a number")
continue
I want to be able to use the strings stored in lis as part of my self.wants_perc. Is it possible to have it like self."string in lis"_perc? The wants, needs, and food is my original code, but im trying to figure out how to make my code shorter and be able to use whatever categories the user inputs, not just what I hard code in (there is more code irrelevant code to my question). Thanks in advance!