Python 3 – Extra Exercise 3 (If-Else, Loops)
Reference:
[Link]
[Link]
1. Write a Python program to find those numbers which are divisible by 7 and
multiple of 5, between 1500 and 1600 (both included).
Program
nl=[]
for x in range(1500, 1600):
#to be completed
print (','.join(nl))
Sample Output
1505,1540,1575
2. Write a Python program to construct the following pattern, using a nested for
loop.
Program
n=5;
for i in range(n):
#to be completed
for i in range(n,0,-1):
#to be completed
Sample Output
*
**
***
****
*****
****
***
**
*
3. Write a Python program that accepts a word from the user and reverse it.
Program
word = input("Input a word to reverse: ")
#to be completed
Sample Output
Input a word to reverse: ecruoser3w
w3resource
4. Write a Python program that accepts a string and calculate the number of
digits and letters.
[Link]()
This method returns true if all the characters in the string are alphabetic and there is at
least one character, false otherwise
[Link]()
This method returns true if all characters in the string are digits and there is at least one
character, false otherwise.
Program
s = input("Input a string")
d=l=0
#to be completed
print("Letters: ", l)
print("Digits: ", d)
Sample Output
Input a string W3resource
Letters: 9
Digits: 1
5. Write a Python program to check whether an alphabet is a vowel or
consonant.
l = input("Input a letter of the alphabet: ")
#to be completed
Sample Output
Case 1 (a,e,I,o,u):
Input a letter of the alphabet: u
u is a vowel.
Case 2 (y):
Input a letter of the alphabet: y
Sometimes letter y stand for vowel, sometimes stand for consonant.
Case 3 (b):
b is a consonant.
6. Write a Python program to convert month name to a number of days.
Case 1: If month input is (“February”)
Output “No. of days: 28/29 days”
Case 2: If month input is ("January", "March", "May", "July", "August", "October",
"December")
Output “No. of days: 31 days”
Case 3: if month input is ("April", "June", "September", "November")
Output “No. of days: 30 days”
Case 4: if month is not valid
Output “Wrong month name”
Program
print("List of months: January, February, March, April, May, June, July, August,
September, October, November, December")
month_name = input("Input the name of Month: ")
#to be completed
Sample Output
List of months: January, February, March, April, May, June, July, August, September,
October, November, December
Input the name of Month: April
No. of days: 30 days