1

Currently on my first python project to make a barista trainer, the current problem I am running into is that depending on the drink/recipe I need to ask a different number of questions. I have a (I think) good way to get the questions I need, the program asks them, but I cant take that input and assign them to a variable.

The code I have so far...

This is the call to my questions class

questions = Questions.get_questions((recipe_label.lower()))

This is where I get the input

for question in range(len(questions)):
    answer = input(questions[question]).split("\n")

The gap here is the part I can not figure out.

Where I call the class that creates the recipe based on input

recipe = Recipe_Factory.get_recipe(recipe_label, size_label, hot_label)

I have tried making a questions class, I tried using a for loop to assign each input to a list of variables, and some other stuff that super did not work at all, I honestly don't even care if it works the way I am trying, just need an intuitive way to have a changing number of questions and answers.

what I am expecting:

recipe_label = input(what do you want to practice)

#questions is a list of strings, the strings are the questions I'm asking

questions = Questions.get_questions((recipe_label.lower()))

Based on input, number of questions change

for question in range(len(questions)):
    answer = input(questions[question]).split("\n")

x, y, z, are the input values

x = input 1
y = input 2
z = input 3

#this is the call to actually build the recipe

recipe = Recipy_Factory(x,y,z)
crthompson
  • 15,653
  • 6
  • 58
  • 80

1 Answers1

1

Can you just store the answers in a global dict, at least to get started?

QnA_d = {}
for question in range(len(questions)):
    answer = input(questions[question]).split("\n")
    QnA_d[questions[question]] = answer

When you finish, you have a dictionary ("dict") with the Questions and the Answers.

You can also simplify your code a bit, as follows:

QnA_d = {}
for question in questions:
    answer = input(question).split("\n")
    QnA_d[question] = answer

With this simplification, I wonder if the input() line now shows a bug that was concealed before...

GaryMBloom
  • 5,350
  • 1
  • 24
  • 32