Loops
Loops
https://pynative.com/python-if-else-and-for-loop-exercise-with-solutions/
https://holypython.com/intermediate-python-exercises/exercise-8-python-for-loop/
https://pythontutorials.eu/basic/loops/
https://pythonistaplanet.com/python-for-loop-examples/
[An editor is available at the bottom of the page to write and execute the
scripts.]
1. Write a Python program to find those numbers which are divisible by 7 and
multiple of 5, between 1500 and 2700 (both included). Go to the editor
Click me to see the sample solution
6. Write a Python program to count the number of even and odd numbers
from a series of numbers. Go to the editor
Sample numbers : numbers = (1, 2, 3, 4, 5, 6, 7, 8, 9)
Expected Output :
Number of even numbers : 5
Number of odd numbers : 4
Click me to see the sample solution
7. Write a Python program that prints each item and its corresponding type
from the following list.
Sample List : datalist = [1452, 11.23, 1+2j, True, 'w3resource', (0, -1), [5, 12],
{"class":'V', "section":'A'}]
Click me to see the sample solution
8. Write a Python program that prints all the numbers from 0 to 6 except 3 and
6.
Note : Use 'continue' statement.
Expected Output : 0 1 2 4 5
Click me to see the sample solution
10. Write a Python program which iterates the integers from 1 to 50. For
multiples of three print "Fizz" instead of the number and for the multiples of
five print "Buzz". For numbers which are multiples of both three and five print
"FizzBuzz".
Sample Output :
fizzbuzz
1
2
fizz
4
buzz
Click me to see the sample solution
11. Write a Python program which takes two digits m (row) and n (column) as
input and generates a two-dimensional array. The element value in the i-th
row and j-th column of the array should be i*j. Go to the editor
Note :
i = 0,1.., m-1
j = 0,1, n-1.
14. Write a Python program that accepts a string and calculate the number of
digits and letters. Go to the editor
Sample Data : Python 3.2
Expected Output :
Letters 6
Digits 2
16. Write a Python program to find numbers between 100 and 400 (both
included) where each digit of a number is an even number. The numbers
obtained should be printed in a comma-separated sequence. Go to the editor
Click me to see the sample solution
ooooooooooooooooo
ooooooooooooooooo
ooooooooooooooooo
oooo
oooo
oooo
ooooooooooooooooo
ooooooooooooooooo
ooooooooooooooooo
oooo
oooo
oooo
ooooooooooooooooo
ooooooooooooooooo
ooooooooooooooooo
Click me to see the sample solution
27. Write a Python program to print alphabet pattern 'T'. Go to the editor
Expected Output:
*****
*
*
*
*
*
*
Click me to see the sample solution
34. Write a Python program to sum of two given integers. However, if the sum
is between 15 to 20 it will return 20. Go to the editor
37. Write a Python program that reads two integers representing a month and
day and prints the season for that month and day. Go to the editor
Expected Output:
Input the month (e.g. January, February etc.): july
Input the day: 31
Season is autumn
Click me to see the sample solution
39. Write a Python program to display the sign of the Chinese Zodiac for given
year in which you were born. Go to the editor
Expected Output:
Input your birth year: 1973
Your Zodiac sign : Ox
Click me to see the sample solution
40. Write a Python program to find the median of three values. Go to the
editor
Expected Output:
Input first number: 15
Input second number: 26
Input third number: 29
The median is 26.0
Click me to see the sample solution
41. Write a Python program to get next day of a given date. Go to the editor
Expected Output:
Input a year: 2016
Input a month [1-12]: 08
Input a day [1-31]: 23
The next date is [yyyy-mm-dd] 2016-8-24
Click me to see the sample solution