Question

In: Computer Science

What are the standard Python modules for handling standard output? How do you program reread data...

What are the standard Python modules for handling standard output?
How do you program reread data from standard input?
What happens when an exception is raised and the program does not handle it with a try/except statement?
What type of exception does a program raise when it tries to open a nonexistent file?
What type of exception does a program raise when it uses the float number to convert a non-numeric string to a number?
What important statement do you need to write in a program that uses the math module?

Solutions

Expert Solution

1.)

  • The output is usually written to standard output using print() method
  • There is yet another standard write() that an output to files, this method can be made to write to standard output using the reference to standard output file sys.stdout

2.)

  • The program can be made to read from standard input using input()
  • Alternatively, we can sys.stdin reference to refer to standard input.

Example:

for x in sys.stdline:

print(x)

  • the above example will read the inputs in standard input and print the data line by line

3.)

  • When an exception is thrown and the program does not handle it, the expception is shown in the interpreter and the program terminates

4.)

  • When we try to open a non existent file, the python interpreter throws a FileNotFoundError, with a message saying no such file or directory

5.)

  • If we try to convert a non-numberic to float, python interpreter throws a ValueError saying "could not convert string to float"

6.)

  • We need to write the import statement import math to use the math module

Related Solutions

Write the following Python script: Imagine you live in a world without modules in Python! No...
Write the following Python script: Imagine you live in a world without modules in Python! No numpy! No scipy! Write a Python script that defines a function called mat_mult() that takes two lists of lists as parameters and, when possible, returns a list of lists representing the matrix product of the two inputs. Your function should make sure the lists are of the appropriate size first - if not, your program should print “Invalid sizes” and return None. Note: it...
Write the following Python script: Imagine you live in a world without modules in Python! No...
Write the following Python script: Imagine you live in a world without modules in Python! No numpy! No scipy! Write a Python script that defines a function called mat_mult() that takes two lists of lists as parameters and, when possible, returns a list of lists representing the matrix product of the two inputs. Your function should make sure the lists are of the appropriate size first - if not, your program should print “Invalid sizes” and return None. Note: it...
How to do this in Python (using Lists): Create a python program that allows a user...
How to do this in Python (using Lists): Create a python program that allows a user to display, sort and update as needed a List of U.S States containing the State Capital and State Bird. You will need to embed the State data into your Python code. The user interface will allow the user to perform the following functions: 1. Display all U.S. States in Alphabetical order along with Capital and Bird 2. Search for a specific state and display...
Writing a Modular Program in Python In this lab, you add the input and output statements...
Writing a Modular Program in Python In this lab, you add the input and output statements to a partially completed Python program. When completed, the user should be able to enter a year, a month, and a day. The program then determines if the date is valid. Valid years are those that are greater than 0, valid months include the values 1 through 12, and valid days include the values 1 through 31. Instructions Notice that variables have been declared...
In this assignment, you are going to write a Python program to demonstrate the IPO (Input-Process-Output)...
In this assignment, you are going to write a Python program to demonstrate the IPO (Input-Process-Output) cycle that is the heart of many imperative programs used for processing large amount of data. Daisy is recently hired by a warehouse. One of her job is to keep track the items ordered by all the branches of the company. The company wants to automate the task using a computer program. Being a friend of Daisy, she knows you are a Computer Science...
Python uses indention in its program structures. How do you define the syntax of a language...
Python uses indention in its program structures. How do you define the syntax of a language construct that uses indention? Give an example to describe.
[PYTHON] How do you write a program that first gets a list of floating point numbers...
[PYTHON] How do you write a program that first gets a list of floating point numbers from input. The input begins with an integer indicating the number of numbers that follow. Then input all data values and store them in a list [PYTHON]
What data processing models would you prescribe for each of the following: handling airline reservations, handling...
What data processing models would you prescribe for each of the following: handling airline reservations, handling total sales by department for each day of operations, and measuring the quality of cookies coming off an assembly line?
In Python Find the errors, debug the program, and then execute to show the output. def...
In Python Find the errors, debug the program, and then execute to show the output. def main():     Calories1 = input( "How many calories are in the first food?")     Calories2 = input( "How many calories are in the first food?")     showCalories(calories1, calories2)    def showCalories():     print('The total calories you ate today', format(calories1 + calories2,'.2f'))
1. What does the following program do? 2. What output does the program produce? 3. Examine...
1. What does the following program do? 2. What output does the program produce? 3. Examine the program code carefully. Is the program functioning correctly? 4. If you do not think the program is working correctly, describe why? 5. Include one screenshot of the program's output. C++ PROGRAM: #include <iostream> #include <pthread.h> #include <stdlib.h> int count; void* myFunction(void* arg) { int actual_arg = *((int*) arg);    for(unsigned int i = 0; i < 10; ++i) { count++; std::cout << "Thread...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT