QnA - Functions

 Predict the output of the following code:

def CALLME(n1=1,n2=2):

    n1=n1*n2

    n2+=2

    print(n1,n2)

CALLME()

CALLME(3)


Find the output:

p=5

def sum(q, r=2):

    global p

    p = r + Q**2

    print(p, end="#")

a=10

b=5

sum(a,b)

sum(r=5, q=1)

Raman has written a code to find its sum of digits of a given number passed as parameter to function sumdigits(n). His code is having errors. Rewrite the correct code and underline the corrections made.

def sumdigits(n):

    d=0

    for x in str(n):

        d=d+x

    return d

n=int(input('Enter any number"))

s=sumdigits(n)

print("Sum of digits",s)



Find the output: 


def Display(str):

    m=""

    for i in range(0,len(str)):

        if(str[i].isupper()):

            m=m+str[i].lower()

        elif str[i].islower():

            m=m+str[i].upper()

        else:

            if i%2==0:

                m=m+str[i-1]

            else:

                m=m+"#"

    print(m)

Display('Fun@Python3.0')


Find the output:

def check(x,y):

    if x != Y:

        return x + 5

    else:

        return y +10

print(check(10,5))



Write a function listchange(Arr,n)in Python, which accepts a list Arr of numbers and n is an numeric value depicting length of the list. Modify the list so that all even numbers doubled and odd number multiply by 3

Sample Input Data of the list: Arr= [ 10,20,30,40,12,11], n=6

Output: Arr = [20,40,60,80,24,33]





No comments:

Post a Comment