0

I have a dictionary with parameters and their values which I retrieve from the console with an interactive program.

mydic = { 'n': Nvalue , 'p': Pvalue }

I want to fixe one value and vary the other between a min and max with a step. For example if the user chooses to vary p he must choose the min and max value and the step. And I must have at the and as dictionaries as possibilities.

min = 0.2
max = 0.5
step = 0.2
n = 3

as a result I will have :

mydic = { 'n': 3 , 'p': 0.2 }
mydic = { 'n': 3 , 'p': 0.4 }

Here is the code I have written. I didn't manage to update the dictionary to obtain the diffrent possibilities

if var_param == param["name"]:
   minimum = int(input("  Choose the min value of " + var_param + " : "))
   maximum = int(input("  Choose the max value of " + var_param + " : "))
   step = int(input("  Choose the step of the variation : "))

   i = minimum
   while i <= maximum :
       mydic.update({var_param: i+step})
       i= i + step

if var_param != param["name"]:
   mydic.update({param["name"]: int(input("Choose the value of "+ param["name"]+ " : "))})
print(mydic)

I get only one dictionary. I know that the problem is in the while-loop but I don't know how to fix it to get all the possible dictionaries with the right values.

Thanks in advance

user850287
  • 289
  • 1
  • 4
  • 11

1 Answers1

2

You are replacing your old dictionary inside the while loop. You need to assign a array [minimum, step, step, step, maximum] as the value for the dict key.

PVaz
  • 130
  • 1
  • 2
  • 6