Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Problem 1 Write code that asks a user for a number, assigns the input to a variable called tot and attempts to convert tot to
Problem 1 Write code that asks a user for a number, assigns the input to a variable called tot and attempts to convert tot to an integer. If the conversion fails, print a message that reads "tot cannot be converted to an integer.". Note: Replace tot with the user's actual input in the message. Problem 2 Building on your code from the previous problem, if tot is successfully converted to an integer, determine whether tot is even or odd. If tot is even, print a message that reads "tot is an even number.". Otherwise, print a message that reads, "tot is an odd number.". Note: Replace tot with the user's actual input in the message. Problem 3 Write code that asks a user for two numbers, assigns the inputs to the variables x and y, and attempts to convert x and y into floating point numbers. If the conversion fails, print a message that reads, "One or both of your inputs could not be converted to a floating point number.". Otherwise, proceed as follows: if x is greater than y, print a message that reads, " x is larger than y." if x is less than y, print a message that reads, " x is smaller than y." if x is equal to y, print a message that reads, "x is equal to y." Note: Replace x and y with the user's actual inputs in the message. Problem 4 Building on your solution to the previous problem, have your code print a thank you message to the user, regardless of whether the conversion failed or succeeded. Problem 5 Building on your solution to the previous problem, instead of comparing x to y, modify your code to divide x by y and assign the result to variable called z (only if the type conversion succeeds). If the division succeeds, print a message that reads "x divided by y equals z.". Otherwise, print a message that reads, " x cannot be divided by y
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started