Write a program in python to create dictionary for 2 student
Read name,age and marks by user?
Answers
def create_dict(values):
zip_obj = zip(create_std_keys(2), values)
return dict(zip_obj)
def create_std_keys(stds):
stds_keys = []
for n in range(stds):
name = f"std_name_{n}"
age = f"std_age_{n}"
marks = f"std_marks_{n}"
stds_keys.extend([name, age, marks])
return stds_keys
std_0_name = input("std_0_name: ")
std_0_age = int(input("std_0_age: "))
std_0_marks = float(input("std_0_marks: "))
print()
std_1_name = input("std_1_name: ")
std_1_age = int(input("std_1_age: "))
std_1_marks = float(input("std_1_marks: "))
std_values = [std_0_name, std_0_age, std_0_marks, std_1_name, std_1_age, std_1_marks]
print(f'\n{create_dict(std_values)}')
The solution could be shorter, but I wanted to auto generate the dict keys and then auto generate the dict itself.