Starting Out with Python (4th Edition)
4th Edition
ISBN: 9780134444321
Author: Tony Gaddis
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Chapter 6, Problem 9AW
Program Plan Intro
The following algorithm is used to display the exception that occurs in the code:
- • Initially, declare the “try” suite.
- • Declare the “float” function and pass the argument “abc123” into the function; then, initialize it to the variable “x”.
- ○ If exception does not occur in the “try” suite, then it displays that print statement.
- • Declare an exception named “IOError” to handle the non-existing files that may occur in the “try” suite.
- ○ Display a specified “IOError” except clause statement on the screen when “IOError” occurs in the “try” suite.
- • Declare an exception named “ValueError” to handle the non-numeric data passed as an argument in the “float” function that may occur in the “try” suite.
- ○ Display a specified “ValueError” except clause statement on the screen when “ValueError” occurs in the “try” suite.
- • Display the “end” statement after exception handled in a code.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
switch_player(): we will allow the players to choose their own names, but for our purposes, it is easier to think of them as number (0 and 1, for indexing purposes). We will display their names to them on the screen, but in the background, we will keep track of them based on their number. This function should take 1 argument, an integer (either 0 or 1) representing the player and should return the opposite integer (1 if 0 is entered and 0 if 1 is entered). This is a simple function, but it will make our code cleaner later. Use your constants!
Using Thonny
X609: Magic Date
A magic date is one when written in the following format, the month times the date equals the year e.g. 6/10/60. Write code that
figures out if a user entered date is a magic date. The dates must be between 1 - 31, inclusive and the months between 1 - 12,
inclusive. Let the user know whether they entered a magic date. If the input parameters are not valid, return false.
Examples:
magicDate(6, 10, 60) -> true
magicDate(50, 12, 600) –> false
ang = (z1+z2).argument(); //Put a comment here explaining what happened and why?
Chapter 6 Solutions
Starting Out with Python (4th Edition)
Ch. 6.1 - What is an output file?Ch. 6.1 - What is an input file?Ch. 6.1 - What three steps must be taken by a program when...Ch. 6.1 - Prob. 4CPCh. 6.1 - Prob. 5CPCh. 6.1 - When writing a program that performs an operation...Ch. 6.1 - If a file already exists, what happens to it if...Ch. 6.1 - What is the purpose of opening a file?Ch. 6.1 - What is the purpose of closing a file?Ch. 6.1 - Prob. 10CP
Ch. 6.1 - In what mode do you open a file if you want to...Ch. 6.2 - Write a short program that uses a for loop to...Ch. 6.2 - Prob. 13CPCh. 6.2 - Assume the file data.txt exists and contains...Ch. 6.2 - Prob. 15CPCh. 6.3 - Prob. 16CPCh. 6.3 - Prob. 17CPCh. 6.3 - Prob. 18CPCh. 6.4 - Prob. 19CPCh. 6.4 - Prob. 20CPCh. 6.4 - What type of exception does a program raise when...Ch. 6.4 - Prob. 22CPCh. 6 - A file that data is written to is known as...Ch. 6 - A file that data is written to is known as...Ch. 6 - Before a file can be used by a program, it must be...Ch. 6 - When a program is finished using a file, it should...Ch. 6 - The contents of this type of file can be viewed in...Ch. 6 - This type of file contains data that has not been...Ch. 6 - When working with this type of file, you access...Ch. 6 - When working with this type of file, you can jump...Ch. 6 - This is a small holding section" in memory that...Ch. 6 - This marks the location of the next item that will...Ch. 6 - When a file is opened in this mode, data will be...Ch. 6 - This is a single piece of data within a record. a....Ch. 6 - Prob. 13MCCh. 6 - Prob. 14MCCh. 6 - Prob. 15MCCh. 6 - When working with a sequential access file, you...Ch. 6 - When you open a file that file already exists on...Ch. 6 - The process of opening a file is only necessary...Ch. 6 - Prob. 4TFCh. 6 - When a file that already exists is opened in...Ch. 6 - Prob. 6TFCh. 6 - You can have more than one except clause in a...Ch. 6 - Prob. 8TFCh. 6 - Prob. 9TFCh. 6 - Describe the three steps that must be taken when a...Ch. 6 - Why should a program close a file when it's...Ch. 6 - What is a read position? where is the read...Ch. 6 - If an existing file is opened in append mode, What...Ch. 6 - If a file does not exist and a program attempts to...Ch. 6 - Write a program that opens an output file with the...Ch. 6 - Write a program that opens the my_name.txt file...Ch. 6 - Write code that does the following: opens an...Ch. 6 - Prob. 4AWCh. 6 - Modify the code that you wrote in problem 4 so it...Ch. 6 - Write code that opens an output file with the...Ch. 6 - A file exists on the disk named students. txt. The...Ch. 6 - A file exists on the disk named students txt. The...Ch. 6 - Prob. 9AWCh. 6 - Prob. 10AWCh. 6 - File Display Assume a file containing a series of...Ch. 6 - File Head Display Write a program that asks the...Ch. 6 - Line Numbers Write a program that asks the user...Ch. 6 - Item Counter Assume a file containing a series of...Ch. 6 - Sum of Numbers Assume a file containing a series...Ch. 6 - Average of Numbers Assume a file containing a...Ch. 6 - Random Number File Writer Write a program that...Ch. 6 - Random Number File Reader This exercise assumes...Ch. 6 - Prob. 9PECh. 6 - Golf Scores The Springfork Amateur Golf Club has a...Ch. 6 - Personal Web Page Generator Write a program that...Ch. 6 - Average Steps Taken A Personal Fitness Tracker is...
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- 3. Write the proper code that responds to the following events handlers: Control Event Action btnRead Click -Read an integer that represent the month -Determine the number of days in the month: Month Number of days 1 31 2 29 3 31 4 30 31 30 7 31 8 31 9 30 10 31 11 30 12 31 - Declare an array to hold the sales of each day in the month - Read the sales of each day in the month using an inputBox and a loop of your preference - Record the sales the array - Compute the summation (using a loop of preference) and average of the sales - Display the summation and average in IstReport your btnClear ClicClear the input and output btnClose ClickpDisplay a messageBox with "Thanks" as title and "Thank you for using the App" -Close the formarrow_forwardgetRandomLib.h: // This library provides a few helpful functions to return random values// * getRandomInt() - returns a random integer between min and max values// * getRandomFraction() - returns a random float between 0 and 1// * getRandomFloat() - returns a random float between min and max values// * getRandomDouble() - returns a random double between min and max values// * getRandomBool() - returns a random bool value (true or false)// * getRandomUpper() - returns a random char between 'A' and 'Z', or between min/max values// * getRandomLower() - returns a random char between 'a' and 'z', or between min/max values// * getRandomAlpha() - returns a random char between 'A' and 'Z' or 'a' and 'z'// * getRandomDigit() - returns a random char between '0' and '9', or between min/max values// * getRandomChar() - returns a random printable char//// Trey Herschede, 7/31/2019 #ifndef GET_RANDOM_LIB_H#define GET_RANDOM_LIB_H #include <cstdlib>#include <random>#include…arrow_forwardA Java Practical Assignments.pdf - Adobe Acrobat Pro DC (32-bit) File Edit View E-Sign Window Help Home Tools Java Practical Assig. x Sign In 1 /1 139% Java Practical Assignments 1. Write an application that throws and catches an ArithmeticException when you attempt to take the square root of a negative value. Prompt the user for an input value and try the Math.sqrt() method on it. The application either displays the square root or catches the thrown Exception and displays an appropriate message. 2. Create a program that allows a user to input customer records (ID number, first name, last name, and balance owed) and save each record to a file. 3. Write an application for Limpopo's Car Care Shop that shows a user a list of available services: oil change, tire rotation, battery check, or brake inspection. Allow the user to enter a string that corresponds to one of the options, and display the option and its price as R250, R220, R150, or R50, accordingly. Display an error message if the…arrow_forward
- Find the error in the following code: The following code was intended for inputting scores for 20 students. If an invalid value was input, the program should keep reminding the user to re-input till a valid value is input. //Create Scanner object Scanner myScanner = new Scanner(System.in); //Declare variables final int studentNumber = 20; int scores[] = new int[studentNumber]; //Use while loop to allow user keep trying till valid input while(true) { for(int i=0; i<scores.length; i++) { System.out.println("Score for student "+(i+1)); scores[i] = myScanner.nextInt(); if( 100 >= scores[i]>=0){ break; } //Otherwise continue the loop } // end for }//end whilearrow_forwardWrite an application that counts by five from 5 through 500 inclusive and that starts a new line after every multiple of 50 (50,100,150 and so on).Save the file as CountByAnything.javaarrow_forward3. Randomly generate a number in range [1, 12]. Map this number to a season: if the number is 3, 4, or 5, map it to “Spring", if the number is 6, 7, or 8, map it to "Summer", if the number is 9, 10, or 11, map it to "Fall", and if the number 12, 1, or 2, map it to "Winter". Display season namearrow_forward
- Compare userNumber with compareNumber and display 'Numbers are not equal' if the numbers are different. Then, display 'Variables are not identical' if the variables are not identical (not strictly equal). let compareNumber = 3; // Code will be tested with: 3, 8, 42let userNumber = '3'; // Code will be tested with: '3', 8, 'Hi'arrow_forwardCan you please fix the code ? see picture for error thank youarrow_forwardimagearrow_forward
- - Declare and create the following two Recipe objects then invoke the printRecipe method to print their info to the console: 1) Recipe name: Beef-Stuffed Peppers Preparation time: 55 minutes Servings: 4 Ingredients: 1 tablespoon olive oil 1 pound lean ground beef 1% cups water 1 (6 ounce) can tomato paste 4 green bell peppers, tops and seeds removed 2) Lemonade Preparation time: 15 minutes Servings: 10 Ingredients: Sugar Water Lemon juice Icearrow_forwardJAVA:arrow_forwardQ1: The local Driver's License Office has asked you to write a program that grades the writ- ten portion of the driver's license exam. The exam has 20 multiple choice questions. Here are the correct answers: 1. A 2. D 3. B 4. B 5. C 6. B 7. A 8. B 9. C 10. D 11. A 12. C 13. D 14. B 15. D 16. C 17. C 18. A 19. D 20. B Your program should store the correct answers shown above in an array. It should ask the user to enter the student's answers for each of the 20 questions, and the answers should be stored in another array. After the student's answers have been entered, the program should display a message indicating whether the student passed or failed the exam. (A student must correctly answer 15 of the 20 questions to pass the exam.) It should then display the total number of correctly answered questions, the total number of incorrectly answered questions, and a list showing the question numbers of the incorrectly answered questions. Input Validation: Only accept the letters A, B, C, or…arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning