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

Python Exercises-Iterations

The document provides 31 Python exercises involving iterations, conditionals, pattern printing, number operations, and prime factorization. The exercises cover concepts like loops, input/output, arithmetic operations, string manipulation, and mathematical functions.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views

Python Exercises-Iterations

The document provides 31 Python exercises involving iterations, conditionals, pattern printing, number operations, and prime factorization. The exercises cover concepts like loops, input/output, arithmetic operations, string manipulation, and mathematical functions.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

IGCSE Computer Science

Python Exercises Worksheet (Iterations)

Write Python code to do the following:

1. Print your name 5 times.


2. Print numbers from 1 to 10.
3. Print numbers from 1 to 10 in reverse order.
4. Print the first 10 multiples of 9 in reverse order.
5. Print the first ‘n’ odd/even numbers.
6. Print the odd/even numbers up to ‘n’.
7. Print the complete multiplication table, up to 10, of given number.
Ex:- if given number is 6, then output should be

6x1=6
6 x 2 = 12
.
.
.
.
6 x 10 = 60

8. Accept ‘n’ numbers from the user and display whether each number is odd or even.
9. Find the sum of first ‘n’ numbers.
10. Accept ‘n’ numbers and display their sum.
11. Accept ‘n’ numbers and display how many positive numbers, negative numbers or zeroes were entered.
12. Accept a maximum of 15 numbers or till the user enters ‘0’ indicating the end. Add up all the numbers divisible
by 4 and display the result.
13. Accept a number and display whether it is a prime number or not.
14. Accept a number and display the number of digits in it.
15. Find the sum of digits of a number.
16. Reverse a number.
17. Check if given number is palindrome or not.
18. Print the Fibonacci series (first ‘n’ terms)
19. Check if given number is an Armstrong number or not.
20. Find the factorial of given number.
21. Accept two numbers and find the value of one number raised to the power of another. (a b)
22. Accept a number and display it’s binary, hexadecimal and octal equivalent.
23. Accept a binary number and display its decimal equivalent.
24. Accept a hexa-decimal number and display its decimal equivalent.
25. Accept an octal number and display its decimal equivalent.
26. Accept a number from the user and print the following pattern. (Assume number entered is 3)

0 3
1 2
2 1
3 0

27. Print the following patterns

* * 1 1 1
** ** 12 22 23
*** *** 123 333 456
**** ** 1234 4444 7 8 9 10
***** * 12345 55555

28. Print the following multiplication table:

29. Print the truth tables of AND, OR and NOT gates without using IF statements.
30. Evaluate the series:
3 5 7
x x x
sin (x) = x - + - + ………..
3! 5! 7!

31. Accept a positive integer and display the prime factors of the number.

You might also like