Question: For this problem, you are given a piece of code that has several bugs. Your task is to identify and correct these bugs to make
For this problem, you are given a piece of code that has several bugs. Your
task is to identify and correct these bugs to make the program work as
intended.
a The code is supposed to calculate the product and quotient of two
numbers put in by the user. Here is the buggy code:
# Get two numbers from the user
num input Enter the first number:
num input Enter the second number:
# Perform multiplication
result num num
printThe product of the numbers is: result
# Perform division, if possible
if num :
result num : num
print "The division of the numbers is: result"
else:
printDivision not possible: Cannot divide by
b Enter that code into your IDE and run it to test and then debug it
You will find several bugs.
c When you find a bug, fix it and leave a comment for each bug you
squash and explain what was wrong with it State whether it is a
syntax, runtime, or logic error. Place each comment on its own line
directly above the line that had the bug in it
d After debugging, the code should:
i Ask the user to input two numbers, represented by num
and num
ii Print the product of the two numbers.
iii. Print the quotient of the two numbers if the division is a legal
operation. Otherwise, it should print a message saying that
you cannot divide by
e Below are some test cases that your program output should match.
But your code should work with any combination of numbers put in
by the user.
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
