Class X
Class X
Coding:
tr=0
to=0
tagr=0
togr=0
#Entering runs and overs and adding them for n number of matches
for i in range(n):
tr=r+tr
to=to+o
tagr+=agr
togr+=ogr
nrr=(tr/to)-(tagr/togr)
Coding:
#Input the character to check
ch=input("Enter Any Character:")
'''Checking whether it is upperletter or lowerletter or digit or a special character'''
if ch.isupper():
print(ch, " is an upper case letter")
elif ch.islower():
print(ch, " is a lower case letter")
elif ch.isdigit():
print(ch, " is a digit")
elif ch.isspace():
print(ch, " is a space")
else:
print(ch," is a special character")
Output:
Enter Any Character: A
A is an upper case letter
Coding:
#Take input or three number to compare
n1=int(input("Enter the Number1:"))
n2=int(input("Enter the Number2:"))
n3=int(input("Enter the Number3:"))
if n1>n2 and n1>n3:
print(n1, " - Number 1 is greater")
elif n1>n2 and n1>n3:
print(n2, " - Number 2 is greater")
elif n3>n1 and n3>n2:
print(n3, " --> Number 3 is greater")
else:
print("All are same")
Output:
Write a program that read the customer number & power consumed and prints the
amount to be paid by the customer. Note that output should be well formatted.
Coding:
#Input Data
cno=int(input("Enter Cusumer Number:"))
pc=int(input("Enter power consumed:"))
#Computing bill amount based on power consumed
if pc>0 and pc<=100:
bill_amt=pc*1
elif pc>100 and pc<=300:
bill_amt=100+(pc-100)*1.25
elif pc>300 and pc<500:
bill_amt=350+(pc-300)*1.50
elif pc>500:
bill_amt=650+(pc-500)*1.75
else:
print("Invalid Power Consumed Units")
#Printing the bill in proper format
print("~"*60)
print("\t\tABC Power Company Ltd.")
print("~"*60)
print("Consumer Number:",cno)
print("Consumed Units:",pc)
print("------------------------------")
print("Bill Amount:",bill_amt)
Output:
Enter Cusumer Number:1002
Enter power consumed:230
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ABC Power Company Ltd.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Consumer Number: 1002
Consumed Units: 230
------------------------------
Bill Amount: 262.5
Coding:
#Enter a number to check
n=int(input("Enter number to check:"))
#Store the original number into temporary variable
t=n
s=0
#Computing the sum of cube of each digit and iterating until n=0
while n!=0:
r=n%10
s=s+(r**3)
n//=10
#Checking & displaying whether armstrong or not
if t==s:
print(s," is Armstrong number")
else:
print("Is not an Armstrong number")
Output:
Enter number to check:153
153 is Armstrong number
Coding:
#Take input to accept a nmuber for printing Multiplication table
n=int(input("Enter number to print multiplication table:"))
#Take for loop for multiple
for i in range(1,11):
print(n," x ", i, " = ", n*i )
Output:
Enter number to print multiplication table: 5
5 x 1 = 5
5 x 2 = 10
5 x 3 = 15
5 x 4 = 20
5 x 5 = 25
5 x 6 = 30
5 x 7 = 35
5 x 8 = 40
5 x 9 = 45
5 x 10 = 50
Coding:
#Take input for n lines
n=int(input("Enter n:"))
#Generating Pattern
k=1
for i in range(1,n+1):
for j in range(1,i+1):
print(k,end=" ")
k=k+1
print()
Output:
Enter n: 5
1
23
456
7 8 9 10
11 12 13 14 15
8. Write a program to create a list of student’s marks with user- defined values and
find the maximum.
Coding:
#Take input for n lines
n=int(input("Enter no. of subjects:"))
#Creating empty list
l=[]
#Accepting marks and appending marks into the list
for i in range(n):
m=int(input("Enter marks:"))
l.append(m)
print("Maximum marks scored:",max(l))
Output:
Enter no. of subjects: 5
Enter marks: 20
Enter marks: 52
Enter marks: 41
Enter marks: 63
Enter marks: 88
Maximum marks scored: 88
9. Write a program to create a list of numbers and swap the content with the next
value divisible by 5.
Coding:
#Take input for no of subjects
n=int(input("Enter no. of subjects:"))
#Creating empty list
l=[]
#Accepting marks and appending marks into the list
for i in range(n):
m=int(input("Enter marks:"))
l.append(m)
#Swaping elements
for i in range(len(l)) :
if l[i] % 5 == 0 :
l [ i ], l [i-1] = l [ i - 1 ] , l [i]
print("List after swap:",l)
Output:
Enter no. of subjects:5
Enter marks:21
Enter marks:55
Enter marks:33
Enter marks:45
Enter marks:25
List after swap: [55, 21, 45, 25, 33]
10. Write a program to count the frequency of every element in a given list.
Coding:
#Creating empty list
l = []
#Take input for n no. of elements
n=int(input("Enter the no. of elements:"))
#Append the values into the list
for i in range(n):
val=int(input("Enter value "+str(i+1)+":"))
l.append(val)
#Declaring a dictionary object to store the data
f = {}
for i in l:
if (i in f):
f[i] += 1
else:
f[i] = 1
#Displaying the data
for i, j in f.items():
print(i, "->",j)
Output:
Enter the no. of elements:5
Enter value 1:24
Enter value 2:21
Enter value 3:24
Enter value 4:23
Enter value 5:24
24 -> 3
21 -> 1
23 -> 1