1.

Q11. Identify the errors in the following program code: # Program to print sum of three numbers whose values are 10, 12 and 15num l=10num2=12num3=15sum = num l-unum2 +num3;print 'sum​

Answer»

ource code:num 1 = 10num2 = 12num3 = 15sum = num 1 - unum2 + num3;PRINT 'sum​Correct code:num1 = 10num2 = 12num3 = 15sum = num1 + num2 + num3;print(sum)Corrections and reasons:num1 = 10      VARIABLE names cannot contain special characters other than underscores (_).num2 = 12   #no correctionnum3 = 15   #no correctionsum = num1 + num2 + num3;The objective was to obtain the sum of all the numbers added together. You would need to change the first SIGN from (-) to (+).The second variable was also named as (num2) and not as (unum2). Wrong variables can lead to Name Errors.print(sum)SYNTAX error: print STATEMENTS need to be enclosed within brackets.



Discussion

No Comment Found