Skip to main content

SoloLearn Python Core: functions and modules quiz answer

 This is a quiz answer of module 4, Python Core course of SoloLearn mobile application. This is final quiz appear after module 4 functions and modules.

1. Fill in the blanks to define a function that takes two number as argument and returns smaller one.

Ans.

def min (x, y):
    if x <= y:
        return x
    else:
        return y

2. Rearrange the code to define a function that calculates the sum of all numbers from 0 to its argument.
Ans.

Def sum (x):
    res = 0
    for i in range (x):
    	res += i
    return res

3. How would you refer to the randint function if it was imported like this? 
from random import random as rnd_int.
Ans.

rnd_int

4.What is the highest number output by this code?

def print_nums(x):
	for i in range(x):
    	print(i)
        return 
print_nums(10)
Ans.
0

5.What is the output of this code?
def funct (x):
    res = 0
    for i in range(x):
        res += i
    return res
print (func(4))
Ans.
6

Comments