我想创建一个程序,它接受3个不同的输入并将它们存储在3个单独的列表中,然后能够将它们组合在字典中并在屏幕上打印。
到目前为止我得到了这个:
size = input("Enter size of family: ")
names = []
year = []
address= []
for i in range(int(size)):
print("Enter name: ", end=' ')
names.append(input())
print("Enter birthyear: ", end=' ')
year.append(int(input()))
print("Enter address: ", end=' ')
address.append(str(input()))
d = list(zip(names, year, address))
print(d)
您可以简化这段代码:
size = int(input("Enter size of family: "))
family_data = {}
for i in range(size):
name = input("Enter name: ")
birthyear = int(input("Enter birthyear: "))
address = input("Enter address: ")
family_data[name] = {'birthyear': birthyear, 'address': address}
print(family_data)