I want to receive the return value of the function and display it on the screen, but it says none

Asked 2 years ago, Updated 2 years ago, 15 views

print ("I will output a multiple of 7 from 1 to 100")
a = 0
def seven_cal (*args):
   global a
   result = [ ]
   for x  in range(1,101):
      a = 1
      a = a + 1
      if a %7 == 0:
           result.append(a)
           return result
           print(result)
seven_cal()

Now, the value of none is constantly displayed here. What's the problem?

python

2022-09-20 17:08

1 Answers

Given the state of the code, I've just started studying PythonRather than that, I needed something like this, so I roughly found it and made it.

Based on the code, it looks like you've compiled what you've looked up here and there.

You've compiled a code that doesn't fit at all.

If you've studied coding a little bit, you've organized the code in a way that you wouldn't have done, and if you want to solve it yourself, you'd better find something that can help you, whether it's on the Internet or in a book.

If you simply want to print that number every time you get a multiple of 7, the code should consist of:

print ("I will output a multiple of 7 from 1 to 100")
def seven_cal ():
    for a in range(1,101):
        if a %7 == 0:
            print(a)

seven_cal()

>> 7
14
21
28
35
42
49
56
63
70
77
84
91
98

If you want to output a composite of the results of finding a multiple of 7 in the function, construct the code in the following way:

print ("I will output a multiple of 7 from 1 to 100")
def seven_cal ():
    result = []
    for a in range(1,101):
        if a %7 == 0:
            result.append(a)
    return result

b = seven_cal()
print(b)

>> [7, 14, 21, 28, 35, 42, 49, 56, 63, 70, 77, 84, 91, 98]


2022-09-20 17:08

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.