#1.
Write a program to do the arithmetic operations (+, -, *, /, //, %, **) by getting 2 inpu
num1 = int(input('Enter the first number'))
num2 = int(input('Enter the second number'))
res_sum = num1 + num2
res_sub = num1 - num2
res_mul = num1 * num2
res_div = num1 / num2
res_fdiv = num1 // num2
res_rem = num1 % num2
res_exp = num1 ** num2
print('Result of addition', res_sum)
print('Result of subtraction', res_sub)
print('Result of multiplication', res_mul)
print('Result of division', res_div)
print('Result of floor division', res_fdiv)
print('Result of remainder', res_rem)
print('Result of exponent', res_exp)
#1. Write a program to do the arithmetic operations (+, -, *, /, //, %, **) by getting 2
num1 = int(input('Enter the first number'))
num2 = int(input('Enter the second number'))
opr = input('Enter the operator')
if opr=='+':
res_sum = num1 + num2
print('Result of addition', res_sum)
elif opr == '-':
res_sub = num1 - num2
print('Result of subtraction', res_sub)
elif opr=='*':
res_mul = num1 * num2
print('Result of multiplication', res_mul)
elif opr=='/':
res_div = num1 / num2
print('Result of division', res_div)
elif opr=='//':
res_fdiv = num1 // num2
print('Result of floor division', res_fdiv)
elif opr=='%':
res_rem = num1 % num2
print('Result of remainder', res_rem)
elif opr=='**':
res_exp = num1 ** num2
print('Result of exponent', res_exp)
'''2. Evaluate the following expressions: (get the input of A, B and C)
i. A + B ** 2 ** 3 //10
ii. B // 20 + A -10 / 3 % 2
iii. A % 10 // 2 – 25 ** 3
iv. A < B > C
v. A<B and B > C or not(A<C)'''
A = int(input('Enter the first number'))
B = int(input('Enter the second number'))
C = int(input('Enter the third number'))
exp_1 = A + B ** 2 ** 3 //10
exp_2 = B // 20 + A-10 / 3 % 2
exp_3 = A % 10 // 2-25 ** 3
exp_4 = A < B > C
exp_5 = A<B and B > C or not(A<C)
print('Result of', 'A + B ** 2 ** 3 //10', 'is', exp_1)
print('Result of', 'B // 20 + A-10 / 3 % 2', 'is', exp_2)
print('Result of', 'A % 10 // 2-25 ** 3', 'is', exp_3)
print('Result of', 'A < B > C', 'is', exp_4)
print('Result of', 'A<B and B > C or not(A<C)', 'is', exp_5)
#3. To find the sum of odd and even numbers of first 100 numbers.
sum_odd = sum_even = 0
for i in range(1,101):
if i%2==0:
sum_even += i
else:
sum_odd += i
print('The sum of odd numbers from 1 to 100 =', sum_odd)
print('The sum of even numbers from 1 to 100 =', sum_even)
#4. To find the total and average of any 10 numbers.
total=0
for i in range(10):
num = int(input('Enter the numbers'))
total = total + num
avg = total / 10
print('Total = ', total)
print('Average =', avg)
# 5. A grading system is a method of evaluating students' performance based on their marks.
# The system usually divides the entire range of possible marks into segments, with each sect
# Get the input of 3 different subject marks for a student.
# For instance, marks could be translated into grades as follows: Write a python program to i
''' A: 90 and above
B: between 80 and 89
C: between 70 and 79
D: between 60 and 69
E: below 60'''
name = input('Enter the name of the student')
physics = int(input('Enter the Pyhsics mark'))
chem = int(input('Enter the Chemistry mark'))
AI = int(input('Enter the AI mark'))
if physics >= 90 and chem >= 90 and AI>=90:
grade = 'A'
elif physics >= 80 and chem >= 80 and AI>=80:
grade = 'B'
elif physics >= 70 and chem >= 70 and AI>=70:
grade = 'C'
elif physics >= 60 and chem >= 60 and AI>=60:
grade = 'D'
else:
grade = 'E'
print(grade)
#6. Write a program to display the first 15 prime num
c=1
for i in range(2,50):
if i>1:
for j in range(2,i):
if i%j==0:
break
else:
print(i, end=' ')
for i in range(5,1,-1):
for j in range(1,i):
print('*', end=' ')
print()
for i in range(1,5):
for j in range(1,i+1):
print(j, end=' ')
print()
#1. Write a program to create a numpy array by the following:
#a. Using list of tuples
#b. Getting input from the user and empty()
import numpy as np
l1=[(12,13,14), (1,2,3), (10,20,30)]
n1=np.array(l1)
print(n1)
n=int(input('Enter the size of the numpy array'))
x=np.empty(n)
print(x)
for i in range(n):
x[i]=int(input('Enter the number'))
print(x)
# 2. Write a program to create a dataframe by the following:
#a. Using numpy array
#b. Using list of dictionaries
import pandas as pd
import numpy as np
d1=np.array([[12,34,67,78],[45,56,67,78], [78,89,90,91]])
df=pd.DataFrame(d1)
df.index=['row1','row2','row3']
df.columns=['col1','col2','col3','col4']
print(df)
#b. Using list of dictionaries
dict1={'col1':12, 'col2':34,'col3':67,'col4':78}
dict2={'col1':45, 'col2':56,'col3':67,'col4':78}
dict3={'col1':78, 'col2':89,'col3':90,'col4':91}
list1=[dict1, dict2, dict3]
df=pd.DataFrame(list1,index=['row1','row2','row3'])
print(df)
# 3. df
import pandas as pd
dict1 = {'Name': ['Tania', 'Papia', 'Arnab', 'Anurag'],
'Course': ['Data Science','Java', 'Python','Machine Learning'],
'Age': [20,21,19,28],
XI AI PROGRAMS file:///C:/Users/adity/Downloads/XI%20AI%20PROGRAMS(2).html
'College': ['JNU', 'BHU','DU','IIT']}
df=pd.DataFrame(dict1)
print(df)
#To add a new row with the entries ‘Sonia’, ‘AI’, 18, ‘DU’
df.loc[4]= ['Sonia','AI', 18, 'DU']
print(df)
#To add a column phone_no (assume your own data)
df['Phone_no']= [9876544321, 8765433222, 9765428762, 9034876511, 9367182343]
print(df)
#To delete a row with the index 1
df=df.drop(1, axis=0)
print(df)
#To delete a column ‘Course’
df=df.drop('Course', axis=1)
print(df)
#To display the course name for the index 2.
print(df.loc[2])
#To display the entries for the student ‘Tania’
print(df.iloc[0])
6 of 11 12-09-2024, 17:35
XI AI PROGRAMS file:///C:/Users/adity/Downloads/XI%20AI%20PROGRAMS(2).html
7 of 11 12-09-2024, 17:35
#4. df
import pandas as pd
dict1={'P':[np.NaN, 3, 5, np.NaN],
'Q':[2,4,np.NaN,4],
'R':[np.NaN,np.NaN, np.NaN,np.NaN],
'S':[0,1,6,5]}
df=pd.DataFrame(dict1)
print(df)
#Finding any missing value in a column 'P'
print(df['P'].isnull().any())
#Finding total number of NaN
print(df.isnull().sum())
#Deleting entire row with NaN values
print(df.dropna())
#Replacing NaN values by 1
print(df.fillna(1))
# 5. df
import pandas as pd
n1 = np.array([['Jack', 34, 'Sydney', 'Australia', 'Computer Science', 'A'],
['Riti', 30, 'Delhi', 'India', 'Computer Science', 'A'],
['Tom', 31, 'Mumbai', 'India', 'Computer Science', 'A'],
['Neelu', 32, 'Bangalore', 'India', 'Computer Science', 'A'],
['John', 16, 'New York', 'US', 'Computer Science', 'A'],
['Mike', 17, 'las vegas', 'US', 'Computer Science', 'A']])
df=pd.DataFrame(n1,columns=['Name','Age', 'City', 'Country','Course','Grade'], index
print(df)
print('Index =', df.index)
print()
print('Columns =', df.columns)
print()
print('Axes =', df.axes)
print()
print('Datatype =', df.dtypes)
print()
print('Size =', df.size)
print()
print('Shape =', df.shape)
print()
print('Values =', df.values)
print()
print('Empty =', df.empty)
print()
print('Dimension =', df.ndim)
print()
print('Transpose =', df.T)
print()
print('Length =', len(df))
print()
print('Count =', df.count())
print()
XI AI PROGRAMS file:///C:/Users/adity/Downloads/XI%20AI%20PROGRAMS(2).html
10 of 11 12-09-2024, 17:35