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
What will the following code display?try:x = float('abc123')print(x)except IOError:print('This code caused an IOError.')except ZeroDivisionError:print('This code caused a ZeroDivisionError.')except:print('An error happened.')print('The end.')
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
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
- ang = (z1+z2).argument(); //Put a comment here explaining what happened and why?arrow_forwardWhat is wrong in the following code?try:# Some code here...except ArithmeticError:print("ArithmeticError")except ZeroDivisionError:print("ZeroDivisionError")print("Continue")arrow_forward3. 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_forward
- A 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_forward3. int x =9 ;display the address of the variable x? Answer:arrow_forwardFind 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_forward
- Write 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_forwardCompare 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_forward
- Can you please fix the code ? see picture for error thank youarrow_forwardJAVA:arrow_forwarddef getDimension(): row = int(input("Enter number of rows (between 4 and 10): ")) while row < 4 or row > 10: row = int(input("Invalid input! Enter number of rows (between 4 and 10): ")) column = int(input("Enter number of columns (between 4 and 10): ")) while column < 4 or column > 10: column = int(input("Invalid input! Enter number of columns (between 4 and 10): ")) return row, column def printBoard(board): for row in board: print("|", end="") for cell in row: if cell == "": print(" ", end="") else: print(cell, end="") print("|", end="") print() print("-" * (len(board[0]) * 2 + 1)) def dropToken(board, col, token): row = len(board) - 1 while row >= 0: if board[row][col] == "": board[row][col] = token return row row -= 1 return -1 def isValidLocation(board, col): return board[0][col] == "" def isTie(board):…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