Program-1: # Wap To Input Three No'S. and Display The Largest and Smallest No
Program-1: # Wap To Input Three No'S. and Display The Largest and Smallest No
Code:
number1 = int(input('Enter First number : '))
number2 = int(input('Enter Second number : '))
number3 = int(input('Enter Third number : '))
def largest(num1, num2, num3):
if (num1 > num2) and (num1 > num3):
largest_num = num1
elif (num2 > num1) and (num2 > num3):
largest_num = num2
else:
largest_num = num3
print("The largest of the 3 numbers is : ", largest_num)
def smallest(num1, num2, num3):
if (num1 < num2) and (num1 < num3):
smallest_num = num1
elif (num2 < num1) and (num2 < num3):
smallest_num = num2
else:
smallest_num = num3
print("The smallest of the 3 numbers is : ", smallest_num)
largest(number1, number2, number3)
smallest(number1, number2, number3)
Output:
PROGRAM-2
#WAP TO DETERMINE WHETHER THE NO. IS A PERFECT
NO. OR ARMSTRONG NO. OR A PALINDROM
Code:
def palindrome(n): # palindrome a function is made and given the input number
temp = n #temp is taken as input
rev = 0 #reverse is 0
while n > 0: #if n is greater than 0 this loop runs
dig = n % 10
rev = rev * 10 + dig #This loop calculates the reverse and matches it with input
n = n // 10
if temp == rev:
print(temp,"The number is a palindrome!")
else:
print(temp,"The number isn’t a palindrome!")
def armstrong(n):
count = 0
temp = n
while temp > 0:
digit = temp % 10
count += digit ** 3
temp //= 10 # Armstrong number is a number that is equal to the sum of cubes of its
digits
if n == count:
print(n,"is an Armstrong number")
else:
print(n,"is not an Armstrong number")
def perfect(n):
count = 0
for i in range(1, n):
if n % i == 0:
count = count + i
if count == n:
print(n,"The number is a Perfect number!")
else:
print(n,"The number is not a Perfect number!")
Code:
num = int(input(“Enter any number :”))
if num >1:
for i in range(2, num):
if (num % i) == 0:
print(num,”is a composite number”)
break
else:
print(num,”is a Prime number”)
elif num == 0 or 1:
print(num,”is a neither Prime NOR Composite number”)
Output:
PROGRAM-4
# WAP TO DISPLAY THE TERMS OF A FIBONACCI SERIES.
Code:
i = int(input(“Enter the limit:”))
x=0
y=1
z=1
print(“Fibonacci series\n”)
print(x,y,end=””)
while(z<=i) :
print(z, end=””)
x=y
y=z
z =x+y
Output:
PROGRAM-5
#WAP TO COMPUTE THE GREATEST COMMON DIVISOR
(GCD) AND LEAST COMMON MULTIPLE(LCM) OF 2
INTEGERS.
Code:
a,b = 28,16
c,d = a,b
gcd,lcm = 0,0
while b:
a,b = b,a%b
gcd = a
lcm = (c * d)/gcd
print (‘GCD is ‘,gcd, ‘\nLCM is ‘,lcm)
Output:
PROGRAM-6
#WAP TO COUNT AND DISPLAY THE NO. OF
VOWELS,CONSONANTS,UPPERCASE, LOWERCASE
CHARACTERS IN A STRING
Code:
string = input("Enter Your String :")
vowels = consonants = uppercase = lowercase = 0
vowels_list = ['a','e','i','o','u']
for i in string:
if i in vowels_list:
vowels += 1
if i not in vowels_list:
consonants += 1
if i.isupper():
uppercase += 1
if i.islower():
lowercase += 1
print("Number of Vowels in this String = ", vowels)
print("Number of Consonants in this String = ", consonants)
print("Number of Uppercase characters in this String = ", uppercase)
print("Number of Lowercase characters in this String = ", lowercase)
Output:
PROGRAM-7
#WAP TO FIND THE LARGEST NO. IN A LIST
Code:
list1 = [ ]
num = int(input(“Enter number of elements in list:”))
for i in range(1, num + 1):
ele = int(input(“Enter elements:”))
list1.append(ele)
print(“Largest element is:”, max(list1))
Output:
PROGRAM-8
#WAP TO INPUT A LIST OF NUMBERS AND SWAP
ELEMENTS AT THE EVEN LOCATION WITH THE
ELEMENTS AT ODD LOCATION.
Code:
val=eval(input(“Enter a list:”))
print(“Original List is:”,val)
s=len(val)
if s%2!=0:
s=s-1
for i in range(0,s,2):
val[i],val[i+1]=val[i+1],val[i]
print(“List after swapping :”,val)
Output: