Question

o Write a function that outputs even numbers less than the input number. • Function name should be evenprint. • A number is
o Write a function to find a factorial of given number. Function name should be factorial . An integer is given as input and
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Here is the completed code for this problem. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. Thanks

Note: Please maintain proper code spacing (indentation), just copy the code part and paste it in your compiler/IDE directly, no modifications required.

#code

''' returns a list of even numbers less than num'''
def evenprint(num):
    #creating an empty list
    evens=[]
    #setting up a loop that will start with i=2 and ends at num-1
    #increments by 2 in each iteration
    for i in range(2,num,2):
        #since we are only iterating through even numbers, we dont need to check
        #if i is even, simply appending i to evens list
        evens.append(i)
    #returning the list
    return evens

''' computes and returns the factorial of a number '''
#assuming number is always positive
def fac(number):
    #if number is either 0 or 1, returning 1
    if number==0 or number==1:
        return 1
    #starting at fact=1
    fact=1
    #looping from i=1 to i=num
    for i in range(1,number+1):
        #multiplying fac by i and storing in fact itself
        fact=fact*i
    #returning fact
    return fact

#testing both functions
print(evenprint(100))
print(fac(5))

#OUTPUT

[2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, 64 6

Add a comment
Know the answer?
Add Answer to:
o Write a function that outputs even numbers less than the input number. • Function name...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT