1. Python program to check uppercase or lowercase letter
Below is the program to check whether the given character is an uppercase or lowercase letter or a digit or a special character.
inputChar = input("Enter any character : ")
if inputChar.isupper():
print(str(inputChar) + " character is uppercase letter")
elif inputChar.islower():
print(str(inputChar) + " character is Lower letter")
elif inputChar.isdigit():
print(str(inputChar) + " character is digit ")
else:
print(str(inputChar) + " character is a special character ")
Output:
Below is the program to find the maximum number out of the given three numbers.
n1= int(input("Enter first number : "))
n2= int(input("Enter second number : "))
n3= int(input("Enter third number : "))
if n1>n2 and n1>n3 :
print(str(n1)+" is biggest number ")
elif n2>n1 and n2>n3 :
print(str(n2)+" is biggest number ")
elif n3>n1 and n3>2 :
print(str(n3)+" is biggest number ")
else:
print("Hey !!! all numbers are equal")
Output:
An electric power distribution company charges its domestic consumers as follows:
Consumption Units | Rate of Charges |
0-100 | Rs. 1 per unit |
101-300 | Rs. 100 plus Rs. 1.25 per unit in excess of 100 |
301-500 | Rs. 350 plus Rs. 1.50 per unit in excess of 300 |
500 and above | Rs. 650 plus Rs. 1.75 per unit in excess of 500 |
Below is a program that read the customer number & power consumed and prints the amount to be paid by the customer. You will note that output is also well formatted. Let's start below
customerNo=int(input("Enter customer number : "))
units=int(input("Enter the power consumed :"))
if units>0 and units<=100 :
billAmt=units*1
elif units>100 and units<=300 :
billAmt=100+(units-100)*1.25
elif units>300 and units<=500 :
billAmt=350+(units-300)*1.50
elif units>500:
billAmt=650+(units-500)*1.75
else:
print("Invalid Input, please try again. ")
print("~"*60)
print("\t\t\t PSPCL BILL ")
print("~"*60)
print("\t\tPayable Bill Amount :INR " +str(billAmt))
print("-"*60)
Output:
Below is a program to print a multiplication table of the entered number.
n=int(input("Enter the table number:"))
print("-"*40)
print("\t\t Table of "+str(n))
print("-"*40)
for i in range(10):
index=i+1
result=n*index
print("\t\t"+str(n)+" * "+str(index)+" = "+str(result))
print("-"*40)
Output:
Below is the program to check whether the entered number is Armstrong or not.
num = int(input("Enter Your Number: "))
sum = 0
temp = num # store value to compare later on
while temp > 0:
digit = temp % 10
sum =sum + digit ** 3
temp =temp // 10
if num == sum:
print("Congrats !! "+str(num)+" is an Armstrong number.")
else:
print("Oops !!"+str(num)+"is not an Armstrong number")
Output:
Below is the program to generate the following pattern.
n=int(input("Enter the number :"))
k=1
for i in range(1,n+1): # outer loop
for j in range(1,i+1): # inner loop
print(str(k)+" ",end="")
k=k+1
print("\r")
Output:
Below is a program to create a list of students’ marks with user-defined values and find the maximum marks of subject.
n = int(input("Enter the number of subjects :"))
l=[]
for i in range (n) :
m=int(input("Enter the marks obtained in subject " +str(i+1)+ " : "))
l.append(m)
print("congratulations !! your maximum marks scored is " +str(max(l)))
Output:
Below is a program to create a list of numbers and swap the content with the next value divisible by 5.
n=int(input("Enter the number of list : "))
l=[]
for i in range(n):
m=int(input("Enter the number "+str(i+1)+" : "))
l.append(m)
for i in range (len(l)):
if i%5==0 :
l[i],l[i+1]=l[i+1],l[i]
print("list after swaped :" +str(l))
Output:
Below is a program to count the frequency of every element in a given list.
n = int(input("\tEnter the number of element :")a)
l = []
for i in range(n):
m = int(input("\tEnter value " + str(i + 1) + " : "))
l.append(m)
f = {}
for item in l :
if item in f :
f[item] += 1
else:
f[item] = 1
for i,j in f.items():
print("-"*30)
print("\r\t"+str(i) + " Frequency is " + str(j))
print("-"*30)
Output:
Below is a program to compute the net run rate of given number of matches.
teamName = input("Enter the name of Team : ")
totalMatches = int(input("Enter the number of matches played : "))
totalRun = 0 # to hold total runs
totalOvers = 0 # to hold total overs
if totalMatches > 5:
print("You can enter Maximum 5 matches")
else:
for i in range(totalMatches):
runs = int(input("Enter the number of run scorred in match " + str(i + 1) + ": "))
overs = int(input("Enter the number of overs " + str(i + 1) + ": "))
totalRun = totalRun + runs
totalOvers = totalOvers + overs
#computing net run rate only for max 5 matches
if totalMatches <= 5:
netRunRate = 0
netRunRate = int(totalRun / totalOvers)
print("Congrats " + teamName + " your net run rate is: " + str(netRunRate))
Output:
11: Write a program to create a 2D array using NumPy.
Output:
12: Write a program to convert a python list to a NumPy array.
Output:
13: Write a program to create matrix of 3x3 from 11 to 30.
Output:
14: Write a program to create a data frame to store data of candidates who appeared in interviews. The data frame columns are name, score, attempts, and qualify (Yes/No). Assign row index as C001,C002, and so on.
Output:
15: Write a program to create a data frame named player and store their data in the columns like team, no. of matches, runs, and average. Assign player name as row index and display only those player details whose score is more than 1000.
Output:
16: Write a program to represent the data on the ratings of mobile games on bar chart. The sample data is given as: Pubg, Free Fire, Mine Craft, GTA-V, Call of duty, FIFA 22. The rating for each game is as: 4.5,4.8,4.7,4.6,4.1,4.3
Output:
17: Observe the given data for monthly sales of one of the salesmen for 6 months. Plot them on the line chart.
Output:
18: Load Image [using CV i.e. computer Vision] and give the title of image
Output:
19: Change the color of image and change the image to grayscale.
20: Display the maximum and minimum pixels of image.
Output:
No comments:
Post a Comment