0% found this document useful (0 votes)
15 views6 pages

Python Practicals - Compressed

The document contains 3 programming problems and their solutions: 1. A program that accepts two integers and prints if the first is divisible by the second. 2. A program that checks if a 10 digit phone number is in a valid format of xxx-xxx-xxxx. 3. A program using a dictionary to store months and days, and prints the days for a given month, months alphabetically, months with 31 days, and months sorted by number of days.

Uploaded by

lomir76956
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)
15 views6 pages

Python Practicals - Compressed

The document contains 3 programming problems and their solutions: 1. A program that accepts two integers and prints if the first is divisible by the second. 2. A program that checks if a 10 digit phone number is in a valid format of xxx-xxx-xxxx. 3. A program using a dictionary to store months and days, and prints the days for a given month, months alphabetically, months with 31 days, and months sorted by number of days.

Uploaded by

lomir76956
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

Practical-1

Design Develop and implement a python program that accepts two integers from the user and
print a message saying if first number is divisible by second number or if it is not.

Solution:

a = int(input("Enter first number:"))

b = int(input("Enter second number:"))

if a % b == 0:

print(a, "is divisible by", b)

else:

print(a, "is not divisible by", b)

Output:

1
Practical -2
Design, Develop and implement a program that prompts for a phone number of 10 digit and
two dashes, with dashes after the area code and the next three number, display if the phone
number enter is valid format or not and display if the phone number is valid or not.

Solution:

number = input("Enter your Phone number :- ")

if len(number)== 12 :

if number[3]== "-" and number [7]== "-":

if( number[ : 3 ]+ number[4:7]+ number[ 8 : ]).isdigit():

print("Number is valid")

else:

print("Number is Invalid")

Output:

2
Practical -3
Create a dictionary whose keys are month name and whose values are number of days in the
corresponding month :
a. ask the user to enter the month name and use the dictionary to tell how many days are in
month .
b. print out all of the keys in alphabetical order .
c. print out all of the month with 31 days
d. print out the (key - value) pair sorted by the number of the days in each month .

Solution:

a.

month = { "jan" : 31 , "feb" : 28 , "march" : 31 , "april" : 30 , "may" : 31 , "june" : 30 , "july" :


31 , "aug" : 31 , "sept" : 30 , "oct" : 31 , "nov" : 30 , "dec" : 31}

mon = input("Enter the month name :- ")

print("Number of days in ",mon,"=",month [ mon ])

b.

month = { "jan" : 31 , "feb" : 28 , "march" : 31 , "april" : 30 , "may" : 31 , "june" : 30 , "july"


: 31 , "aug" : 31 , "sept" : 30 , "oct" : 31 , "nov" : 30 , "dec" : 31}

lst = list ( month.keys() )

lst.sort()

print( lst )

c.

month = { "jan" : 31 , "feb" : 28 , "march" : 31 , "april" : 30 , "may" : 31 , "june" : 30 , "july"


: 31 , "aug" : 31 , "sept" : 30 , "oct" : 31 , "nov" : 30 , "dec" : 31}

'''print( "Month which have 31 days !!-- ")

for i in month :

3
if month [ i ] == 31 :

print( i )

d.

month = { "jan" : 31 , "feb" : 28 , "march" : 31 , "april" : 30 , "may" : 31 , "june" : 30 , "july"


: 31 , "aug" : 31 , "sept" : 30 , "oct" : 31 , "nov" : 30 , "dec" : 31}

print("Month according to number of days --")

print("feb")

for i in month :

if month [ i ] == 30 :

print(i)

for i in month :

if month [ i ] == 31 :

print( i)

Output:

a.

4
b.

c.

d.

5
6

You might also like