Question

In: Computer Science

PYTHON Modify the program in section Ask the user for a first name and a last...

PYTHON

Modify the program in section

Ask the user for a first name and a last name of several people.

 Use a loop to ask for user input of each person’s first and last names

 Each time through the loop, use a dictionary to store the first and last names of that person

 Add that dictionary to a list to create a master list of the names

 Example dictionary:

aDict = { "fname":"Douglas", "name":"Lee" }

 Example master list, each element in the list is a dictionary:

namesList = [

{ "fname":"Douglas", "lname":"Lee" },

{ "fname":"Neil", "lname": "Armstrong" },

{ "fname":"Buzz", "lname":"Aldrin" },

{ "fname":"Eugene", "lname":"Cernan"},

{ "fname":"Harrison", "lname": "Schmitt"}

]

Pseudocode:

1) Ask for first name

2) Ask for last name

3) Create a dictionary with first name and last name

4) Add that dictionary to the master list object

5) If more names, go to (1)

6) If no more names, print the master list in a visually pleasing manner

Solutions

Expert Solution

# loop till no more names

master_list = []

while(True):

    # ask for first name

    fname = input("Enter first name: ")

    lname = input("Enter last name: ")

    # create dictionary

    name_dict = {"fname": fname, "lname": lname}

    # add to master list

    master_list.append(name_dict)

    # ask for more names

    choice = int(input("Press 1 if no more names: "))

    if choice == 1:

        break

# print master list

print(master_list)

.

Screenshot:

Output:

.


Related Solutions

Python Code: Write a program to prompt the user to enter a first name, last name,...
Python Code: Write a program to prompt the user to enter a first name, last name, student ID, number of hours completed and GPA for 5 students. Use a loop to accept the data listed below. Save the records in a text file. Write a second program that reads the records from your new text file, then determines if the student qualifies for Dean’s list or probation. Display the records read from the file on screen with appropriate headings above...
You will ask the end user to type their first name and their last name and...
You will ask the end user to type their first name and their last name and store it on separate string variables, you will ask for the gender, you will then concatenate both strings into a third string variable. You will salute the end user as Mr. or Ms depending on the gender and last you will display the initials of the end user. (You must use methods of the string class in this lab)
In python. Projectile motion: Write a python program that will ask the user for      an...
In python. Projectile motion: Write a python program that will ask the user for      an initial height y0, initial velocity v, launch angle theta, and mass m.      Create two functions, one that will calculate max height      of the projectile, and one that will calculate the range. Ask the     user which one he/she would like to calculate, then present them with the answer. (use kg, m and m/s)
java programming write a program with arrays to ask the first name, last name, middle initial,...
java programming write a program with arrays to ask the first name, last name, middle initial, IDnumber and 3 test scores of 10 students. calculate the average of the 3 test scores. show the highest class average and the lowest class average. also show the average of the whole class. please use basic codes and arrays with loops the out put should look like this: sample output first name middle initial last name    ID    test score1 test score2...
Calculating Delivery Cost Program in Python write a program in Python that will ask a user...
Calculating Delivery Cost Program in Python write a program in Python that will ask a user to enter the purchase total, the number of the items that need to be delivered and delivery day. Then the system displays the cost of delivery along with the total cost. Purchase total > $150 Yes Number of the items (N) N<=5 N>=6 Delivery day Same Day Next Day Same Day Next Day Delivery charges ($) 8 N * 1.50 N * 2.50 N...
C++ Change the program to take user input for first name and last name for five...
C++ Change the program to take user input for first name and last name for five employees. Add a loop to read the first name and last name. // EmployeeStatic.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include <string> #include <iostream> #include <string> using namespace std; class Employee { public:    Employee(const std::string&, const std::string&); // constructor    ~Employee(); // destructor    std::string getFirstName() const; // return first name    std::string getLastName() const; // return...
First, the Python program prompts user to enter user information (name, email, and phone number). Then...
First, the Python program prompts user to enter user information (name, email, and phone number). Then it displays a menu called “Fish Information” that has the following fish type: 1. Cat Fish 2. Red Fish 3. Any other fish Let user choose the fish type that he/she got and input the length of the fish. Then the program will determine what should be done with this particular fish. Based on the following criteria: Criteria: Length: FISHTYPE - Cat Fish <10:...
Create a program (Python) YourFirstnameLastnameA06b.py to ask the user to create a password: The user will...
Create a program (Python) YourFirstnameLastnameA06b.py to ask the user to create a password: The user will first enter a password, then enters the same password again; If the second input is the same as first one, the user successfully creates the password. Print “Well done.”; Otherwise, the user will be directed to repeat the whole process (go to step 1.)
Modify the Assignment program from Module 1 to read a user's first and last name read...
Modify the Assignment program from Module 1 to read a user's first and last name read three integer scores, calculate the total and average determine the letter grade based on the following criteria - Average 90-100 grade is A, 80-89.99 grade is B, 70-79.99 grade is C, all others F (use a nested if) Output formatted results consisting of the full name, the three scores, the total, average (to 2 decimal places), and the letter grade go to step 1...
Create a small program that contains the following. ask the user to input their name ask...
Create a small program that contains the following. ask the user to input their name ask the user to input three numbers check if their first number is between their second and third numbers
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT