Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question 1: 1 Reset to Starter Code Write a program that asks for 'name' from the user and then asks for a number and stores

Question 1: 1

Reset to Starter Code

Write a program that asks for 'name' from the user and then asks for a number and stores the two in a dictionary (called 'the_dict') as key-value pair. The program then asks if the user wants to enter more data (More data (y/n)? ) and depending on user choice, either asks for another name-number pair or exits and stores the dictionary key, values in a list of tuples and prints the list. Note: Ignore the case where the name is already in the dictionary.

Example:

Name: pranshu

Number: 517-244-2426

More data (y/n)? y

Name: rich

Number: 517-842-5425

More data (y/n)? y

Name: alireza

Number: 517-432-5224

More data (y/n)? n

[('alireza', '517-432-5224'), ('pranshu', '517-244-2426'), ('rich', '517-842-5425')]

code:

dictlist = [] #declare variables #loop needed input("Name: ") input("Number: ") ##add name and number to dictionary input('More data (y/n)? ') #if more data, then repeat

for key, value in the_dict.items(): #we store the dictionary in a list, then sort and print temp = (key,value) dictlist.append(temp) print(sorted(dictlist))

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Moving Objects Databases

Authors: Ralf Hartmut Güting, Markus Schneider

1st Edition

0120887991, 978-0120887996

More Books

Students also viewed these Databases questions

Question

Did the groups function as a team?

Answered: 1 week ago

Question

3.What are the Importance / Role of Bank in Business?

Answered: 1 week ago

Question

What are Decision Trees?

Answered: 1 week ago

Question

What is meant by the Term Glass Ceiling?

Answered: 1 week ago