Test Index
Functions in Python
© examsnet.com
Question : 19 of 23
Marks:
+1,
-0
Predict the output of the following code :
def Total (Num=10): Sum=0 for C in range(1,Num+1): if C%2!=0: continue Sum+=C return Sumprint(Total(4),end="$")print(Total(),sep="@")
[CBSE 2024 Compartment]
Solution:
Concept:The function adds only the even numbers from 1 to Num: for an odd C,
continue skips the addition. end="$" prints $ instead of a newline; sep matters only between several values, so with one value it has no effect.Explanation:Total(4): even numbers 2, 4, Sum = 6. Printed as 6$ (no newline).Total(): Num = 10 (default), even numbers 2, 4, 6, 8, 10, Sum = 30. Printed right after the $.Output:6$30
© examsnet.com
Go to Question: