Assignment 3
NAME : Ansh Jigneshkumar Darji
REG_NO: 20243507
1.Write a python program to find largest of three numbers.
a=int(input("enter a no1: "))
b=int(input("enter a no2: "))
c=int(input("enter a no3: "))
if a>b and a>c :
print(a," is the largest")
elif a<b and b>c :
print(b," is the largest")
elif c>a and c>b :
print(c," is the largest")
else :
print("error!")
WITH FUNCTION:
def q1():
a=int(input("enter a no1: "))
b=int(input("enter a no2: "))
c=int(input("enter a no3: "))
if a>b and a>c :
print(a," is the largest")
elif a<b and b>c :
print(b," is the largest")
elif c>a and c>b :
print(c," is the largest")
else :
print("error!")
q1()
OUTPUT:
2. Read two integer numbers from the keyboard and print
minimum value using ternary operator
x=int(input("enter no1: "))
y=int(input("enter no2: "))
z=y if x>y else x
print("smallest number is",z)
WITH FUNCTION :
def q2():
x=int(input("enter no1: "))
y=int(input("enter no2: "))
z=y if x>y else x
print("smallest number is",z)
q2()
OUTPUT
3. Write a Python program to compute the GCD of two
numbers.
g=0
a=int(input("enter a number: "))
b=int(input("enter a number:"))
if a<b:
a,b=b,a
for i in range(1,b+1):
if a%i==0 and b%i==0:
g=i
print("GCD: ", g)
WITH FUNCTION :
def q3():
g=0
a=int(input("enter a number: "))
b=int(input("enter a number:"))
if a<b:
a,b=b,a
for i in range(1,b+1):
if a%i==0 and b%i==0:
g=i
print("GCD: ", g)
q3()
OUTPUT
4. Write a program to compute LCM of a number.
l=0
a=int(input("enter a number"))
b=int(input("enter another number: "))
if a<b:
a,b=b,a
for i in range(1,b+1):
if (a*i)%b==0:
l=i*a
break
print("LCM: ", l)
WITH FUNCTION :
def q4():
l=0
a=int(input("enter a number"))
b=int(input("enter another number: "))
if a<b:
a,b=b,a
for i in range(1,b+1):
if (a*i)%b==0:
l=i*a
break
print("LCM: ", l)
q4()
OUTPUT:
5. Write a python program to that accepts length of three
sides of a triangle as inputs. The program should indicate
whether or not the triangle is a right-angled triangle (use
Pythagorean Theorem).
a=int(input("side1: "))
b=int(input("side2: "))
c=int(input("side3: "))
l=[a,b,c]
l.sort()
a,b,c=l
if (a*a)+(b*b)==(c*c):
print("The triangle is a right angle triangle")
else:
print("not a right angle trigangle")
WITH FUNCTION :
def q5():
a=int(input("side1: "))
b=int(input("side2: "))
c=int(input("side3: "))
l=[a,b,c]
l.sort()
a,b,c=l
if (a*a)+(b*b)==(c*c):
print("The triangle is a right angle triangle")
else:
print("not a right angle trigangle")
q5()
OUTPUT
6. Write a Python program to check whether a year entered
by user at run-time is a leap year or not.
a=int(input("enter a year:"))
if a%4==0:
print("leap year")
else:
print("not a leap year")
WITH FUNCTION :
def q6():
a=int(input("enter a year:"))
if a%4==0:
print("leap year")
else:
print("not a leap year")
q6()
OUTPUT
7. Write a program to print a given number is Armstrong or
not.
import math
a=input("enter a number: ")
sum=0
c=len(list(a))
for i in a:
sum+=pow(int(i),c)
if sum==int(a):
print("armstrong")
else:
print("not armstrong")
WITH FUNCTION:
def q7():
import math
a=input("enter a number: ")
sum=0
c=len(list(a))
for i in a:
sum+=pow(int(i),c)
if sum==int(a):
print("armstrong")
else:
print("not armstrong")
q7()
OUTPUT
8. Write a program to print first 100 elements of a Fibonacci
series.
a=0
b=1
print("fibonacci series")
print(a)
print(b)
for i in range(98):
g=a+b
a=b
b=g
print(g)
WITH FUNCTION :
def q8():
a=0
b=1
print("fibonacci series")
print(a)
print(b)
for i in range(98):
g=a+b
a=b
b=g
print(g)
q8()
OUTPUT:
09. Write a program to create a multiplication Table.
x = int(input("Enter the number: "))
for i in range(1,11):
print(x,'x',i,"=",x*i)
WITH FUNCTION :
def q9():
x = int(input("Enter the number: "))
for i in range(1,11):
print(x,'x',i,"=",x*i)
q9()
OUTPUT
10. Write a program to print a given string is a palindrome
or not.
str1 = input("Enter a string: ")
l1 = []
for i in str1:
l1.append(i)
tlist = l1.copy()
l1.reverse()
rlist = l1
if(rlist == tlist):
print("It is palindrome")
else:
print("Not a palindrome")
WITH FUNCTION :
def q10():
str1 = input("Enter a string: ")
l1 = []
for i in str1:
l1.append(i)
tlist = l1.copy()
l1.reverse()
rlist = l1
if(rlist == tlist):
print("It is palindrome")
else:
print("Not a palindrome")
q10()
OUTPUT
11. Write a program to remove punctuations from a string.
s = input("Enter a string: ")
l = []
for i in s:
if i.isalpha() or i == " ":
l.append(i)
s = ''.join(l)
print("String:", s)
WITH FUNCTION :
def q11():
s = input("Enter a string: ")
l = []
for i in s:
if i.isalpha() or i == " ":
l.append(i)
s = ''.join(l)
print("String:", s)
q11()
OUTPUT
12. Write a Python program to check whether a character
entered by a user is vowel or not.
inp = input("Enter character: ")
vowels =['a','e','i','o','u']
if inp in vowels:
print("Yes its a vowel")
else:
print("Not a vowel")
WITH FUNCTION :
def q12():
inp = input("Enter character: ")
vowels =['a','e','i','o','u']
if inp in vowels:
print("Yes its a vowel")
else:
print("Not a vowel")
q12()
OUTPUT
13. Write a program to print number of vowels present in a
string.
inp= input("Enter string:")
vowels =['a','e','i','o','u']
k=0
for i in inp:
if(i in vowels):
k =k + 1
print("Number of vowels ",k)
WITH FUNCTION :
def q13():
inp= input("Enter string:")
vowels =['a','e','i','o','u']
k=0
for i in inp:
if(i in vowels):
k =k + 1
print("Number of vowels ",k)
q13()
OUTPUT