Python Assignment
Python Assignment
1. Start
❖ pandas
❖ openpyxl
a. Loop indefinitely:
b. Loop indefinitely:
❖ Prompt the user to enter the file name (without extension) to save data.
6. End
Python Source Code
import pandas as pd
def safe_input_int(prompt):
while True:
user_input = input(prompt)
try:
value = int(user_input)
return value
except ValueError:
print("Error: Please enter a valid integer.")
def survey_census():
households_data = []
while True:
household_name = input("Enter household name: ")
num_people = safe_input_int("Enter number of people in the household: ")
individuals_list = []
person_details = {
'Household Name': household_name,
'Name': person_name,
'Age': person_age,
'Address': person_address
}
individuals_list.append(person_details)
households_data.extend(individuals_list)