Python File
Python File
OUTPUT:
Enter first number : 2
Enter second number : 3
Sum = 5
Difference = -1
Multiplication = 6
Division = 0.6666666666666666
Floor Division = 0
Modulus = 2
Exponent = 8
2028202 Subject code-BTCS-513-18
3. Write a program to create, concatenate and print a string and accessing
substring from a given string.
while(1):
print("select the option")
print("1.creating a string")
print("2.concatenate a string")
print("3.printing a string")
print("4.accessing a substring")
print("5.exit")
ans=int(input())
if ans==1:
str=input("Enter the string:")
print("your entered string is:",str)
if ans==2:
str1=input("enter your first string:")
str2=input("enter your second string:")
str3=str1+str2
print("your concatenated string is:",str3)
if ans==3:
str4=input("Enter the string:")
print("your entered string is:",str4)
if ans==4:
str=input("Enter the string:")
sc=input("enter the value to check substring:")
if sc in str:
print(sc, "is a substring")
else:
print(sc, "is a substring")
if ans==5:
print("you exit from program")
2028202 Subject code-BTCS-513-18
exit()
OUTPUT:
select the option
1.creating a string
2.concatenate a string
3.printing a string
4.accessing a substring
5.exit
1
Enter the string:cse
your entered string is: cse
1.Create a list
2.Append into a list
3.Remove from a list
4.Exit
Enter your choice :3
Enter the element which you want to remove :2
['1', '3']
1.Create a list
2.Append into a list
3.Remove from a list
4.Exit
Enter your choice :4
you exit from program
2028202 Subject code-BTCS-513-18
6. Write a program to demonstrate working with tuples in python.
#code
while(1):
print("\n")
print('1.Create a tuple')
print('2.Append/Insert into a tuple')
print('3.Remove from a Tuple')
print('4.Update values of Tuple')
print('5.Exit')
a=int(input('Enter your choice :'))
if(a==1):
lst=[]
n=int(input('Enter the number of elements you want to add into Tuple : '))
for i in range(0,n):
ele=input('Enter element :')
lst.append(ele)
tup=tuple(lst)
print(tup)
elif(a==2):
ap=input("Enter the element you want to append into Tuple : ")
lst.append(ap)
tup=tuple(lst)
print(tup)
elif(a==3):
rm=input("Enter the element which you want to remove :")
lst.remove(rm)
tup=tuple(lst)
print(tup)
elif(a==4):
ind=int(input("Enter the index of element which you want to update :"))
el=input("Enter value :")
lst[ind]=el
tup=tuple(lst)
print(tup)
elif(a==5):
print("exited")
exit()
2028202 Subject code-BTCS-513-18
OUTPUT:
1.Create a tuple
2.Append/Insert into a tuple
3.Remove from a Tuple
4.Update values of Tuple
5.Exit
Enter your choice :1
Enter the number of elements you want to add into Tuple : 4
Enter element :1
Enter element :2
Enter element :3
Enter element :43
('1', '2', '3', '43')
1.Create a tuple
2.Append/Insert into a tuple
3.Remove from a Tuple
4.Update values of Tuple
5.Exit
Enter your choice :3
Enter the element which you want to remove :43
('1', '2', '3')
1.Create a tuple
2.Append/Insert into a tuple
3.Remove from a Tuple
4.Update values of Tuple
5.Exit
Enter your choice :5
exited
2028202 Subject code-BTCS-513-18
9. Write a Python program to convert temperatures to and from Celsius,
Fahrenheit.
[ Formula: c/5 = f-32/9]
#code
F=float(input("Enter temperature in fahrenheit:"))
C=(F-32)*5/9
print("%.2f Fahrenheit is: %0.2f Celsius" %(F,C))
C=float(input("Enter temperature in celsius:"))
F=(C*9/5)+32
print("%.2f Celsius is: %0.2f Fahrenheit" %(C,F))
OUTPUT:
Enter temperature in fahrenheit:212
212.00 Fahrenheit is: 100.00 Celsius
Enter temperature in celsius:100
100.00 Celsius is: 212.00 Fahrenheit
OUTPUT:
Enter the number:5
*
**
***
****
*****
****
***
**
*
2028202 Subject code-BTCS-513-18
11. Write a Python script that prints prime numbers less than 20.
#code
lower_val=int(input("enter the lower number:"))
greater_value=int(input("enter the higher number:"))
for number in range(lower_val,greater_value+1):
if number>1:
for i in range(2,number):
if(number%i)==0:
break
else:
print(number)
OUTPUT:
OUTPUT:
User Input : 4
The factorial of 4 is 24
2028180 Subject code-BTCS-513-18
25. WAP to check is a substring is present in a string.
#code
s=input("Enter the string:")
sub=input("Enter the substring:")
if sub in s:
print("Yes, the substring is present in the string")
else:
print("No, the substring is not present in the string")
OUTPUT:
Enter the string: hi hello
Enter the substring: hey
No, the substring is not present in the string