0% found this document useful (0 votes)
6 views5 pages

PS Week 4

Uploaded by

onurleb
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)
6 views5 pages

PS Week 4

Uploaded by

onurleb
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/ 5

INTRODUCTION TO PROGRAMMING

STUDY QUESTIONS (WEEK 4)

Q1. Create a function, which counts and prints down from given number (as an input) to
0. Then it counts and prints from zero to given number.

Q2. The function below finds the summation of all numbers between 0 and 10. Try to
figure out the errors.

def summation():
for i in range(9):
sum=0

sum +=1
print sum

Q3. Write a function print_even() that takes two even numbers as input and prints the all
even numbers between these numbers. (write it with for and while loop) For example:

print_even(12,18)
14
16
Q4. What is the output of the following operations?

 a=4

 b=6

 c=4

 print(a = 2)

 print(b > 2)

 print(a >= c)

 print(a > b)

 print(b < a)

 print(a = b)

 print(a <= c)

 print(a != b)

 print(a =< c)

Q5. Write a function that takes a negative number and prints all the negative numbers
from 0 until that number. For example:

negatives(-10)
0

-1
-2
-3
-4
-5
-6
-7
-8
-9
-10
Q6. Write a function that prints the following when called.
10

20
30
40
50
60
70
80
90
100

Q7. Write a function that takes 2 numbers and prints from the smaller number till the
bigger one. You may use max(), min() built in functions. Hint: use for loop. For example: if
the input is func(1,6), the output should be:
1
2
3
4
5
6

Q8. What is the output of the following code?

for I in range(-1,-10,1):
print(i)

Q9. Is there a way to fix this code? What does it output?


a == 2
for I in range(a):
print(a = 2)
Q10. Create a function which draws the figure below

Q11. Create a function draws the figure below.


Q12. Create a function which draws the figures below.

Q13. Create a function which draws the figure below several times.

You might also like