-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExercise3.txt
43 lines (37 loc) · 1.36 KB
/
Exercise3.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
-------------------------
Exercises
-------------------------
Loops and Conditionals
----------------------
# Solve the following using either while/do while loops
1) Take a number from the user and print sum from 1 to that number
2) Take a number from the user and print all prime numbers from 1 to that number
pseudo code :
--------------
accept input from the user
loop from 1 to that number
is_prime(loop_iteration_number) which will return
the true if the loop_iteration_number is a prime number
Based on the return value determine if you need to print the
loop_iteration_number
def is_prime(input_number):
loop from 2 to that input_number/2
if the input_number is divisible by the current loop counter
terminate the loop and return false
return true
3) Take a number from the user and print all Odd numbers from 1 to that number
4) Take a number from the user and print all Even numbers from 1 to that number
5) Take a number from the user and print fibonacci sequence till that number
eg : fibonnaci sequence for 5 is 0,1,1,2,3,5
Test cases :
1) input_number = 13 output = 0 1 1 2 3 5 8 13
2) input_number = 15 output = 0 1 1 2 3 5 8 13
3) input_number = 1 output = 0 1 1
4) input_number = 0 output = 0
-----------
Assignment:
-----------
-----------
Assignment:
-----------
https://pynative.com/python-if-else-and-for-loop-exercise-with-solutions/