Class 10 Exam  >  Class 10 Questions  >  Write a Python program to enter the the numbe... Start Learning for Free
Write a Python program to enter the the number of family members and their age and store this information in dictionary?
Most Upvoted Answer
Write a Python program to enter the the number of family members and t...
**Python program to enter the number of family members and their age and store this information in dictionary**

To write a Python program to enter the number of family members and their age and store this information in a dictionary, we can follow the below steps:

1. Take input from the user for the number of family members.
2. Create an empty dictionary to store the family members' information.
3. Use a for loop to iterate over the range of number of family members entered by the user.
4. For each iteration, take input from the user for the family member's name and age.
5. Store the family member's information in the dictionary with their name as the key and age as the value.

Here is the complete Python program that implements the above steps:

```python
# take input from the user for the number of family members
num_members = int(input("Enter the number of family members: "))

# create an empty dictionary to store the family members' information
family = {}

# use a for loop to iterate over the range of number of family members
for i in range(num_members):
# take input from the user for the family member's name and age
name = input("Enter family member's name: ")
age = int(input("Enter family member's age: "))

# store the family member's information in the dictionary
family[name] = age

# print the dictionary containing the family members' information
print(family)
```

**Explanation:**

Let's go through the program step by step to understand how it works.

1. We start by taking input from the user for the number of family members using the `input()` function. We convert the input to an integer using the `int()` function and store it in the variable `num_members`.

```python
num_members = int(input("Enter the number of family members: "))
```

2. Next, we create an empty dictionary called `family` to store the family members' information.

```python
family = {}
```

3. We use a for loop to iterate over the range of number of family members entered by the user. The range function generates a sequence of numbers from 0 to `num_members - 1`.

```python
for i in range(num_members):
```

4. For each iteration of the for loop, we take input from the user for the family member's name and age using the `input()` function. We store the name in the variable `name` and the age as an integer in the variable `age`.

```python
name = input("Enter family member's name: ")
age = int(input("Enter family member's age: "))
```

5. Finally, we store the family member's information in the dictionary `family` using the family member's name as the key and their age as the value.

```python
family[name] = age
```

6. After all the family members' information has been entered and stored in the dictionary, we print the dictionary using the `print()` function.

```python
print(family)
```

This will output the dictionary containing the family members' information.
Community Answer
Write a Python program to enter the the number of family members and t...
#Program to create a dictionary which stores name of family members and their age
#entering the number of family members from user
num=int(input("Enter the the number of family members:"))
count=1
family=dict()      #Creating an empty dictionary
while count<=num:
    name=input("Enter the name of family member:")
    age=int(input("Enter age:"))
    family[name]=age
    count+=1
print("\n\nfamily_member\tage")
for k in family:
 print(k,'\t\t',family[k])
Output:

Attention Class 10 Students!
To make sure you are not studying endlessly, EduRev has designed Class 10 study material, with Structured Courses, Videos, & Test Series. Plus get personalized analysis, doubt solving and improvement plans to achieve a great score in Class 10.
Explore Courses for Class 10 exam

Top Courses for Class 10

Write a Python program to enter the the number of family members and their age and store this information in dictionary?
Question Description
Write a Python program to enter the the number of family members and their age and store this information in dictionary? for Class 10 2024 is part of Class 10 preparation. The Question and answers have been prepared according to the Class 10 exam syllabus. Information about Write a Python program to enter the the number of family members and their age and store this information in dictionary? covers all topics & solutions for Class 10 2024 Exam. Find important definitions, questions, meanings, examples, exercises and tests below for Write a Python program to enter the the number of family members and their age and store this information in dictionary?.
Solutions for Write a Python program to enter the the number of family members and their age and store this information in dictionary? in English & in Hindi are available as part of our courses for Class 10. Download more important topics, notes, lectures and mock test series for Class 10 Exam by signing up for free.
Here you can find the meaning of Write a Python program to enter the the number of family members and their age and store this information in dictionary? defined & explained in the simplest way possible. Besides giving the explanation of Write a Python program to enter the the number of family members and their age and store this information in dictionary?, a detailed solution for Write a Python program to enter the the number of family members and their age and store this information in dictionary? has been provided alongside types of Write a Python program to enter the the number of family members and their age and store this information in dictionary? theory, EduRev gives you an ample number of questions to practice Write a Python program to enter the the number of family members and their age and store this information in dictionary? tests, examples and also practice Class 10 tests.
Explore Courses for Class 10 exam

Top Courses for Class 10

Explore Courses
Signup for Free!
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev