Feb-06-2018, 07:19 AM
(This post was last modified: Feb-06-2018, 07:26 AM by gjenkinslb.)
Here is a variation that is a little better (see my comments):
Here is another more structured:
d = {} for _ in range(10): # loop ten times name = input('Enter your Name :') # store str input if name == 'stop': break # nice to be able to stop early to test it age = int(input('Input your age :')) # convert str input to int height = float(input('Input your height :')) # convert str input to float d[name] = [ age, height] # add new list with age and height to dict d print(d)
Here is another more structured:
d = {} def input_name_data(): name = input('Enter your Name :') # store str input if name == 'stop': return None, None age = int(input('Input your age :')) # convert str input to int height = float(input('Input your height :')) # convert str input to float return name, [age, height] for _ in range(10): name, data = input_name_data() if name is not None: d[name] = data else: break print(d)