slip test - functions error based
slip test - functions error based
2. total = 0; 2
def sum(arg1, arg2):
total = arg1 + arg2;
print("Total :", total)
return total;
sum(10, 20);
print("Total :", total)
Ans. total = 0
: def sum(arg1, arg2):
total = arg1 + arg2
print("Total :", total)
return total
sum(10, 20)
print("Total :", total)
Reason:
4. Rao has written a code to input a number and check whether it is prime or not. His code 2
is having errors. Rewrite the correct code and underline the corrections made.
def prime():
n=int(input("Enter number to check :: ")
for i in range (2, n//2):
if n%i=0:
print("Number is not prime \n")
break
else:
print("Number is prime \n’)
Ans.
:
5. Atharva is a Python programmer working on a program to find and return the maximum 2
value from the list. The code written below has syntactical errors. Rewrite the correct
code and underline the corrections made.
def max_num (L):
max=L(0)
for a in L :
if a > max
max=a
return max
Ans. def max_num(L):
: max = L[0] # Correction: used square brackets to access the first element.
for a in L:
if a > max: # Correction: added a colon at the end of the 'if' line.
max = a
return max