Civil-3rd Yr Sac Python Prog Syllabus r20
Civil-3rd Yr Sac Python Prog Syllabus r20
Website: www.sircrrengg.ac.in
SIR C.R.REDDY COLLEGE OF ENGINEERING
ELURU-534007, ELURU DIST, A P., INDIA
(Approved by AICTE, New Delhi )
Phone no: 08812-230840, 2300656 Fax: 08812-224193
Visit us at http://www.sircrrengg.ac.in
DEPARTMENT OF CIVIL ENGINEERING
The Department of Civil Engineering strives to graduate highly qualified engineers, maintain
nationally recognized research and provide quality professional and community service to the
society.
PSO3.Use different sophisticated software’s which helps to carry out research and
consultancy works.
PEO2.Analyse and design Civil engineering systems with social awareness and
responsibility.
SYLLABUS
List of Experiments:
1.)Write a program that asks the user for a weight in kilograms and converts it to pounds. There are
2.2 pounds in a kilogram.
2) Write a program that asks the user to enter three numbers (use three separate input statements).
Create variables called total and average that hold the sum and average of the three numbers and
print out the values of total and average.
3) Write a program that uses a for loop to print the numbers 8, 11, 14, 17, 20, . . . , 83, 86,89.
5) Use a for loop to print a triangle like the one below. Allow the user to specify how high the
triangle should be.
*
**
***
****
6) Generate a random number between 1 and 10. Ask the user to guess the number and print a
message based on whether they get it right or not.
7) Write a program that asks the user for two numbers and prints Close if the numbers are
within .001 of each other and Not close otherwise.
8) Write a program that asks the user to enter a word and prints out whether that word contains any
vowels.
9) Write a program that asks the user to enter two strings of the same length. The program should
then check to see if the strings are of the same length. If they are not, the program should print an
appropriate message and exit. If they are of the same length, the program should alternate the
characters of the two strings. For example, if the user enters abcde and ABCDE the program should
print out AaBbCcDdEe
10) Write a program that asks the user for a large integer and inserts commas into it according to the
standard American convention for commas in large numbers. For instance, if the user enters
1000000, the output should be1,000,000.
11) In algebraic expressions, the symbol for multiplication is often left out, as in 3x+4y or 3(x+5).
Computers prefer those expressions to include the multiplication symbol, like 3*x+4*y or 3*(x+5).
Write a program that asks the user for an algebraic expression and then inserts multiplication
symbols where appropriate.
12) Write a program that generates a list of 20 random numbers between 1 and100. (a) Print the list.
(b) Print the average of the elements in the list. (c) Print the largest and smallest values in the list.
(d) Print the second largest and second smallest entries in the list (e) Print how many even numbers
are in the list.
13) Write a program that asks the user for an integer and creates a list that consists of the factors of
that integer.
14) Write a program that generates 100 random integers that are either 0 or 1. Then find the longest
run of zeros, the largest number of zeros in a row. For instance, the longest run of zeros in
[1,0,1,1,0,0,0,0,1,0,0] is4.
15) Write a program that removes any repeated items from a list so that each item appears at most
once. For instance, the list [1,1,2,3,4,3,0,0] would become[1,2,3,4,0]
16) Write a program that asks the user to enter a length in feet. The program should then give the
user the option to convert from feet into inches, yards, miles, millimeters, centimeters, meters, or
kilometers. Say if the user enters a 1, then the program converts to inches, if they enter a 2, then the
program converts to yards, etc. While this can be done with if statements, itis much shorter with
lists and it is also easier to add new conversions if you use lists.
17) Write a function called sum_digits that is given an integer num and returns the sum of the digits
of num.
18) Write a function called first_diff that is given two strings and returns the first location in which
the strings differ. If the strings are identical, it should return-1.
19) Write a function called number_of_factors that takes an integer and returns how many factors
the number has.
20) Write a function called is_sorted that is given a list and returns True if the list is sorted and
False otherwise.
21) Write a function called root that is given a number x and an integer n and returns x1/n. In the
function definition, set the default value of n to2.
22) Write a function called primes that is given a number n and returns a list of the first n primes.
Let the default value of n be100.
23) Write a function called merge that takes two already sorted lists of possibly different lengths,
and merges them into a single sorted list. (a) Do this using the sort method. (b) Do this without
using the sort method.
24)Write a program that asks the user for a word and finds all the smaller words that can be made
from the letters of that word. The number of occurrences of a letter in a smaller word can’t exceed
the number of occurrences of the letter in the user’s word.
25) Write a program that reads a file consisting of email addresses, each on its own line. Your
program should print out a string consisting of those email addresses separated by semicolons.
26) Write a program that reads a list of temperatures from a file called temps.txt, converts those
temperatures to Fahrenheit, and writes the results to a file called ftemps.txt.
27) Write a class called Product. The class should have fields called name, amount, and holding the
product’s name, the number of items of that product in stock, and the regular price of the product.
There should be a method get_price that receives the number of items to be bought and returns a the
cost of buying that many items, where the regular price is charged for orders of less than 10 items, a
10% discount is applied for orders of between 10 and 99 items, and a 20% discount is applied for
orders of 100 or more items. There should also be a method called make_purchase that receives the
number of items to be bought and decreases amount by that much.
28) Write a class called Time whose only field is a time in seconds. It should have a method called
convert_to_minutes that returns a string of minutes and seconds formatted as in the following
example: if seconds is 230, the method should return '5:50'. It should also have a method called
convert_to_hours that returns a string of hours, minutes, and seconds formatted analogously to the
previous method.
29) Write a class called Converter. The user will pass a length and a unit when declaring an object
from the class for example, c = Converter(9,'inches'). The possible units are inches, feet, yards,
miles, kilometers, meters, centimeters, and millimeters. For each of these units there should be a
method that returns the length converted into those units. For example, using the Converter object
created above, the user could call c. feet() and should get 0.75 as the result.
32) Write a program that opens a file dialog that allows you to select a text file. The program then
displays the contents of the file in a textbox.
Bloom’s
CO OUTCOMES
Level
CO-PO MAPPING
P P P P P P P P P PO PO PO PS PS
O O O O O O O O O 10 11 12 O1 O2
1 2 3 4 5 6 7 8 9
C
O 2 2 1
1
C
O 3 2 1
2
C
O - 3 2 3
3
C
O 3 2 3
4
2.6 3.0
- - - - - - - - - 2.00 2.00
6 0
INDEX
Page Date Marks/ Signature
S.No Name of Experiment CO
No Grade
*
5 2
**
***
****
Program 1
Write a program that asks the user for a weight in kilograms and converts it to pounds. There are
2.2 pounds in a kilogram.
Program:
Output:
Write a program that asks the user to enter three numbers (use three separate input statements).
Create variables called total and average that hold the sum and average of the three numbers and
print out the values of total and average.
Program:
Program 3
Write a program that uses a for loop to print the numbers 8, 11, 14, 17, 20, . . . , 83, 86, 89.
Program:
for i in range(8,90,3):
print(i,end=" ")
Output:
8 11 14 17 20 23 26 29 32 35 38 41 44 47 50 53 56 59 62 65 68 71 74 77 80 83 86 89
Program 4
Write a program that asks the user for their name and how many times to print it. The program
should print out the user’s name the specified number of times.
Program:
Output:
Program 5
Use a for loop to print a triangle like the one below. Allow the user to specify how high the triangle
should be.
*
**
***
****
Program:
height=int(input("Enter the height of the Triangle:"))
for i in range(1,height+1):
for j in range(i):
print("*",end="")
print("")
Output:
Enter the height of the Triangle:6
*
**
***
****
*****
******
Program-6
Generate a random number between 1 and 10. Ask the user to guess the number and print a message
based on whether they get it right or not.
Program:
if(n==Guessnumber):
Output:
Program-7
Write a program that asks the user for two numbers and prints Close if the numbers are within .001
of each other and Not close otherwise.
Note: 'abs' is a built-in math function in python which is used for absolute value.
from decimal import *
Program:
Program-8
Write a program that asks the user to enter a word and prints out whether that word contains any
vowels.
Program:
Output:
Program-9
Write a program that asks the user to enter two strings of the same length. The program should then
check to see if the strings are of the same length. If they are not, the program should print an
appropriate message and exit. If they are of the same length, the program should alternate the
characters of the two strings. For example, if the user enters abcde and ABCDE the program should
print out AaBbCcDdEe.
Program:
s1=input("enter the string1:")
s2=input("enter the string2:")
r=''
if(len(s1)==len(s2)):
print('Two strings are same length')
for i in range(len(s1)):
r=r+(s2[i]+s1[i])
print(r)
else:
print("Two strings are different")
Output:
AaBbCcDd
Program-10
Write a program that asks the user for a large integer and inserts commas into it according to the
standard American convention for commas in large numbers. For instance, if the user enters
1000000, the output should be 1,000,000.
Program:
Output:
1,000,000
Enter the Long integer:33000
33,000
Program-11
In algebraic expressions, the symbol for multiplication is often left out, as in 3x+4y or3(x+5).
Computers prefer those expressions to include the multiplication symbol, like3*x+4*y or 3*(x+5).
Write a program that asks the user for an algebraic expressionand then inserts multiplication
symbols where appropriate.
s=input(“Enter algebraic Expressions:”)
l=list(s)
result=’ ‘
i=0
while(i<len(l)):
if l[i]==’(‘:
index=l.index(’)’)
s2=’ ‘.join(l[i:index+1])
result=result+’*’+l[i]
i=i+len(s2)
else if l[i].isalpha():
result=result+’*’+l[i]
i=i+1
else
result=result+l[i]
i=i+1
print(result)
Output:
Enter algebraic expression:3x+4y
3*x+4*y
Program 12
Write a program that generates a list of 20 random numbers between 1 and 100.
(a) Print the list.
(b) Print the average of the elements in the list.
(c) Print the largest and smallest values in the list.
(d) Print the second largest and second smallest entries in the list
(e) Print how many even numbers are in the list.
Program:
import random
l=[]
for num in range(20):
l.append(random.randint(1,100))
print("List Elements are:",l)
avg=sum(l)/len(l)
print("The Average of the Elements in the list is=",avg)
print("Largest Value in the list is :",max(l))
print("Smallest Value in the list is :",min(l))
l1=sorted(l)
print("second Largest value in the List is:",l1[-2])
print("Second smallest value in the List is:",l1[1])
count=0
for i in l1:
if (i%2==0):
count=count+1
print("Number of Even Number in the List is :",count)
Output:
List Elements are: [23, 72, 37, 86, 9, 54, 9, 78, 32, 40, 12, 3, 54, 65, 49, 88, 98, 70, 51, 82]
The Average of the Elements in the list is= 50.6
Largest Value in the list is : 98
Smallest Value in the list is : 3
second Largest value in the List is: 88
Second smallest value in the List is: 9
Number of Even Number in the List is : 12
List Elements are: [31, 56, 77, 32, 47, 85, 17, 61, 86, 50, 86, 85, 96, 14, 37, 64, 75, 11, 22, 68]
The Average of the Elements in the list is= 55.0
Largest Value in the list is : 96
Smallest Value in the list is : 11
second Largest value in the List is: 86
Second smallest value in the List is: 14
Number of Even Number in the List is : 10
Program-13
Write a program that asks the user for an integer and creates a list that consists of the factors of that
integer.
Program:
num=int(input("Enter the Number:"))
l=[]
for i in range(1,num+1):
if(num%i==0):
l.append(i)
print("factors of %d is="%(num),l)
Output:
Write a program that generates 100 random integers that are either 0 or 1. Then find the longest run
of zeros, the largest number of zeros in a row. For instance, the longest run of zeros in
[1,0,1,1,0,0,0,0,1,0,0] is 4.
Import random
l=[]
for num in range(20):
l.append(random.randint(0,1))
print("ListElementsare:",l)
c=0
max_count=0
for range(0,20):
if (l[i]== 0):
c += 1
if(i==len(l)-1):
if(c>max_count):
max_count=c
else:
if c > max_count:
max_count = c
c=0
OUTPUT:
ListElements are: [0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 0]
Longest Run of Zeros in a row is: 2
ListElements are: [0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 1, 1, 0, 1, 0]
Longest Run of Zeros in a row is: 3
Program-15
Write a program that removes any repeated items from a list so that each item appears at most once.
For instance, the list [1,1,2,3,4,3,0,0] would become [1,2,3,4,0].
Program:
n=int(input("Enter the number elements in the list:"))
l=[]
for i in range(1,n+1):
l.append(int(input("Enter the list %d Element:"%(i))))
Output:
Enter the number elements in the list:5
Enter the list 1 Element:45
Enter the list 2 Element:1
Enter the list 3 Element:2
Enter the list 4 Element:5
Enter the list 5 Element:45
The List elements are [45, 1, 2, 5, 45]
remove repeated items from a list is: [45, 1, 2, 5]
Write a program that asks the user to enter a length in feet. The program should then give the user
the option to convert from feet into inches, yards, miles, millimeters, centimeters, meters, or
kilometers. Say if the user enters a 1, then the program converts to inches, if they enter a 2, then the
program converts to yards, etc. While this can be done with if statements,it is much shorter with
lists and it is also easier to add new conversions if you use lists.
Program:
feet=int(input("Enter the Length in Feet:"))
print("""Choose 1 to convert into inches,
choose 2 to convert into yards,
choose 3 to convert into miles,
choose 4 to convert into millimeters,
choose 5 to convert into centimeters,
choose 6 to convert into meters,
choose 7 to convert into kilometers""")
if(opt==1):
print("Inches is:",feet * 12)
elif(opt==2):
print("Yards is:",feet * 0.33333)
elif(opt==3):
print("Miles is:",feet * 0.000189393939)
elif(opt==4):
print("MilliMeters is:",feet * 304.8)
elif(opt==5):
print("centimeters is:",feet * 30.48)
elif(opt==6):
print("meters is:",feet * 0.3048)
elif(opt==7):
print("kilometersis:",feet * 0.0003048)
Output:
Enter the Length in Feet:6
Choose 1 to convert into inches,
choose 2 to convert into yards,
choose 3 to convert into miles,
choose 4 to convert into millimeters,
choose 5 to convert into centimeters,
choose 6 to convert into meters,
choose 7 to convert into kilometers
Enter the your choice:1
Inches is: 72
Program 17
Write a function called sum_digits that is given an integer num and returns the sum of the digits of
num.
Program:
def sum_digit(num):
sum1=0
while(num!=0):
sum1=sum1+num%10
num=num//10
return(sum1)
num=int(input("enter the integer number:"))
sum1=sum_digit(num)
print("the sum of %d digits are =%d"%(num,sum1))
Output:
enter the integer number:164
the sum of 164 digits are =11
Program 18
Write a function called first_diff that is given two strings and returns the first location in which the
strings differ. If the strings are identical, it should return -1.
Program:
def first_diff(s1,s2):
if(s1==s2):
return(-1)
else:
if len(s1)==len(s2):
for i in range(len(s2)):
if s1[i]!=s2[i]:
return(i+1)
s1=input("Enter the string1:")
s2=input("Enter the string2:")
c=first_diff(s1,s2)
if(c==-1):
print("Both Strings are Identical")
else:
print("first Difference occurs at location: ",c)
Output:
Program 19
Write a function called number_of_factors that takes an integer and returns how many factors the
number has.
Program:
def number_of_factors(num):
count=0
for i in range(1,num+1):
if(num%i==0):
print(i,end=" ")
count=count+1
return(count)
Output:
Program 20
Write a function called is sorted that is given a list and returns True if the list is sorted and False
otherwise.
Program:
def is_sorted(l):
k=l[:]
k.sort()
print("The K List elements are",k)
if(l==k):
return True
else:
return False
n=int(input("Enter the number elements in the list:"))
l=[]
for i in range(1,n+1):
l.append(int(input("Enter the list %d Element:"%(i))))
print("The L List elements are",l)
Print(is_sorted(l))
Output:
Write a function called root that is given a number x and an integer n and returns x1/n. In the
function definition, set the default value of n to 2.
Program:
def root(x,n=2):
s=(x**(1/n))
return(s)
Output:
enter the X value:18
enter the nvalue:2
Root value With Default 'n' value 2 is= 4.242640687119285
Root value With 'n' value is= 4.242640687119285
PROGRAM-22
Write a function called primes that is given a number n and returns a list of the first n primes.
Let the default value of n be 100.
Program:
def
printPrime(n=100):
l=[]
x=2
while(len(l)<n):
for i in range(2,int(x**0.5)+1):
if(x%i==0):
break
else:
l.append(x)
x=x+1
return(l)
n=int(input("enter the number of prime numbers:"))
s=printPrime(n)
print("List of first",n,"primes:",s)
j=printPrime()
print("List of first 100 primes:",j)
Output:
Program 23
Write a function called merge that takes two already sorted lists of possibly different lengths, and
merges them into a single sorted list.
(a) Do this using the sort method. (b) Do this without using the sort method.
def merge(l1,l2):
l=l1+l2
l.sort()
return l
Output:
result = []
i=0
j=0
return result
l1=list(map(int,input("Enter the Sorted list 1:").split()))
l2=list(map(int,input("Enter the Sorted list 2:").split()))
s=merge_lists(l1,l2)
print("After merge the list is:",s)
Output:
Program:
Output:
Enter A Word: CSE
CS CE SC SE EC ES
Enter A Word:crre
cr cr ce rc rr re rc rr re ec er er crr cre crr cre cer cer rcr rce rrc rre rec rer rcr rce rrc rre rec rer ecr
ecr erc err erc err
Program 25
Write a program that reads a file consisting of email addresses, each on its own line. Your program
should print out a string consisting of those email addresses separated by semicolons.
Program:
file=open(input("Enter the File name:"))
l=file.readlines()
for line in range(len(l)):
if (l==len(l)-1):
print('{}'.format(l[line].strip()))
else:
print('{}'.format(l[line].strip()),end=";")
Output:
Enter the File name:cse.txt
[email protected];[email protected];[email protected];[email protected];[email protected];
Program 26
Write a program that reads a list of temperatures from a file called temps.txt, converts those
temperatures to Fahrenheit, and writes the results to a file called ftemps.txt.
Program:
file=open('temps.txt','r')
l=file.readlines()
f=open('ftemps.txt','w')
for line in range(len(l)):
d=l[line].strip()
fahrenheit = (float(d) * 9/5) + 32
f.write(str(fahrenheit)+"\n")
f.close()
Output
Program 27
Write a class called Product. The class should have fields called name, amount, and price, holding
the product’s name, the number of items of that product in stock, and the regular price of the
product. There should be a method get_price that receives the number of items to be bought and
returns a the cost of buying that many items, where the regular price is charged for orders of less
than 10 items, a 10% discount is applied for orders of between 10 and 99 items, and a 20% discount
is applied for orders of 100 or more items. There should also be a method
called make_purchase that receives the number of items to be bought and decreases amount by that
much.
Program:
class Product:
Output:
Final costs = 35
A 10% discount is applied for orders of between 10 and 99 items
A 20% discount is applied for orders of 100 or more items
Program 28
Write a class called Time whose only field is a time in seconds. It should have a method
called convert_to_minutes that returns a string of minutes and seconds formatted as in the following
example: if seconds is 230, the method should return '5:50'. It should also have a method
called convert_to_hours that returns a string of hours, minutes, and seconds formatted analogously
to the previous method.
Program:
class Time:
def __init__(self,sec):
self.sec=sec
def seconds_to_Minutes(self):
s=self.sec
minutes = s // 60
seconds=s%60
print('Times in Minutes:seconds format',str(minutes)+":",str(seconds))
def seconds_to_Hours(self):
s=self.sec
hours = s // 3600
minutes=(s//60)%60
seconds=s%60
print('TimesinHours:Minutes:seconds format',str(hours)+":",str(minutes)+":",str(seconds))
Output:
Write a class called Converter. The user will pass a length and a unit when declaring an object from
the class—for example, c = Converter(9,'inches'). The possible units are inches, feet, yards, miles,
kilometers, meters, centimeters, and millimeters. For each of these units there should be a method
that returns the length converted into those units. For example, using the Converter object created
above, the user could call c.feet() and should get 0.75 as the result.
Program:
Class converter:
def __init__ (self,length,unit) :
self.length=length
self.unit=unit
def feet(self):
if (self.unit==’feet’)
return self.length
elif (self.unit==’inches’)
return self.length/12
elif (self.unit==’yards’)
return self.length/0.333
elif (self.unit==’miles’)
return self.length/0.000189
elif (self.unit==’millimeters’)
return self.length/304.8
elif (self.unit==’centimeters’)
return self.length/30.48
elif (self.unit==’meters’)
return self.length/0.305
elif (self.unit==’kilometers’)
return self.length/0.000305
def yards(self):
if (self.unit==’feet’)
return self.length*0.333333
elif (self.unit==’inches’)
return self.length*0.0277778
elif (self.unit==’yards’)
return self.length
elif (self.unit==’miles’)
return self.length*1760
elif (self.unit==’millimeters’)
return self.length*0.00109361
elif (self.unit==’centimeters’)
return self.length*0.0109361
elif (self.unit==’meters’)
return self.length*1.09361
elif (self.unit==’kilometers’)
return self.length*109.361
def miles(self):
if (self.unit==’feet’)
return self.length*0.000189394
elif (self.unit==’inches’)
return self.length*63360
elif (self.unit==’yards’)
return self.length*0.027777728
elif (self.unit==’miles’)
return self.length
elif (self.unit==’millimeters’)
return self.length/1609344
elif (self.unit==’centimeters’)
return self.length/160934.4
elif (self.unit==’meters’)
return self.length/1609.344
elif (self.unit==’kilometers’)
return self.length*/1.609
def kilometers(self):
if (self.unit==’feet’)
return self.length/3280.84
elif (self.unit==’inches’)
return self.length/39370.1
elif (self.unit==’yards’)
return self.length/1093.61
elif (self.unit==’miles’)
return self.length/0.621371
elif (self.unit==’millimeters’)
return self.length/1000000
elif (self.unit==’centimeters’)
return self.length/100000
elif (self.unit==’meters’)
return self.length/1000
elif (self.unit==’kilometers’)
return self.length
def meters(self):
if (self.unit==’feet’)
return self.length/3.28084
elif (self.unit==’inches’)
return self.length/39.3701
elif (self.unit==’yards’)
return self.length/1.09361
elif (self.unit==’miles’)
return self.length/0.000621371
elif (self.unit==’millimeters’)
return self.length/1000
elif (self.unit==’centimeters’)
return self.length/100
elif (self.unit==’meters’)
return self.length
elif (self.unit==’kilometers’)
return self.length/0.001
def centimeters(self):
if (self.unit==’feet’)
return self.length/0.0328084
elif (self.unit==’inches’)
return self.length/0.393701
elif (self.unit==’yards’)
return self.length/0.0109361
elif (self.unit==’miles’)
return self.length*160934
elif (self.unit==’millimeters’)
return self.length/10
elif (self.unit==’centimeters’)
return self.length
elif (self.unit==’meters’)
return self.length*100
elif (self.unit==’kilometers’)
return self.length*100000
def millimeters(self):
if (self.unit==’feet’)
return self.length*304.8
elif (self.unit==’inches’)
return self.length*0.0393701
elif (self.unit==’yards’)
return self.length*0.00109361
elif (self.unit==’miles’)
return self.length*1609340
elif (self.unit==’millimeters’)
return self.length
elif (self.unit==’centimeters’)
return self.length*10
elif (self.unit==’meters’)
return self.length*100
elif (self.unit==’kilometers’)
return self.length*1000000
len=int(input(“Enter length”))
type=input(“Enter unit type:
inches,feet,yards,miles,millimeters,centimeters,meters,kilometers----🡪“)
c=Converter(len,type)
print(“Length in Feet: ”,round(c.feet(),3))
print(“Length in Inches: ”,round(c.inches(),3))
print(“Length in Yards: ”,round(c.yards(),3))
print(“Length in Miles: ”,round(c.miles(),3))
print(“Length in Kilometers: ”,round(c.kilometers(),3))
print(“Length in Meters: ”,round(c.meters(),3))
print(“Length in Centimeters: ”,round(c.centimeters(),3))
print(“Length in Millimeters: ”,round(c.millimeters(),3))
Output
Enter length: 6
Enter unit type: inches,feet,yards,miles,millimeters,centimeters,meters,kilometers---->inches
Length in Feet :0.5
Length in Inches : 6
Length in Yards: 0.167
Length in Miles: 380160
Length in Kilometers:0
Length in Meters: 0.152
Length in Centimeters:15.24
Length in Millimeters:152.4
Program 30
Write a Python class to implement pow(x, n).
Program:
class Pow1:
def poe(self,x,n):
k=x**n
print("pow({},{})={}".format(x,n,k))
p=Pow1()
x=int(input("Enter the X value:"))
n=int(input("Enter the Y value:"))
p.poe(x,n)
Output:
Program:
class Sa:
def display(self,s):
words = s.split(' ')
reverse_sentence = ' '.join(reversed(words))
print("The reverse words of string:",reverse_sentence)
k=Sa()
s = input("enter the string:")
k.display(s)
Output:
enter the string:welcome to python
The reverse words of string: python to welcome
Program-32
Write a program that opens a file dialog that allows you to select a text file. The program then
displays the contents of the file in a textbox.
Output
Program 33
Program:
try:
a=int(input("enter the A value:"))
b=int(input("enter the B value:"))
s=a/b
except ZeroDivisionError:
print("Can't divide by zero(b=0)")
else:
print("The division is=",s)
Output:
Program 34
Program:
try:
a=int(input("enter the A value:"))
b=int(input("enter the B value:"))
s=a/b
except ZeroDivisionError:
print("Can't divide by zero(b=0)")
else:
print("The divsion is=",s)
finally:
print('This is always executed')
Output: