![]() Note a key point in python is everything is an object. ![]() | Base 0 means to interpret the base from the string as an integer literal. The literal can be preceded by ' ' or '-' and be surrounded | bytes, or bytearray instance representing an integer literal in the | If x is not a number or if base is given, then x must be a string, | Convert a number or string to an integer, or return 0 if no arguments Notice from the documentation, for int the expected parameter is an object. When defining and giving two parameters with one argument I get "TypeError: div_calc() missing 1 required positional argument: 'userInput2'" I wasn't able to get the function to throw the exception when defining and giving only a single parameter and argument, as it continues on to ask for the second input, which results in one of the aforementioned Error as e exceptions. a number outside expected boundaries) should result in a ValueErrorLinks to an external site.įurthermore, when I attempted to define the code as a function and the inputs as arguments.įeeding the function "m" for either of (or both) parameters throws Exception as e referencing "Unknown Error: unsupported operand type(s) for /: 'str' and 'int'" (or. is expected) should result in a TypeErrorLinks to an external site., but passing arguments with the wrong value (e.g. Passing arguments of the wrong type (e.g. Why does entering "m" in scenario 1 trip a ValueError instead of a TypeError?Īccording to the official Python v3.11.3 documentation: My question as it was posted on the course's Canvas board: Print("\'Exception as e\' caused by \'myFile = open(\"missing.txt\", \'r\')\' when \n no such file exists.") Num2 = int(input("Please enter another Integer: ")) Num1 = int(input("Please enter an Integer: ")) # Could not trigger as function, so "m" has to be entered manually on prompt # num2 = int(input("Please enter another Integer: ")) # num1 = int(input("Please enter an Integer: ")) Here's the code I wrote for the exercise: def div_calc(num1, num2): Print("Error: You did not enter a number") UserInput2 = int(input("Please enter another Integer:")) UserInput1 = int(input("Please enter an Integer:")) Then explain why you have Unknown error at the end of the output ![]() Generate correct output for following code.Ģ.Try 12 for the first number then 0 for the second numberģ.Try 12 for the first number then 3 for the second number. Here's the assignment prompt: In-Class Exercise on Exceptions I had originally posted this question onto the course's Canvas discussion board, but there hasn't been a single reply (not even from the professor), so I've decided to post it up here to see if it'll fare better. This is regarding an Intro to Python academic course exercise on expections.
0 Comments
Leave a Reply. |