0% found this document useful (0 votes)
21 views

Lab-3 Assignment Renas H. Darweesh

The document contains Renas H. Darweesh's solutions to 5 questions on an assignment involving recursion, loops, and conditionals. Question 1 defines a recursive function to print numbers from n to 0. Question 2 provides two ways to calculate powers: using a for loop and using recursion. Question 3 uses a for loop to print even numbers from 0 to 20. Question 4 uses a while loop to print odd numbers from 1 to 30. Question 5 uses a for loop to calculate the sum of numbers from 5 to 20.

Uploaded by

Renas Dareesh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views

Lab-3 Assignment Renas H. Darweesh

The document contains Renas H. Darweesh's solutions to 5 questions on an assignment involving recursion, loops, and conditionals. Question 1 defines a recursive function to print numbers from n to 0. Question 2 provides two ways to calculate powers: using a for loop and using recursion. Question 3 uses a for loop to print even numbers from 0 to 20. Question 4 uses a while loop to print odd numbers from 1 to 30. Question 5 uses a for loop to calculate the sum of numbers from 5 to 20.

Uploaded by

Renas Dareesh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Lab-3 Assignment Renas H.

Darweesh

Q1:
def foo(n):
print(n)
if n == 0:
return 0
else:
return foo (n - 1)

Q2:
Using For loop:
def Power(a,b):
power=1
for i in range (1, b+1):
power=power*a
print(power)
Using Recursion:
def Power (a, b):
if b==0:
return 1
else:
return a*Power (a, b-1)

Q3:
for x in range (0,20+1):
if x%2==0:
print(x)

1
Lab-3 Assignment Renas H. Darweesh

Q4:
def OddNum ():
x=1
while x in range (1,30):
if x%2==0:
x+=1
continue
else:
print(x)
x+=1
Q5:
def Sum5_20():
sum=0
for i in range(5,20):
sum+=i
print(sum)

You might also like