Q. What are the errors in following codes? Correct the code and predict output:
(a)
total = 0 ;
def sum( arg1, arg2 ):
total = arg1 + arg2 ;
print("Total :", total)
return total ;
sum( 10, 20 ) ;
print("Total :", total)
(b)
def Tot (Number) #Method to find Total
Sum = 0
for C in Range (1, Number + 1):
Sum += C
RETURN Sum
print (Tot[3]) #Function Calls
print (Tot[6])
Answer =
(i) In line 3 & 4 there should be double indentation.
total = 0 def sum( arg1, arg2 ): total = arg1 + arg2 print("Total :", total) return total sum( 10, 20 ) print("Total :", total)
Output:-
Total : 30
Total : 0
(ii) In line 5 "RETURN" should be in small words and also there is only one indentation.
def Tot (Number): #Method to find Total Sum = 0 for C in range (1, Number + 1): Sum += C return Sum print (Tot(3)) #Function Calls print (Tot(6))
Output:-
6
21
What a solution
ReplyDeleteThankyou : )
DeletePlease explin also
DeleteThankyou So much..
ReplyDelete◉‿◉AWESOME SOLUTION
Welcome : )
DeleteThank you for such a clear explanation.!
ReplyDeleteWelcome 😊😊😊
Deletethnks bro
ReplyDeleteyou r welcome
DeleteWelcome : )
DeleteOk
ReplyDelete: )
Delete1st question is from which book
ReplyDeleteSumita Arora
Delete(a) for a part there should be no indent in line 2. there should be no semicolons in line 1 ,3,5 and 6.
ReplyDelete(b) it cant accept a list as argument because it is used in range function. and RETURN.
Please run the code.
DeleteThank yu
ReplyDelete〰️
DeleteWelcome : )
Deleteʕಠ_ಠʔ
ReplyDelete╰(*°▽°*)╯
DeleteNot understood the (b) part
ReplyDeletePlease copy the code and run it in your IDLE Python.
DeletePost a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )