Starting Out with Python (4th Edition)
4th Edition
ISBN: 9780134444321
Author: Tony Gaddis
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
Chapter 7, Problem 5PE
Program Plan Intro
Charge account validation
Program Plan:
- • Declare a function named “readfile()”.
- ○ The function accepts a file handler “inputfileobject” as a parameter.
- ○ Create an empty list “chargeaccountlist” to hold the account number from the input file.
- ○ Use “for” to iterate through the file and fetch the charge account numbers from each line of the file.
- ○ “append()” function is used to add the fetched charge account numbers from the file to the list “chargeaccountlist”.
- ○ The function finally returns the list “chargeaccountlist”.
- • Declare a function named “checknumber()”.
- ○ The function accepts a list “chargeaccountlist” as a parameter.
- ○ Prompt the user to enter a seven digit charge account number and store in a variable “n”.
- ○ Use an “if” statement to check whether “n” is in the list “chargeaccountlist”. If the statement returns true, print the user entered charge account number is valid; otherwise, print invalid.
- • In the “main()” function,
- ○ Open the file “charge_accounts.txt” and assign to “inputfileobject”.
- ○ Call the function “readfile()” with “inputfileobject” as a parameter and assign the function return to the “chargeaccountslist”.
- ○ Call the function “checknumber()” with “chargeaccountslist” as a parameter.
- • Finally, call the “main()” to execute the program.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
1994 Weekly Gas GraphIn the student sample programs for this book, you will find a text file named 1994_Weekly_Gas_Averages.txt. The file contains the average gas price for each week in the year 1994.(There are 52 lines in the file.) Using matplotlib, write a Python program that reads thecontents of the file then plots the data as either a line graph or a bar chart. Be sure to displaymeaningful labels along the X and Y axes, as well as the tick marks.
(in python)
Pendant Publishing edits multi-volume manuscripts for many authors. For each volume, they want a label that contains the author’s name, the title of the work, and a volume number in the form Volume 9 of 9. For example, a set of three volumes requires three labels: Volume 1 of 3, Volume 2 of 3, and Volume 3 of 3. Design an application that reads records that contain an author’s name, the title of the work, and the number of volumes. The application must read the records until eof is encountered and produce enough labels for each work. The flowchart must include a call symbol, at the beginning, to redirect the input to the external data file.
create a solution algorithm using pseudocode
create a flowchart using RAPTOR
Pendant Publishing edits multi-volume manuscripts for many authors. For each volume, they want a label that contains the author’s name, the title of the work, and a volume number in the form Volume 9 of 9. For example, a set of three volumes requires three labels: Volume 1 of 3, Volume 2 of 3, and Volume 3 of 3. Design an application that reads records that contain an author’s name, the title of the work, and the number of volumes. The application must read the records until eof is encountered and produce enough labels for each work. Design a flowchart and psuedocode Pendant Publishing.
Chapter 7 Solutions
Starting Out with Python (4th Edition)
Ch. 7.2 - What will the following code display? numbers =...Ch. 7.2 - Prob. 2CPCh. 7.2 - Prob. 3CPCh. 7.2 - Prob. 4CPCh. 7.2 - Prob. 5CPCh. 7.2 - Prob. 6CPCh. 7.2 - Prob. 7CPCh. 7.2 - Prob. 8CPCh. 7.3 - Prob. 9CPCh. 7.3 - Prob. 10CP
Ch. 7.3 - Prob. 11CPCh. 7.3 - Prob. 12CPCh. 7.3 - Prob. 13CPCh. 7.4 - What will the following code display? names =...Ch. 7.5 - Prob. 15CPCh. 7.5 - Prob. 16CPCh. 7.5 - Prob. 17CPCh. 7.5 - Prob. 18CPCh. 7.8 - Prob. 19CPCh. 7.8 - Prob. 20CPCh. 7.8 - Write a set of nested loops that display the...Ch. 7.9 - Prob. 22CPCh. 7.9 - Prob. 23CPCh. 7.9 - Prob. 24CPCh. 7.9 - Prob. 25CPCh. 7.10 - Prob. 26CPCh. 7.10 - Prob. 27CPCh. 7.10 - Prob. 28CPCh. 7.10 - Prob. 29CPCh. 7.10 - Prob. 30CPCh. 7.10 - To create a bar chart with the bar function, what...Ch. 7.10 - Assume the following statement calls the bar...Ch. 7.10 - Prob. 33CPCh. 7 - This term refers to an individual item in a list....Ch. 7 - This is a number that identifies an item in a...Ch. 7 - Prob. 3MCCh. 7 - This is the last index in a list. a. 1 b. 99 c. 0...Ch. 7 - This will happen if you try to use an index that...Ch. 7 - This function returns the length of a list. a....Ch. 7 - When the operator's left operand is a list and...Ch. 7 - This list method adds an item to the end of an...Ch. 7 - This removes an item at a specific index in a...Ch. 7 - Prob. 10MCCh. 7 - If you call the index method to locate an item in...Ch. 7 - Prob. 12MCCh. 7 - This file object method returns a list containing...Ch. 7 - Which of the following statement creates a tuple?...Ch. 7 - Prob. 1TFCh. 7 - Prob. 2TFCh. 7 - Prob. 3TFCh. 7 - Prob. 4TFCh. 7 - A file object's writelines method automatically...Ch. 7 - You can use the + operator to concatenate two...Ch. 7 - Prob. 7TFCh. 7 - You can remove an element from a tuple by calling...Ch. 7 - Prob. 1SACh. 7 - Prob. 2SACh. 7 - What will the following code display? values = [2,...Ch. 7 - Prob. 4SACh. 7 - Prob. 5SACh. 7 - Prob. 6SACh. 7 - Prob. 1AWCh. 7 - Prob. 2AWCh. 7 - Prob. 3AWCh. 7 - Prob. 4AWCh. 7 - Write a function that accepts a list as an...Ch. 7 - Prob. 6AWCh. 7 - Prob. 7AWCh. 7 - Prob. 8AWCh. 7 - Total Sales Design a program that asks the user to...Ch. 7 - Prob. 2PECh. 7 - Rainfall Statistics Design a program that lets the...Ch. 7 - Prob. 4PECh. 7 - Prob. 5PECh. 7 - Larger Than n In a program, write a function that...Ch. 7 - Drivers License Exam The local driver s license...Ch. 7 - Name Search If you have downloaded the source code...Ch. 7 - Prob. 9PECh. 7 - World Series Champions If you have downloaded the...Ch. 7 - Prob. 11PECh. 7 - Prob. 12PECh. 7 - Magic 8 Ball Write a program that simulates a...Ch. 7 - Expense Pie Chart Create a text file that contains...Ch. 7 - 1994 Weekly Gas Graph In the student sample...
Knowledge Booster
Similar questions
- PYTHON Language Programming Write a program that asks user for state name in a text document "state.txt" Please eneter a state: Georgia Georgia has been added to the list Enter another name(Y/N): Y Please enter a state: California New York is already in the list Enter another name (Y/N): N Here are the states in the file: California and Georgiaarrow_forwardProgram Specification For this assignment you will write a program to help people record the events of their day by supplying prompts and then saving their responses along with the question and the date to a file. Functional Requirements This program must contain the following features: Write a new entry - Show the user a random prompt (from a list that you create), and save their response, the prompt, and the date as an Entry. Display the journal - Iterate through all entries in the journal and display them to the screen. Save the journal to a file - Prompt the user for a filename and then save the current journal (the complete list of entries) to that file location. Load the journal from a file - Prompt the user for a filename and then load the journal (a complete list of entries) from that file. This should replace any entries currently stored the journal. Provide a menu that allows the user choose these options Your list of prompts must contain at least five different prompts.…arrow_forwardName SearchIn the Chap07 folder of the Student Sample Programs, you will find the followingfiles:• GirlNames.txt—This file contains a list of the 200 most popular names given to girls born in the United States from 2000 through 2009.• BoyNames.txt—This file contains a list of the 200 most popular names given to boys born in the United States from 2000 through 2009.Create an application that reads the contents of the two files into two separatearrays or Lists. The user should be able to enter a boy’s name, a girl’s name, orboth, and the application should display messages indicating whether the nameswere among the most populararrow_forward
- Command Program Create a program that allows you to view and edit the sales amounts for each month of the current year. This program is required to use commands add, view, totals, edit, and exit. The program should use a list to store the sales data for each month with the three-letter abbreviation for the month (Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, and Dec) to use as the key for each item. When the program starts, it should read the sales data inserted from the user. If the user edits the sales data, the program should edit the data If the user selects total, then the program should calculate the total sales and average monthly sales. Use functions to view sales, edit sales, calculate total, and calculate average. Please use all commands, and thank you in advance.arrow_forwardPython Programming Questionarrow_forwardC++HurdleWords The HurdleWords class is mostly provided to you. HurdleWords is constructed from two files in the data/ folder: ● valid_guesses.txt (all 5 letter guesses considered to be valid words to guess), and ● valid_hurdles.txt (all words that may be selected to be the secret Hurdle.) ● Note: you may edit both text files if you’d like to add custom words to your game. HurdleWords stores all potential valid Hurdles from valid_hurdles.txt into a vector of strings (valid_hurdles_), and all valid guesses from valid_guesses.txt into an unordered set of strings (valid_guesses_). A set is simply a data structure that contains no duplicates and allows for a speedy lookup to check if a given element exists within the set. Because there are over 10,000 valid guesses, we store them in an unordered set to leverage their speediness, as you will need to check if a user-submitted guess is considered valid (i.e. their guess is considered a valid guess in the dictionary). You are responsible for…arrow_forward
- Create a hand of cards using python code: - 52 cards are in the deck To create a hand of cards, first prompt the user for the number of cards to deal between 2 and 5. You must check the users input for the correct value. If the value is incorrect, tell the user, it is incorrect and ask for a new number. Take the number of cards entered by the user and from the deck of cards place those number of cards in the list called hand. Hint: use the pop command to take from the shuffled deck of cards and place into the hand list. Always make sure you have cards left in the deck of cards when creating a hand.arrow_forwardProgram Description:in C language The project is a student management system which maintains student records in a simple text file. Your task is to write a program to save a list of students records in a FILE and then perform several operations on this FILE. Your program will ask user to choose the option from a menu. The 3 major function in menu are: ADD STUDENT FIND STUDENT PRINT LIST Exit How it Works The menu is handled by do while and switch statement. Sample output The Methods to be implemented are as follows: 1. ADDSTUDENT This method will add a new student to the file. It takes 3 parameters ( student name, id, and GPA). Your program must ask the user to enter the details of new students: Name, ID and GPA 2. FINDSTUDENT This method will search for a student with his/her id in the file. If the student is found it will print her/his record to the output. If the student is not found it will print “There is no record of this student in this system” 3. PRINTLIST This method will…arrow_forwardLaboratory Exercise No. 40 Filename: Lab_exer40 You are tasked to create a program that will get the basic salary of 5 employees from the user and these 5 values should be saved in a list named as basicSalary. The user will then enter the incentive rate (Example. 0.15) The program should compute the net salary. The net salary is computed using the formula basic salary multiplied by incentive rate. Store the computed net salary in another list which will be named as net_salary. Display the values stored in the 2 lists. Example Output: Enter basic salary : 200 Enter basic salary : 300 Enter basic salary : 450 Enter basic salary : 600 Enter basic salary : 750 Enter incentive rate : 0.50 Basic salary [200,300,450,600,750] Net Salary [100,150,225,300,375]arrow_forward
- In Python, grades_dict = {'Wally': [87,96,70], 'Eva': [100,87,90], 'Sam': [94,77,90], 'Katie': [100,81,82], 'Bob': [83, 65, 85]} Ask user to enter the names of the rows, i.e., indices. You can use: len(grades) to get the number of rows of the DataFrame. In addition, using the sort_index() method, ask user whether they wish to sort by rows or by columns and whether to sort in ascending or descending order (do not use any if-else statements)arrow_forwardBanking Online Using mainly loops in Python Create a menu to allow the banker to add a client, insert the client into a special location in the list, closing the account(remove), find the client based on firstName, and sort the list in descending order (larger to smaller value). NewClient=["Mike navarro","Miguel saba","Maria Rami"] Balance= [900.00, 400.00, 450.00] You may use any of build in functions. Here is an sample output: 1- Add a new client 2- Remove a client 3- Insert an item to the list 4- Search for the client based on firstName 5-Search for the client based on lastName 6- Sort the list in descending order(firstName) 7- Quit the program Please enter your option: 3 Where do you want to insert the client? (Enter the index number) 1 Please enter the client info: "Tina Mari" Your original List : ["Mike navarro","Miguel saba","Maria Rami"] After inserting an item into index 1: ["Mike navarro","Tina Mari", "Miguel saba","Maria Rami"] Once the user enters an option, your…arrow_forwardIf you have downloaded the source code from this book’s companion Web site, you will find a file named USPopulation.txt in the Chapter 07 folder. The file contains the midyear population of the United States, in thousands, during the years 1950 through 1990. The first line in the file contains the population for 1950, the second line contains the population for 1951, and so forth.Write a program that reads the file’s contents into a list. The program should display the following data:• The average annual change in population during the time period• The year with the greatest increase in population during the time period• The year with the smallest increase in population during the time period(You can access the book’s companion Web site at www.pearsonglobaleditions.com/gaddis.)arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTProgramming with Microsoft Visual Basic 2017Computer ScienceISBN:9781337102124Author:Diane ZakPublisher:Cengage LearningProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781305480537Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:9781337102124
Author:Diane Zak
Publisher:Cengage Learning
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781305480537
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,