How to make a for,array,and range functions

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By !Prince

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

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

if foo > 0:
     # Do stuff here.

Ertain | 2020-12-18 17:53

:bust_in_silhouette: Reply From: Thomas Karcher

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))