II Term STD 10 - Revision 5 For Robotics & AI
II Term STD 10 - Revision 5 For Robotics & AI
2) The Fine Electricity Ltd calculates monthly electricity bill as per the given
criteria
Number of units consumed Rate per unit(Rs.)
First 100 units Only meter rent Rs.150/-
For next 100 units Rs.1.00 per unit + meter rent
For next 100 units Rs.1.20 per unit + meter rent
For more than 300 units Rs.1.50 per unit + meter rent
Write a program to input meter number (integer type) and number of units
consumed (integer type). Calculate the bill amount to be paid. Print the meter
number and the bill amount.
Sample Output:
Enter the meter no:123
Enter the units consumed:99
Meter number = 123
Bill amount = 150.0
Solution:
meterno = int(input("Enter the meter no:"))
units = int(input("Enter the units consumed:"))
if(units>=1 and units<=100):
billamount = 150.0
elif(units>100 and units<=200):
billamount = 150.0 + (1.0 * (units-100))
elif(units>200 and units<=300):
billamount = 150.0 + (1.0 * 100.0) + (1.2 * (units-200))
else:
billamount = 150.0 + (1.0 * 100.0) + (1.2 * 100.0)+(1.5 *(units-300))
print("Meter number =",meterno)
print("Bill amount =",billamount)
3) Write a menu-driven program in python to enter a day number and find out
which day of week it is?
Solution:
print("Enter the Day number to find the Day -Day 1 = Sunday, Day 2 =
Monday...and so on.")
n = int(input('Enter a number to check for the Day : '))
match n:
case 1:
print("Sunday")
case 2:
print("Monday")
case 3:
print("Tuesday")
case 4:
print("Wednesday")
case 5:
print("Thursday")
case 6:
print("Friday")
case 7:
print("Saturday")
case default:
print("Invalid Input-please try again")
12
123
1234
12345
Solution:
for i in range(0,5,1):
for j in range(1,i+2,1):
print(j,end =" ")
print("\n")
5) Write a program in python to display the pattern given below:
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15
Solution:
n=1
for i in range(0,5,1):
for j in range(1,i+2,1):
print(n,end =" ")
n=n+1
print()
Solution:
for i in range(0,5,1):
n = 'BASIC'
for j in range(0,i+1,1):
print(n[j],end =" ")
print()
7) Write a program in python to display the pattern given below:
A
B C
D E F
G H I J
K L M N O
Solution:
n = 65 #ASCII value for uppercase A
for i in range(0,5,1):
for j in range(1,i+2,1):
print(chr(n),end =" ") # explicit type conversion
n=n+1
print()
A
A B
A B C
A B C D
A B C D E
Solution:
for i in range(0,5,1):
n = 65
for j in range(1,i+2,1):
print(chr(n),end =" ")
n=n+1
print()
9) Write a program in python to display the pattern given below:
12345
1234
123
12
1
Solution:
for i in range(5,0,-1):
for j in range(1,i+1,1):
print(j,end =" ")
print("\n")
43
432
4321
Solution:
for i in range(4,0,-1):
for j in range(4,i-1,-1):
print(j,end =" ")
print("\n")
11) Write a program in python to display the pattern given below:
1
21
321
4321
Solution:
for i in range(0,4,1):
for j in range(i+1,0,-1):
print(j,end =" ")
print("\n")
13) Write a program in python to accept a number and display its reverse.
Example: Enter a number: 133
The reverse of the given number is = 331
Solution:
n = int(input("Enter a number: "))
reverse = 0
temp = n
while(temp>0):
digit = temp%10
reverse = reverse * 10 + digit
temp = temp//10
print("The reverse of the given number is =", reverse)
14) Create a user defined function isPrime( ) to accept a number and return True if
number is prime otherwise False. (A number is said to be prime if it is only
divisible by itself and 1) Board -Specimen Question
Solution:
def isPrime(num):
flag = False
count = 0
for i in range(1,num+1,1):
if(num%i == 0):
count = count + 1
if(count == 2):
flag = True
return flag
n = int(input('Enter a number to check for Prime: '))
result = isPrime(n)
if (result == True):
print(n,' is a Prime Number')
else:
print(n,' is not Prime Number')
15) Create a user defined function fourop( ) to accept two numbers and return the
sum, difference, product and division of the two numbers.
Solution:
def fourop(a,b):
add = a + b
sub = a - b
mul = a * b
div = a / b
return(add,sub,mul,div)
c = eval(input('Enter the first number: '))
d = eval(input('Enter the second number: '))
ad,su,mu,di = fourop(c,d)
print("Sum is: ",ad,"Difference is: ",su,"Product is: ",mu,"Division is: ",di)
17) Write a program in python to print the first 10 terms of the Fibonacci series.
The 10 terms of Fibonacci series are :
0 1 1 2 3 5 8 13 21 34
Hint: The sum of the first two terms of the series is equal to the third term.
Solution:
# using while loop
num1 = 0
num2 = 1
next_num = num2
print("The 10 terms of Fibonacci series are : ")
print(num1,end = " ") #Printing First term
count = 1
while(count <= 9):
print(next_num,end = " ")#Printing remaining 9 terms
next_num = num1 + num2
num1 = num2
num2 = next_num
count = count + 1
OR
s=0
i=1
while(i <= 15):
print(((i**2)+1),end = " ")
i=i+1
Output:
Note: In the above program, even though the labelling of X-axis and Y-axis is not
mentioned in the question, it is compulsory to label and give title to it. The output
graph will not be given in the exam, I have given only for your reference)
21) Write a python program to create a bar chart with a heading ‘Enrollment’–
x – axis (labelled Courses offered) - C, C++, Java and Python
y – axis (labelled No. of students enrolled) – 20, 15, 30, 35
Solution:
import matplotlib.pyplot as plt
x = ['C','C++', 'Java', 'Python']
y = [20,15,30,35]
plt.bar(x,y,color = 'maroon', width = 0.4)
plt.xlabel("Courses offered")
plt.ylabel("No. of Students enrolled")
plt.title("Enrollment")
plt.show()
Note: In the above program, the data andlabelling of X-axis and Y-axis is
mentioned in the question, but if it is not given, you need to give the data and
solve the problem. The output graph will not be given in the exam, I have given
only for your reference)
Output:
22) Write a program in python to create a scatter plot for the following–
x – axis – (5,7,8,7,2,17,2,9,4,11,12,9,6)
y – axis – (99,86,87,88,100,86,103,87,94,78,77,85,86)
Solution:
import matplotlib.pyplot as plt
x = [5,7,8,7,2,17,2,9,4,11,12,9,6]
y = [99,86,87,88,100,86,103,87,94,78,77,85,86]
plt.scatter(x,y,color = 'blue')
plt.xlabel("X-axis")
plt.ylabel("Y-axis")
plt.title("Scatter Plot")
plt.show()
Output:
Note: In the above program, the data and labelling of X-axis and Y-axis is
mentioned in the question, but if it is not given, you need to give the data and
solve the problem. The output graph will not be given in the exam, I have given
only for your reference)
23) Write a program in python to create a pie chart for the following data–
Category – (AUDI, BMW, FORD, TESLA, JAGUAR, MERCEDES)
Proportion of each category mentioned above– (23,17, 35, 29, 12, 41)
Solution:
import matplotlib.pyplot as plt
cars = ['AUDI', 'BMW','FORD', 'TESLA','JAGUAR', 'MERCEDES']
data = [23,17, 35, 29, 12, 41]
plt.pie(data,labels = cars)
plt.title("Analysis")
plt.show()
Output:
Note: In the above program, the data and labelling of X-axis and Y-axis is
mentioned in the question, but if it is not given, you need to give the data and
solve the problem. The output graph will not be given in the exam, I have given
only for your reference)
24) Write a program in python to create and display a Series for the following
data– 11, 8, 6, 14, 25.
Solution:
import pandas as pd
s = pd.Series([11,8,6,14,25])
print(s)
Output:
0 11
1 8
2 6
3 14
4 25
25) Write a program in python to create and display a Series for the following
data– 11, 8, 6, 14, 25 with index a, b, c, d, e.
Solution:
import pandas as pd
s = pd.Series([11,8,6,14,25],index =['a', 'b','c','d','e'])
print(s)
Output:
a 11
b 8
c 6
d 14
e 25
26) Write a program in python to create and display the following data using a
DataFrame by taking input as a dictionary, also find the average age–
Name Age
Alice 24
Bob 27
Charlie 22
Solution:
import pandas as pd
data = {'Name':['Alice','Bob','Charlie'], 'Age':[24,27,22]} #dictionary to store data
df = pd.DataFrame(data)
print("Data Frame:")
print(df)
# calculate the average age
average_age =df['Age'].mean( )
print(“\nAverage Age:”,average_age)
Output:
Data Frame:
Name Age
0 Alice 24
1 Bob 27
2 Charlie 22
27) Write a program in python to create and display the following data using a
DataFrame by taking input as a list–
Name Age
Alice 24
Bob 27
Charlie 22
Solution:
import pandas as pd
data = [['Alice',24],['Bob',27],['Charlie',22]] #list to store data
df = pd.DataFrame(data,columns=['Name','Age'])
print("Data Frame:")
print(df)
Output:
Same as program(vii)
28) Write a program in python to calculate the mean of an array.
Solution:
import numpy as np
data = np.array([1,2,3,4,5,6,7,8,9,10])#creating a sample array
mean_value = np.mean(data)
print("The mean of the array is:",mean_value)
Output:
The mean of the array is: 5.5
29) Write a Python program that performs the following operations on a list of
integers:
1. Create a list of integers: [10, 20, 30, 40, 50].
2. Append the integer 60 to the list.
3. Insert the integer 25 at index 2.
4. Append elements [22,43] from another list to the above list.
5. Sort the list in ascending order.
6. Search for the integer 30 in the list and print its index.
7. Print the final list.
8. Sort the final list in the descending order.
Solution:
my_list = [10, 20, 30, 40, 50] #creating a list
print(my_list)
my_list.append(60) #appending a number in the list
print(my_list)
my_list.insert(2,25)#inserting a number in the list
print(my_list)
my_list.extend([22,43])#extending the list
print(my_list)
my_list.sort()#sorting the list in ascending order
print(my_list)
if 30 in my_list:
print("Its index =",my_list.index(30))#searching and printing the index of 30
print(my_list)
my_list.sort(reverse=True)#sorting the list in descending order
print(my_list)
Output:
[10, 20, 30, 40, 50]
[10, 20, 30, 40, 50, 60]
[10, 20, 25, 30, 40, 50, 60]
[10, 20, 25, 30, 40, 50, 60, 22, 43]
[10, 20, 22, 25, 30, 40, 43, 50, 60]
Its index = 4
[10, 20, 22, 25, 30, 40, 43, 50, 60]
[60, 50, 43, 40, 30, 25, 22, 20, 10]
30) Write a Python program that performs the following operations on a tuple:
1. Create a tuple with the elements: (5, 10, 15, 20, 25).
2. Access and print the element at index 2.
3. Convert the tuple into a list.
4. Append the integer 30 to the list.
5. Convert the list back into a tuple.
6. Print the final tuple.
Solution:
my_tuple = (5, 10, 15, 20, 25) #creating a tuple
print(my_tuple)
print(my_tuple[2]) #accessing and printing the element at index 2
my_list = list(my_tuple)#converting tuple into list
my_list.append(30)#appending 30 into the list
print(my_list)
my_tuple=tuple(my_list)#converting the list to a tuple
print(my_tuple)#printing the final tuple
Output:
(5, 10, 15, 20, 25)
15
[5, 10, 15, 20, 25, 30]
(5, 10, 15, 20, 25, 30)