1. Write a Python program to reverse a number and also find the sum of digits of the number.
Prompt the user for input.
Number = int(input("Enter any Number: "))
Reverse = 0
Sum=0
while(Number > 0):
Reminder = Number %10
Reverse = (Reverse *10) + Reminder
Sum+=Reminder
Number = Number //10
print("\n Reverse of entered number is =",Reverse)
print("\n Sum of digits is =",Sum)
11. A) Write a Python code to check whether a given year is a leap year or not [An year is a leap year
if it’s divisible by 4 but not divisible by 100 except for those divisible by 400].
year = int(input("Enter a year: "))
# divided by 100 means century year (ending with 00)
# century year divided by 400 is leap year
if (year % 400 == 0) and (year % 100 == 0):
print(year, " is a leap year")
# not divided by 100 means not a century year
# year divided by 4 is a leap year
elif (year % 4 ==0) and (year % 100 != 0):
print("year, " is a leap year"))
# if not divided by both 400 (century year) and 4 (not century year)
# year is not leap year
else:
print(year, " is not a leap year")
11. B) Write a Python program to print the value of 22n+n+5 for n provided by the user.
n=int(input("Enter a number"))
val=2**(2*n)+n+5
print("Result of 2**(2*n)+n+5 is ", val)
12. A) Write a Python program to find the value for sin(x) up to n terms using the series
where x is in degrees
# importing math module
import math
# function which returns sum of sine series
def sumsine(degrees, terms):
# taking a variable which stores sum of sine series
sumSeries = 0
for i in range(terms):
# getting sign
signofNum = (-1)**i
# pie value
pievalue = 22/7
# degree value of given number
degval = degrees*(pievalue/180)
sumSeries = sumSeries + ((degval**(2.0*i+1)) /[Link](2*i+1))*signofNum
# returning the sum of sine series
return sumSeries
degrees = int(input("enter the number of degrees = "))
terms = int(input("enter number of terms = "))
print("The sum of sine series of ", degrees, "degrees", "of", terms, "terms =", round(sumsine(degrees,
terms), 2))
12. B) Write a Python code to determine whether the given string is a Palindrome or not using slicing. Do
not use any string function.
# function to check string is palindrome or not
def isPalindrome(str):
# Run loop from 0 to len/2
for i in range(0, int(len(str)/2)):
if str[i] != str[len(str)-i-1]:
return False
return True
s =input("Enter a string")
ans = isPalindrome(s)
if (ans):
print("Yes. String is palindrome")
else:
print("No. String is not palindrome")
13. A) Write a Python code to create a function called list_of_frequency that takes a string and prints the
letters in non-increasing order of the frequency of their occurrences. Use dictionaries.
Output
13 B) Write a Python program to read a list of numbers and sort the list in a non-decreasing order without
using any built in functions. Separate function should be written to sort the list wherein the name of the list
is passed as the parameter
14 B)Write a Python program to check the validity of a password given by the user.
15 A) Write a program to draw a hexagon using turtle
17 A) Write a Python program to express the instances as return values to define a class RECTANGLE
with parameters height, width, corner_x, and corner_y and member functions to find center, area, and
perimeter of an instance.
18 A) same as 17 A (CIRCLE instead of RECTANGLE)
18 B) Write Python program to create a class called as Complex and implement __add__( ) method to add
two complex numbers. Display the result by overloading the + Operator
19 A) Write a Python program to add two matrices and also find the transpose of the resultant matrix
19 B) Given a file “[Link]” of automobile data with the fields index, company, body-style, wheel-base,
length, engine-type, num-of-cylinders, horsepower, average-mileage, and price, write Python codes using
Pandas to ................................................................
Reading the data file and showing the first five records
import pandas as pd
df = pd.read_csv("Automobile_data.csv")
[Link](5)
1) Clean and Update the CSV file
import pandas as pd
df = pd.read_csv("Automobile_data.csv",
na_values={
'price':["?","n.a"],
'stroke':["?","n.a"],
'horsepower':["?","n.a"],
'peak-rpm':["?","n.a"],
'average-mileage':["?","n.a"]})
print (df)
df.to_csv("Automobile_data.csv")
2) Find the highest priced car of all companies
import pandas as pd
df = pd.read_csv("Automobile_data.csv")
[Link]('company')[['company','price']].max()
3)Print total cars of all companies
import pandas as pd
df = pd.read_csv("Automobile_data.csv")
[Link]('company')['company'].count()
4) Find the average mileage of all companies
import pandas as pd
df = pd.read_csv("Automobile_data.csv")
[Link]('company')[['company','average-mileage']].mean()
20 A) Write Python program to write the data given below to a CSV file.
20 B) Given the sales information of a company as CSV file with the following fields month_number,
facecream, facewash, toothpaste, bathingsoap, shampoo, moisturizer, total_units, total_profit. Write
Python codes to visualize the data as follows
1) Toothpaste sales data of each month and show it using a scatter plot
2) Face cream and face wash product sales data and show it using the bar chart
3) Calculate total sale data for last year for each product and show it using a Pie chart.
import pandas as pd
import [Link] as plt
import os
import numpy as np
import matplotlib
comp_sales_df = pd.read_csv('company_sales_data.csv')
comp_sales_df
# Toothpaste sales data of each month and show it using a scatter plot
[Link](x=comp_sales_df.month_number,
y=comp_sales_df.toothpaste)
[Link](True, linewidth= 2, linestyle = "-")
[Link]("Months Number")
[Link]("Toothpastes sold")
[Link](" Toothpaste sale data each month ")
[Link]([Link](1, 13))
[Link]()
# Face cream and face wash product sales data and show it using the bar
chart
[Link](comp_sales_df.month_number, comp_sales_df.facecream,
label='Facecream',color ='g')
[Link](comp_sales_df.month_number, comp_sales_df.facewash, label=
'Facewash', color = "r" )
[Link]()
[Link]("Months")
[Link]("Sold units number ")
[Link]([Link](1, 13))
[Link]()
#Calculate total sale data for last year for each product and show it using a Pie chart.
new_comp_sales_df =
pd.read_csv('company_sales_data.csv').set_index('month_number')
new_set = new_comp_sales_df[['facecream', 'facewash', 'toothpaste',
'bathingsoap', 'shampoo', 'moisturizer']]
new1 = ['facecream', 'facewash', 'toothpaste', 'bathingsoap', 'shampoo',
'moisturizer']
new_set.sum(axis=0).plot(kind='pie', label= '', figsize=(6,6), autopct
='%1.1f%%')
[Link](" Sales data")
[Link]()