Python Aat Sukruthi KC
Python Aat Sukruthi KC
Python Aat Sukruthi KC
Report is submitted for the fulfillment of the AAT Work in the subject
“Python Programming”
(22MCA1PCPY)
Of
I Semester
MCA
By
RV RAGHAVENDRA RAO
(Assistant Professor)
TABLE OF CONTENTS
24. Develop a program to print non-eligible student roll num and percentage of attendance
by using dictionary Comprehension Consider the dictionary Attendance = {‘01’:60,
‘02’:76, ‘03’:34, ‘08’:77, ‘04’:75, ‘05’:80, ‘06’:100} With student id, percentage as key
value pair and 75 is the required percentage to get eligibility.
25. Find the min and max score of a subject by using dictionary comprehension Consider
the following data Marks = {‘OS’:[10,12,8,19], ‘python’:[8,12,9,15,14],
‘DSA’:[23,77,12,6,12], ‘MFCA’:[8,9,12,17], ‘COA’:[12,15,17,19] }
26. Create a Python class called Bank Account which represents a bank account, having as
attributes: accountNumber (numeric type), Name (name of the account owner as a string
type), balance. Create a constructor with the accountNumber, name, and balance
parameters. Create a Deposit() method that manages the deposit actions. Create a
Withdrawal() method that manages withdrawal actions. Create a bankFees () method to
apply the bank fees with a percentage of 5% of the balance account. Create a display()
method to display account details.
27. Create a function that takes a number as an argument, increments the number by +1 and
returns the result.
28. Write a program to calculate the age of the user, by receiving the user's DOB as input
and using functions.
29. Develop a program for conversion. CM to Inches (and vice versa), Meters to
Kilometers (and vice versa), Grams to Kilograms (and vice versa). Initially, you need to
collect input from the user by displaying the above options for conversion procedures and
perform accordingly.
30. "A Bachelor of Engineering in Computer Science from BMS College of Engineering in
Karnataka, 29-year-old Amrith was part of the National Cadet Corps's Republic Day team
in 2008 and harboured the dream of being part of the marching contingents of one of the
three services at the celebrations in Delhi." Apply all possible string handling operations to
the above data. Identify the length of the data, number of words, and print each word and
how many times it appeared in the data shared
OUTPUT:
def convert(c):
f = (9.5)*c + 32
return(F)
cel=float(input("Enter the temperature: "))fah=convert(cel)
print("The temperature in fahrenheit is",Fah)
OUTPUT:
3) Python program to find the area of a triangle whose sides are given
OUTPUT:
OUTPUT:
p=0
product = 1
count = int(input("Enter numbers="))for i in
range(count):
x = float(input("Enter num="))
product = product * x
print("product is=",product)
OUTPUT
pi=3.14
r=int(input("enter the radius of circle: "))
y= int(input("Type number="))
if(y%5==0):
print("Yes")
else:
print("No")
OUTPUT
OUTPUT:
while count<10:
n = float(input("Number " + str(count + 1) + ": "))sum = sum + n
count = count + 1
average = sum/10
print(f 'The average of these numbers is: {average}')
OUTPUT:
o = 9724
rev = 0
while(o<0):
a = o %10
rev = rev * 10 + ao = o
// 10
print(rev)
OUTPUT
numbers = []
n=int(input("Enter the range"))
for i in range(n):
j=int(input("Enter number "+str(i+1)+":"))
numbers.append(j)
largest = numbers[0]
for num in numbers[1:]:
if num > largest:
largest = num
12) Python program to find the sum of the digits of an integer using a while loop
def sum1():
sum = 0
number = int(input("Enter an integer: "))
while(number!=0):
digit = number%10
sum = sum+digit
number = number//10
print("Sum of digits is: ", sum)
sum1()
OUTPUT:
13) Python program to display all the multiples of 3 within the range 10 to 50
for i in range(10,50):
if (i%3==0):
print(i)
OUTPUT:
14)Python program to display all integers within the range 100-200 whose sum of
digits is an even number
for i in range(100,200):
num = i
sum = 0
while(num!=0):
digit = num%10
sum = sum + digit
num = num//10
if(sum%2==0):
print(i)
OUTPUT:
15) Python program to check whether the given integer is a prime number or not
OUTPUT:
OUTPUT:
import math
a = float(input("Enter the first coefficient: "))
b = float(input("Enter the second coefficient: "))
c = float(input("Enter the third coefficient: "))
if (a!=0):
d = (b*b)-(4*a*c)
if (d==0):
print("The roots are real and equal.")
r = -b/(2*a)
print("The roots are ", r,"and", r)
elif(d>0):
print("The roots are real and distinct.")
r1 = (-b+(math.sqrt(d)))/(2*a)
r2 = (-b-(math.sqrt(d)))/(2*a)
print("The root1 is: ", r1)
print("The root2 is: ", r2)
else:
print("The roots are imaginary.")
realpart = -b/(2*a)
imaginarypart = math.sqrt(-d)/(2*a)
print("The root1 is: ", realpart, "+ i",imaginarypart)
print("The root2 is: ", realpart, "- i",imaginarypart)
else:
print("Not a quadratic equation.")
OUTPUT:
18) Python program to print the numbers from a given number n till 0 using
recursion
def count(n):
if n >= 0:
count(n - 1)
print(n)
num=int(input("Enter the number"))
count(num)
OUTPUT:
def fact(n):
if n==1:
return 1
else:
return n * fact(n-1)
total = 0
numbers=[]
num = int(input("Enter the range"))
for n in range(num):
x = int(input("Enter number"))
numbers.append(x)
for ele in range(0, len(numbers)):
total = total + numbers[ele]
print("Sum of all elements in given list: ", total)
OUTPUT:
21) Python program to find largest number in a list without using built in functions
numbers = []
n=int(input("Enter the range"))
for i in range(n):
j=int(input("Enter number "+str(i+1)+":"))
numbers.append(j)
largest = numbers[0]
for num in numbers[1:]:
if num > largest:
largest = num
emails = []
for i in range(10):
email = input("Enter email " + str(i+1) + ": ")
emails.append(email)
print(updated_emails)
OUTPUT
for x in init:
print(x,end="")
OUTPUT
attendance = {'01':60,'02':76,'03':34,'08':77,'04':75,'05':80,'06':100}
not_eligible = {key: value for key, value in attendance.items() if value < 75}
result = {"Roll number " + str(key) + " has attendance percentage " + str(value) + "%" for
key, value in not_eligible.items()}
OUTPUT:
marks = {'OS': [10, 12, 8, 19], 'Python': [8, 12, 9, 15, 14], 'DSA': [23, 77, 12, 6, 12],
'MFCA': [8, 9, 12, 17], 'COA': [12, 15, 17, 19]}
OUTPUT:
26) Create a Python class called Bank Account which represents a bank
account, having as attributes: accountNumber (numeric type),
Name (name of the account owner as a string type), balance.
Create a constructor with the accountNumber, name, and balance
parameters.
Create a Deposit() method that manages the deposit actions.
Create a Withdrawal() method that manages withdrawal actions.
Create a bankFees () method to apply the bank fees with a percentage of 5%
of the balance account.
Create a display() method to display account details.
class BankAccount:
def init (self, accountNumber, name, balance):
self.accountNumber = accountNumber
self.name = name
self.balance = balance
else:
print("Invalid amount. Please enter a valid amount.")
def bankFee(self):
fee = 0.05 * self.balance
self.balance -= fee
print("Bank fees of 5% applied. New balance is:", self.balance)
def display(self):
print("Account Details:")
print("Account Number:", self.accountNumber)
print("Account Holder Name:", self.name)
print("Account Balance:", self.balance)
OUTPUT:
OUTPUT:
28) Write a program to calculate the age of the user, by receiving the user's
DOB as input and using functions.
import datetime
def calculate_age(birthdate):
today = datetime.date.today()
age = today.year - birthdate.year - ((today.month, today.day) < (birthdate.month,
birthdate.day))
return age
age = calculate_age(birthdate)
print("Your age is:", age)
OUTPUT:
def cm_to_inches(cm):
return cm / 2.54
def inches_to_cm(inches):
return inches * 2.54
def meters_to_kilometers(meters):
return meters / 1000
def kilometers_to_meters(kilometers):
return kilometers * 1000
def grams_to_kilograms(grams):
return grams / 1000
def kilograms_to_grams(kilograms):
return kilograms * 1000
print("1. CM to inches")
print("2. Inches to CM")
print("3. Meters to Kilometers")
print("4. Kilometers to Meters")
print("5. Grams to Kilograms")
print("6. Kilograms to Grams")
if choice == 1:
OUTPUT:
National Cadet Corps's Republic Day team in 2008 and harboured the
dream of being part of the marching contingents of one of the three services
at the celebrations in Delhi."
Apply all possible string handling operations to the above data. Identify the
length of the data, number of words, and print each word and how many
times it appeared in the data shared.
OUTPUT:
import pandas as pd
pd.read_csv("data.csv")
df=pd.read_csv("data.csv")
df
1/16
work_year experience_level employment_type job_title salary salary_currency salary_in_usd
df.head(n=5) Principal
0 2023 SE FT Data 80000 EUR 85847
Scientist
work_year experience_level employment_type job_t tle salary salary_currency salary_in_usd emp
ML
1 2023 MI CT 30000 USD 30000
Prin ipal
Engineer
0 2023 SE FT Data 80000 EUR 85847
Sci ntist ML
2 2023 MI CT 25500 USD 25500
Engineer
ML
1 2023 MI CT 30000 USD 30000
Data
3 2023 SE FT Eng neer 175000 USD 175000
Scientist
ML
2 2023 MI CT 25500 USD 25500
Data
4 2023 SE FT Eng neer 120000 USD 120000
Scientist
Data
3 2023 SE FT 175000 USD 175000
... ... ... ... Sci ntist ... ... ... ...
DataData
3750
4 2020
2023 SE SE FT FT 120000
412000 USDUSD 120000
412000
Scientist
Scientist
Principal
3751 2021 MI FT Data 151000 USD 151000
Scientist
Data
3752 2020 EN FT 105000 USD 105000
df.tail(n=5) Scientist
Business
3753 work_year
2020 experience_level
EN employment_type
CT job_title
Data salary salary_currency
100000 USD salary_in_usd
100000
Analyst
Data
3750 2020 SE FT 412000 USD 412000
Scientist
Data
3754 2021 SE FT Science 7000000 INR 94665
Principal
Manager
3751 2021 MI FT Data 151000 USD 151000
3755 rows × 11 columns Scientist
Data
3752 2020 EN FT 105000 USD 105000
Scientist
Business
3753 2020 EN CT Data 100000 USD 100000
Analyst
Data
3754 2021 SE FT Science 7000000 INR 94665
Manager
df.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 3755 entries, 0 to 3754
Data columns (total 11 columns):
# Column Non-Null Count Dtype
2/16
3 job_title 3755 non-null object
4 salary 3755 non-null int64
5 salary_currency 3755 non-null object
6 salary_in_usd 3755 non-null int64
7 employee_residence 3755 non-null object
8 remote_ratio 3755 non-null int64
9 company_location 3755 non-null object
10 company_size 3755 non-null object
dtypes: int64(4), object(7)
memory usage: 322.8+ KB
df.sample(5)
Analytics
117 2023 SE FT 289800 USD
Engineer
Data
1846 2022 SE FT 51000 USD
Scientist
Data
519 2023 SE FT 275300 USD
Scientist
Data 106800
2076 2022 SE FT USD
Engineer
Data
759 2023 SE FT Operations 193000 USD
Engineer
df.describe()
df.isnull()
3/16
work_year experience_level employment_type job_title salary salary_currency salary_in_usd
Ap lied
5 2023 SE FT 222200 USD 222200
Sc ntist
Ap lied
6 2023 SE FT 136000 USD 136000
Sc ntist
Data
12 2023 SE FT 100000 USD 100000
An lyst
Data
18 2023 SE FT 150000 USD 150000
Sci ntist
Data
19 2023 MI FT 150000 USD 150000
An lyst
Data
29 2023 SE FT 90000 USD 90000
df.iloc[2:8]
4/16
work_year experience_level employment_type job_title salary salary_currency salary_in_usd emp
ML
2 2023 MI CT 25500 USD 25500
Engineer
Data
3 2023 SE FT 175000 USD 175000
Scientist
Data
4 2023 SE FT 120000 USD 120000
Scientist
Applied
5
df.columns 2023 SE FT 222200 USD 222200
Scientist
Applied 'job_title',
Index(['work_year', 'experience_level', 'employment_type',
6 2023 SE FT 136000 USD 136000
'salary', 'salary_currency', 'salary_in_usd', 'employee_residence',
Scientist
'remote_ratio', 'company_location', 'company_size'],
dtype='object') Data
7 2023 SE FT 219000 USD 219000
Scientist
Princ pal
0 2023 SE FT Dta 80000 EUR 85847
Scie tist
ML
1 2023 MI CT 30000 USD 30000
Engi eer
ML
2 2023 MI CT 25500 USD 25500
Engi eer
D ta
3 2023 SE FT 175000 USD 175000
Scie tist
ta
4 2023 SE FT 120000 USD 120000
Scientist
df.drop(
labels=[5,7,12,18,27],
axis=0,
inplace=True
)
df
5/16
work_year experience_level employment_type job_t tle salary salary_currency salary_in_usd
Prin ipal
0 2023 SE FT Data 80000 EUR 85847
Scie tist
ML
1 2023 MI CT 30000 USD 30000
Engi eer
ML
2 2023 MI CT 25500 USD 25500
Engi eer
Data
3 2023 SE FT 175000 USD 175000
Scie tist
Data
4 2023 SE FT 120000 USD 120000
Scie tist
Data
3750 2020 SE FT 412000 USD 412000
Scie tist
Prin ipal
3751 2021 MI FT Data 151000 USD 151000
Scie tist
Data
3752 2020 EN FT 105000 USD 105000
Scientist
len(df) Business
3753 2020 EN CT Data 100000 USD 100000
3750 Analyst
Data
df.query("salary
3754 > salary_in_usd")
2021 SE FT Science 7000000 INR 94665
Manager
6/16
work_year experience_level employment_type job_title salary salary_currency salary_in_usd
Machine
41 2022 MI FT Learning 1650000 INR 20984
Engineer
Data
80 2023 MI FT 510000 HKD 65062
Scientist
Applied
156 2023 MI FT Data 1700000 INR 20670
Scientist
Data
217 2023 EN FT 1400000 INR 17022
df.sort_values(by="work_year")
Engineer
Applied
work_year experience_level employment_type job_t tle salary salary_currency salary_in_usd
218 2023 SE FT Data 100000 AUD 68318
Scientist
Staff Data
183 2020 EX FT 15000 USD 15000
An lyst
... ... ... ... ... ... ... ...
Data
3548 2020 EN FT Computer 10000 USD 10000
An lyst
3723 2021 SE FT Vision 102000 BRL 18907
Engineer
Ma hine
3549 2020 EN FT Lea ning
AI 138000 USD 138000
3729 2021 EN FT Eng neer 1335000 INR 18053
Scientist
Data
3681 2020 MI FT Lead Data 8000 USD 8000
3734 2021 MI FT An lyst 1450000 INR 19609
Analyst
Data
Data
3682
3746 2020
2021 EN
MI FT
FT 4450000
160000 JPY
SGD 41689
119059
Eng neer
Scientist
... ... ... ... ... ... ... ...
Data
3754 2021 SE FT Science
Data 7000000 INR 94665
1212 2023 SE FT Manager 170000 USD 170000
Eng neer
Data
1214 2023 SE FT 108000 USD 108000
An lyst
Data
1202 2023 SE FT Sci ntist 182200 USD 182200
Prin ipal
0 2023 SE FT Data 80000 EUR 85847
Scientist
df.replace('USD', 'IND')
7/16
work_year experience_level employment_type job_t tle salary salary_currency salary_in_usd
Prin ipal
0 2023 SE FT Data 80000 EUR 85847
Scie tist
ML
1 2023 MI CT 30000 IND 30000
Engi eer
ML
2 2023 MI CT 25500 IND 25500
Engi eer
Data
3 2023 SE FT 175000 IND 175000
Scie tist
Data
4 2023 SE FT 120000 IND 120000
Scie tist
Data
3750 2020 SE FT 412000 IND 412000
Scie tist
Prin ipal
3751 2021 MI FT Data 151000 IND 151000
Scie tist
Data
3752 2020 EN FT 105000 IND 105000
Scie tist
Busi ess
3753 2020 EN CT Data 100000 IND 100000
Analyst
Data
3754 2021 SE FT Science 7000000 INR 94665
Manager
df.groupby("job_title")['salary'].sum()
3750 rows × 11 columns
job_title
3D Computer Vision Researcher 480000
AI Developer 1509000
AI Programmer 110000
AI Scientist 4405000
Analytics Engineer 15589320
...
Research Engineer 6021854
Research Scientist 13183049
Software Data Engineer 150000
Staff Data Analyst 15000
Staff Data Scientist 105000
Name: salary, Length: 93, dtype: int64
df.count(0)
work_year 3750
experience_level 3750
employment_type 3750
job_title 3750
salary 3750
salary_currency 3750
salary_in_usd 3750
employee_residence 3750
remote_ratio 3750
company_location 3750
8/16
company_size 3750
dtype: int64
df.shape
(3750, 11)
df['salary'].mean()
190712.1792
df.select_dtypes(include='int64')
pd.read_csv("industry.csv")
df1=pd.read_csv("industry.csv")
df1
9/16
Industry
0 Accounting/Finance
1 Advertising/Public Relations
2 Aerospace/Aviation
3 Arts/Entertainment/Publishing
4 Automotive
5 Banking/Mortgage
6 Business Development
7 Business Opportunity
8 Clerical/Administrative
9 Construction/Facilities
10 Consumer Goods
11 Customer Service
12 Education/Training
13 Energy/Utilities
14 Engineering
15 Government/Military
16 Green
17 Healthcare
18 Hospitality/Travel
19 Human Resources
20 Installation/Maintenance
21 Insurance
22 Internet
24 Law Enforcement/Security
25 Legal
26 Management/Executive
27 Manufacturing/Operations
28 Marketing
29 Non-Profit/Volunteer
30 Pharmaceutical/Biotech
31 Professional Services
32 QA/Quality Control
33 Real Estate
34 Restaurant/Food Service
10/16
35 Retail
df1.head(n=5)
36 Sales
37 Science/Research
Industry
38
0 Skilled Labor
Accounting/Finance
39 Technology
1 Advertising/Public Relations
40
2 Telecommunications
Aerospace/Aviation
41 Transportation/Logistics
3 Arts/Entertainment/Publishing
42 Other
4 Automotive
df1.tail(n=5)
Industry
38 Skilled Labor
39 Technology
40 Telecommunications
41 Transportation/Logistics
42 Other
df1.sample(5)
Industry
23 Job Search Aids
9 Construction/Facilities
4 Automotive
30 Pharmaceutical/Biotech
31 Professional Services
df1.columns
Index(['Industry'], dtype='object')
name=df1['Industry']
print(name)
0 Accounting/Finance
1 Advertising/Public Relations
2 Aerospace/Aviation
3 Arts/Entertainment/Publishing
4 Automotive
5 Banking/Mortgage
6 Business Development
7 Business Opportunity
8 Clerical/Administrative
9 Construction/Facilities
10 Consumer Goods
11/16
11 Customer Service
12 Education/Training
13 Energy/Utilities
14 Engineering
15 Government/Military
16 Green
17 Healthcare
18 Hospitality/Travel
19 Human Resources
20 Installation/Maintenance
21 Insurance
22 Internet
23 Job Search Aids
24 Law Enforcement/Security
25 Legal
26 Management/Executive
27 Manufacturing/Operations
28 Marketing
29 Non-Profit/Volunteer
30 Pharmaceutical/Biotech
31 Professional Services
32 QA/Quality Control
33 Real Estate
34 Restaurant/Food Service
35 Retail
36 Sales
37 Science/Research
38 Skilled Labor
39 Technology
40 Telecommunications
41 Transportation/Logistics
42 Other
Name: Industry, dtype: object
df1[3:10]
Industry
3 Arts/Entertainment/Publishing
4 Automotive
5 Banking/Mortgage
6 Business Development
7 Business Opportunity
8 Clerical/Administrative
9 Construction/Facilities
df1.loc[[2,4,6,7,8,9,19 ]]
12/16
Industry
2 Aerospace/Aviation
4 Automotive
df1.iloc[2:13]
6 Business Development
7 Business Opportunity
Industry
8 Clerical/Administrative
2 Aerospace/Aviation
9 Construction/Facilities
3 Arts/Entertainment/Publishing
19
4 Human Resources
Automotive
5 Banking/Mortgage
6 Business Development
7 Business Opportunity
8 Clerical/Administrative
9 Construction/Facilities
10 Consumer Goods
11 Customer Service
12 Education/Training
import numpy as np
df5 = pd.DataFrame([[
np.nan, 2, np.nan, 0],
[3, 4, np.nan, 1],
[np.nan, np.nan, np.nan, 5],
[np.nan, 3, np.nan, 4]],
)
print(df1)
Industry
0 Accounting/Finance
1 Advertising/Public Relations
2 Aerospace/Aviation
4 Automotive
5 Banking/Mortgage
6 Business Development
7 Business Opportunity
8 Clerical/Administrative
11 Customer Service
14 Engineering
15 Government/Military
16 Green
17 Healthcare
18 Hospitality/Travel
19 Human Resources
20 Installation/Maintenance
21 Insurance
22 Internet
23 Job Search Aids
24 Law Enforcement/Security
25 Legal
13/16
26 Management/Executive
27 Manufacturing/Operations
28 Marketing
29 Non-Profit/Volunteer
30 Pharmaceutical/Biotech
31 Professional Services
32 QA/Quality Control
33 Real Estate
34 Restaurant/Food Service
35 Retail
36 Sales
37 Science/Research
38 Skilled Labor
39 Technology
40 Telecommunications
41 Transportation/Logistics
42 Other
df1.fillna(0)
14/16
Industry
0 Accounting/Finance
1 Advertising/Public Relations
2 Aerospace/Aviation
4 Automotive
5 Banking/Mortgage
6 Business Development
7 Business Opportunity
8 Clerical/Administrative
11 Customer Service
14 Engineering
15 Government/Military
16 Green
17 Healthcare
18 Hospitality/Travel
df1.drop(
19 Human Resources
labels=[ 3,9,10,12,13],
axis=0,
20 Installation/Maintenance
inplace=True
) 21 Insurance
df1
22 Internet
24 Law Enforcement/Security
25 Legal
26 Management/Executive
27 Manufacturing/Operations
28 Marketing
29 Non-Profit/Volunteer
30 Pharmaceutical/Biotech
31 Professional Services
32 QA/Quality Control
33 Real Estate
34 Restaurant/Food Service
35 Retail
36 Sales
37 Science/Research
38 Skilled Labor
39 Technology
15/16
40 Telecommunications
Industry
41 Transportation/Logistics
0 Accounting/Finance
42 Other
1 Advertising/Public Relations
2 Aerospace/Aviation
4 Automotive
5 Banking/Mortgage
6 Business Development
7 Business Opportunity
8 Clerical/Administrative
11 Customer Service
14 Engineering
15 Government/Military
16 Green
17 Healthcare
18 Hospitality/Travel
19 Human Resources
20 Installation/Maintenance
21 Insurance
22 Internet
24 Law Enforcement/Security
25 Legal
26 Management/Executive
27 Manufacturing/Operations
28 Marketing
29 Non-Profit/Volunteer
30 Pharmaceutical/Biotech
31 Professional Services
32 QA/Quality Control
33 Real Estate
34 Restaurant/Food Service
35 Retail
36 Sales
37 Science/Research
38 Skilled Labor Colab paid products - Cancel contracts here0s
completed at 9:44 PM
16/16
22MCA1PCPY:Python Programming
32)
35) Consider the dataset, and perform the tasks defined below.
a) Read Total profit of all months and show it using a line plot
b) Read toothpaste sales data of each month and show it using a
scatter plot
Solution:
1. Using the data given below, develop scatter plot, line chart, bar
chart.
Solution:
2. Using python tkinter, design the following UI.
solution: