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

Workshop 5 (Python)

The document contains a series of Python programming exercises focused on conditional statements and loops. Each exercise provides a specific task, such as finding numbers divisible by 7 and 5, constructing patterns, reversing strings, counting letters and digits, checking vowels, and converting month names to days. Sample outputs are included for each task to illustrate expected results.

Uploaded by

khkoo
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 views

Workshop 5 (Python)

The document contains a series of Python programming exercises focused on conditional statements and loops. Each exercise provides a specific task, such as finding numbers divisible by 7 and 5, constructing patterns, reversing strings, counting letters and digits, checking vowels, and converting month names to days. Sample outputs are included for each task to illustrate expected results.

Uploaded by

khkoo
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/ 6

Python 3 – Extra Exercise 3 (If-Else, Loops)

Reference:
https://www.w3resource.com/python-exercises/python-conditional-statements-and-loop-
exercises.php

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.

str.isalpha()
This method returns true if all the characters in the string are alphabetic and there is at
least one character, false otherwise
str.isdigit()
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

You might also like