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

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)
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...
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...
in java code Modify your program as follows: Ask the user for the number of hours...
in java code Modify your program as follows: Ask the user for the number of hours worked in a week and the number of dependents as input, and then print out the same information as in the initial payroll assignment. Perform input validation to make sure the numbers entered by the user are reasonable (non-negative, not unusually large, etc). Let the calculations repeat for several employees until the user wishes to quit the program. Remember: Use variables or named constants...
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
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...
In your python program, ask the user to enter the annual income of an employee and...
In your python program, ask the user to enter the annual income of an employee and the years of experience. Pass these data to a function. The function decides if an employee does qualify for a loan or does not, then it prints a message based on the following rules: If the income is equal or greater than $40000, the function checks if the employee’s years of experience is greater than 4, if so the employee gets $6000 loan; otherwise,...
Write a Python program that has a loop to continuously ask the user for a number,...
Write a Python program that has a loop to continuously ask the user for a number, terminating the loop when the number entered is -1. Inside the loop, 1.) display one asterisk(*) if the number is 1, 2.) two asterisk(**) if the number is 2 and 3.) "OTHER" if the number is any other number.
Python Program Write a program that will ask a user on how many input colored balls...
Python Program Write a program that will ask a user on how many input colored balls of the following codes: R-red, B-blue, W-white, G-green and O-orange -will he or she would like to enter in the program and print the total number of Red balls were encountered. Assume an uppercase and lower case letter will be accepted.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT