Question: PYTHON Program- Format the code properly and take as screenshot of formatted code. Take a screenshot of output as well. I keep on getting errors
PYTHON Program- Format the code properly and take as screenshot of formatted code. Take a screenshot of output as well. I keep on getting errors b/c of format. The outputs should look like this:

The source code for this is :
# Taking two integers from the user num1 = input("The first number is: ") num2 = input("The second number is: ") # Converting them to strings and extracting the length of the each integers num1len = len(str(num1)) num2len = len(str(num2)) # Validating the length of first integer if (num1len != 3): print(num1, " is not a 3 digit integer"); exit() # exit from the script if not a valid integer # Validating the length of second integer if (num2len != 3): print(num2, " is not a 3 digit integer"); exit() # exit from the script if not a valid integer # Calculating product of two integers product = num1 * num2 # Extracting the length of the product for printing purpose productLen = len(str(product)) # Identifying the printing format based on the width of the product printFormat1 = '%' + str(productLen) + 's' printFormat2 = 'x%' + str(productLen-1) + 's' # Printing mutliplication with proper indentation print(printFormat1 % num1) #printing first num print(printFormat2 % num2) #printing second num # Printing the separator line print('_' * productLen) print(printFormat1 % product) #printing product # Calculating remainder and quotient values remainder = num1 % num2 quotient = num1um2 # Converting quotient into string for printing purposes qustr = str(quotient) # Setting format for printing first line in multiplication printFormat1 = '%' + str(productLen + 2) + 's' # Printing first line in division print(printFormat1 % qustr + ' R ' + str(remainder)) # Setting format for printing first line in division printFormat2 = (('%' + str(productLen + productLen/2 - 1 ) + 's')) # Printing the separator line print((printFormat2 % ((productLen-1) * '_')) # Printing last line in division print(str(num2) + ') ' + '%3s' % num1) # Opening a file to write output outputFile = open("results.txt", "w"); # Writing output to the file outputFile.write(str(num1) + " times " + str(num2) + " is " + str(product) + ", and "\ + str(num1) + " divided by " + str(num2) + " is " + str(quotient)\ + " remainder " + str(remainder) + ". "); # Closing output file outputFile.close(); Output-ScreenShot k@ashok-Aspire-E1-571G: /Desktop/Chegg ashok@ashok-Aspire-E1-571G:~/Desktop/Chegg$ python -version Python 2.7.6 ashok@ashok-Aspire-E1-571G:~/Desktop/Cheggs python numop.py The first number is: 739 The second number is: 212 739 x 212 156668 3 R 103 212) 739 ashok@ashok-Aspire-E1-571G:~/Desktop/Cheggs cat results.txt 739 tines 212 is 156668, and 739 divided by 212 is 3 remainder 103 ashok@ashok-Aspire-E1-571G:-/Desktop/Cheggs python numop.py The first number is: 999 The second number is: 999 x 999 998001 999) 999 ashok@ashok-Aspire-E1-571G:-/Desktop/Cheggs cat results.txt 999 tines 999 is 998001, and 999 divided by 999 is 1 remainder ashok@ashok-Aspire-E1-571G:-/Desktop/Cheggs Comment
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
