Question

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_dicr) as key-value pair. The program then asks if the user wants to enter more data [More data ly/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 l(alireza, 517-432-5224), [pranshu, 517-244-2426], [rich, 517-842-5425) Code Full Screen code.py ? ? New 1 dictlist [ 4 input (Name: ) 5 input (Number:) 7 input(More data (y/n)?) 9 to ct 10 for key, value in the dict.items(): temp (key,value) dictlist.append (temp) 12 13 print (sorted(dictlist))

0 0
Add a comment Improve this question Transcribed image text
Answer #1

dictlist = []

the_dict = {}

while True:

# taking user input for name and number

name = input("Name :")

number = input("Number :")

# putting it into dictionary and list

dictlist.append((name, number))

the_dict[name] = number

# asking for choice

choice = input("\nMore data (y/n)?")

if choice == 'n':

break

# printing output

print()

print(the_dict)

print(sorted(dictlist))

Add a comment
Know the answer?
Add Answer to:
Write a program that asks for 'name from the user and then asks for a number...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a program that asks the user for a student name and asks for grades until...

    Write a program that asks the user for a student name and asks for grades until the user enters a non-number input, it should then ask if the user wants to enter another student, and keep doing the process until the user stops adding students. The student’s must be stored in a dictionary with their names as the keys and grades in a list. The program should then iterate over the dictionary elements producing the min, max, and mean of...

  • python program 6 Write an input validation loop that asks the user to enter a number...

    python program 6 Write an input validation loop that asks the user to enter a number in the range of 100 through 1000? 7 Write an input validation loop that asks the user to enter ‘Y’, ‘y’, ‘N’, or ‘n’? 8 How many times the following loop will repeat? cnt = 0    while  cnt != 5: print(cnt) cnt = cnt + 2

  • Write a C++ program that asks the user to enter a single number from 1 to...

    Write a C++ program that asks the user to enter a single number from 1 to 50 and a choice of "even" or "odd". Using a recursive function, output the sum of all the even or odd integers from 1 up to (and including) that number. Your program does not need to loop and accept more input (only one input of the number then even/odd).

  • Write a python program that does the following. a. It asks the user to enter a...

    Write a python program that does the following. a. It asks the user to enter a 5-digit integer value, n. b. The program reads a value entered by the user. If the value is not in the right range, the program should terminate. c. The program calculates and stores the 5 individual digits of n. d. The program outputs a “bar code” made of 5 lines of stars that represent the digits of the number n. For example, the following...

  • Write a PYTHON program that asks the user for the name of the file. The program...

    Write a PYTHON program that asks the user for the name of the file. The program should write the contents of this input file to an output file. In the output file, each line should be preceded with a line number followed by a colon. The output file will have the same name as the input filename, preceded by “ln” (for linenumbers). Be sure to use Try/except to catch all exceptions. For example, when prompted, if the user specifies “sampleprogram.py”...

  • ***** JAVA ONLY ***** Write a program that asks the user to enter the name of...

    ***** JAVA ONLY ***** Write a program that asks the user to enter the name of a file, and then asks the user to enter a character. The program should count and display the number of times that the specified character appears in the file. Use Notepad to create a simple file that can be used to test the program. ***** JAVA ONLY *****

  • Write a program that asks the user to type an even number or 111 to stop....

    Write a program that asks the user to type an even number or 111 to stop. When the user types an even number, display the message “Great Work”, and then ask for input again. When the user types an odd number, display the message “Try again” and ask the user to enter again. When the user enters the sentinel value of 111 the program ends I've attempted this but it went horribly wrong. we are only suppose to use while,...

  • 3. Write a program that asks the user for the name of two input files and...

    3. Write a program that asks the user for the name of two input files and appends the data from the second file onto the first file. To be clear: the second file should be unchanged, and the first file should end up holding all its own data followed by all the data from the second file. Be sure to handle the potential error of a missing data file appropriately.

  • Write a program which asks the user to enter a number. While the number is outside...

    Write a program which asks the user to enter a number. While the number is outside the range of 50 to 65 (exclusive). print "This is not valid input." and ask the user to re-enter a number. Remember to include a comment at the start of the program. 7 A- B I - : F F 2

  • Write a program that asks the user for his or her name, and then asks the user to enter a sentence that describes him or herself.

    23. Personal Weeb Page GeneratorWrite a program that asks the user for his or her name, and then asks the user to enter a sentence that describes him or herself. Here is an example of the program's screen:Enter your name: Julie Taylor [Enter]<html>  <head>  </head>  <body>    <center>      <h1>Julie Taylor</h1>    </center>    <hr />    I am a computer science major, a member of the Jazz club,    and I hope to work as a mobile app developer after I graduate.    <hr />  </body> </html>Describe yourself: I am a computer science major, a member of theOnce the user has entered the requested input, the program should create an HTML file,...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT