This is my program when i return num_list it doesn't work but when i put print it work smoothly,

94 views Asked by At

This is my program when i return num_list it doesn't work but when i put print it work smoothly,my program and another friend program is exactly same but his program working and mine not.

import random

def make_random_real():
    num_list = []
    for i in range(0, 10):
        num_list.append(random.random())
    return num_list


make_random_real()
3

There are 3 answers

0
Sırrı Kırımlıoğlu On

In this version of the function, it just returns a value, so if you want to print it first you need to assign it to a variable like this:

result = make_random_real()

then you can print(result) which will show you the num_list in your function.

If you just want to print it without any assignment then just change return num_list to print num_list in your make_random_real() function.

0
Tomato Master On

The code is fine ,

only you are not able to view output because you are not printing the returned result from the function.

import random

def make_random_real():
    num_list = []
    for i in range(0, 10):
        num_list.append(random.random())
    return num_list


print(make_random_real())
0
opolikos On

Assign the return value of the function to a value, so that you can print.