-4

I've got an idea for a program that I'm not sure how to implement. How can I make the program ask the user something -- input() -- as many times as user responds until x command is written and (and this is the hard part) create variables automatically (e.g answer1 = x, answer2 = x, answer3 = x, answer4 = x) with their respective value assigned? And how could I then print all those variables without having to write them manually, for example, if at the beginning 6 variables were created then the 6 variables will be printed. I'm not asking you to write it all for me, conversely I want you to give me some tips, some functions or ideas and I will be more than grateful. Thanks in advance!!

gonza
  • 3
  • 4

1 Answers1

1

If I understand your problem correctly, python lists should be a better solution to your problem. You can simply create an empty list:

answers = []

and then follow with something like this:

string = input()
while string != x:
    answers.append(string)
    string = input()

print(answers)
MoonMist
  • 1,232
  • 6
  • 22
  • I've been working on this and I got another question. How can I multiply every number in the list by a variable which has a float number? – gonza Nov 16 '19 at 06:16
  • I understand that it has to be int but I need the exact number in the variable – gonza Nov 16 '19 at 06:26
  • @gonza I'm not sure what you're asking. You cannot multiply a string and a float without throwing an error. If you want the list to contain numerical values, then it would be possible – MoonMist Nov 18 '19 at 00:07