Question: 1 . Write a Python program that prompts the user to enter a number, calculates its square root, and handles the ValueError exception by displaying

1. Write a Python program that prompts the user to enter a number, calculates its square root, and handles the
"ValueError" exception by displaying an appropriate error message when the user enters a negative number.
The program should also write the results to a file named "sart_results.txt".
2. Write a python program that reads the contents of a text file and implements error handling using try-except-finally block to handle exceptions such as "FileNotFoundError" and
"IOError". Print the contents of the file or display appropriate error messages
if any of these exceptions occur during file handling.
3. You're going to write an interactive calculator! User input is assumed to be a formula that consist of a number, an operator (at least + and -), and another number, separated by white space (e.g.1+1). Split user input using str.split, and check whether the resulting list is valid:
If the input does not consist of 3 elements, raise a FormulaError, which is a custom Exception. Try to convert the first and third input to a float (like so:
float_value = float(str_value)). Catch any ValueError that
occurs, and instead raise a FormulaError. If the second input is not '+' or'-', again raise a FormulaError. If the input is valid, perform the calculation and print out the result. The user is then prompted to provide new input, and so on, until the user enters quit. (Python Program)
4. Write a python program that Define a function capitalize_last_name() that accepts as argument a string with a (single) first and a (single) last name, and returns a string in which only the first letter of the first name is uppercase, whereas all letters of the last name are uppercase; in otherwords, 'marisa tomei' becomes 'Marisa TOMEI. (Tip: use str.split() to split a str into separate words.)
If something other than a str object is passed as an argument, the function should raise a TypeError. (Tip: you can use isistance) to check whether an object is of a particular type.) If the str does not consist of exactly two words, the function should raise a ValueError.
1 . Write a Python program that prompts the user

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!