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
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 "sartresults.txt
Write a python program that reads the contents of a text file and implements error handling using tryexceptfinally 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.
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 eg Split user input using strsplit, and check whether the resulting list is valid:
If the input does not consist of elements, raise a FormulaError, which is a custom Exception. Try to convert the first and third input to a float like so:
floatvalue floatstrvalue 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
Write a python program that Define a function capitalizelastname 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 strsplit 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.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
