-3

Python 3.5

So I want to know how I can make variables based on the input of the user.

for example :,

I have the follwing code: residents=input("How many people live in your house?")

If the answer '7' I should prompt 7 times to ask the for names of the 7 residents one by one. How can I do this?

Dhia
  • 10,119
  • 11
  • 58
  • 69
  • 5
    (a) you asked this already, and were answered: http://stackoverflow.com/questions/34697159/variables-based-on-input (b) **don't** make a whole bunch of named variables, use a list. – Hugh Bothwell Jan 09 '16 at 20:48

1 Answers1

0

If all you want is to store a list of names of residents, use a list:

resident_list = []
residents = input("How many people live in your house?")
print("Please enter the names of %d residents, one to a line" % residents)
while residents:
    resident_list.append(input("Resident name: "))
    residents -= 1

(For clarity purposes, there's no error checking of the input in the code sample)

If you want to do more than that, you'll have to post an update to your question that specifies what further processing you want to do once you know the names of the residents.

Pat Knight
  • 101
  • 6
  • I want to store the names present additional information about each resident which will be collected later- like age, height etc. so I want it to show data about each person and present it to the user – TheHolyTurnip Jan 09 '16 at 22:25