Advertisement
vivaladiva

Untitled

Nov 11th, 2020
603
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.39 KB | None | 0 0
  1. # Init the empty dictionary
  2. dct = {}
  3.  
  4. while True:
  5.     # Ask for a name.
  6.     name = raw_input("Enter a name or an empty string to stop: ")
  7.  
  8.     # If the given name is empty string, break the loop.
  9.     if name == '':
  10.         break
  11.  
  12.     # Ask for an age.
  13.     age = int(input("Enter age: "))
  14.  
  15.     # Add user input to the dictionary. Name as key, age as value.
  16.     dct[name] = age
  17.  
  18. print(dct)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement