0 votes

Hello, I need help with an assignment my teacher gave me. I promise I will find out how to do this on my own, but right now I have little time before it's due. Below is the prompt.

create 4 functions

1 takes in 1 param(has to be a positive #), and will print out the value from 0 to that number

2 take 2 params, the second bigger than the first, print the range between them

3 receives a list of numbers and prints them out in reverse order

4 take in one param( both +/-), print out the odd numbers from 0 to that number

Godot version 3.0
in Engine by (12 points)

You can check the value of the parameters by a comparison operation, e.g.

if foo > 0:
     # Do stuff here.

1 Answer

0 votes

Please be aware that your teacher will most likely notice this wasn't done by a beginner:

func test():
    f1 (7)          # output: 0 1 2 3 4 5 6 7
    f2 (3,9)        # output: 4 5 6 7 8 
    f3 ([2,4,6,8])  # output: 8 6 4 2
    f4 (-5)         # output: -1 -3 -5

func f1(n):
    for i in range (0, n + 1): print (i)

func f2(n1, n2):
    for i in range (n1 + 1, n2): print (i)

func f3(n):
    for i in range (n.size(), 0, -1): print (n[i - 1])

func f4(n):
    for i in range (1, (abs(n) + 1), 2): print (i * sign(n))
by (1,742 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.