PDA Assignments
  • Python For Data Analytics
    • 1.Python
      • 1.Python Documents
        • 1.Data Types
        • 2.Variables In Python
        • 3.Operators In Python
        • 4.User Input In Python
        • 5.TypeCasting In Python
        • 6.Strings In Python
        • 7.Conditional Statements In Python
        • 8.Branching using Conditional Statements and Loops in Python
        • 9.Lists In Python
        • 10.Sets In Python
        • 11.Tuples In Python
        • 12.Dictionary In Python
        • 13.Functions In Python
        • 14.File Handling In Python
        • 15.Numerical Computing with Python and Numpy
      • 2.Python Assignments
        • Data Type & Variables
        • Operators Assignment
        • User Input & Type Casting
        • Functions- Basic Assignments
        • String Assignments
          • String CheatSheet
        • Conditional Statements Assignments
        • Loops Assignments
        • List Assignments
          • List Cheatsheet
        • Set Assignments
          • Sets Cheatsheet
        • Dictionary Assignments
          • Dictionary Cheatsheet
        • Function Assignments
        • Functions used in Python
      • 3.Python Projects
        • Employee Management System
        • Hamming distance
        • Webscraping With Python
          • Introduction To Web Scraping
          • Importing Necessary Libraries
          • Basic Introduction To HTML
          • Introduction To BeautifulSoup
          • Flipkart Web Scraping
            • Scraping Step By Step
        • Retail Sales Analysis
        • Guess the Word Game
        • Data Collection Through APIs
        • To-Do List Manager
        • Atm-functionalities(nested if)
        • Distribution of Cards(List & Nested for)
        • Guess the Number Game
      • 4.Python + SQL Projects
        • Bookstore Management System
    • 2.Data Analytics
      • 1.Pandas
        • 1.Pandas Documents
          • 1.Introduction To Pandas
          • Reading and Loading Different Data
          • 2.Indexing and Slicing In Pandas
          • 3.Joining In Pandas
          • 4.Missing Values In Pandas
          • 5.Outliers In Pandas
          • 6.Aggregating Data
          • 7.DateTime In Pandas
          • 8.Validation In Pandas
          • 9.Fetching Data From SQL
          • 10. Automation In Pandas
          • 11.Matplotlib - Data Visualization
          • 12. Seaborn - Data Visualization
          • 13. Required Files
        • 3.Pandas Projects
          • Retail Sales Analysis
            • Retail Sales Step By Step
          • IMDB - Dataset Analysis - Basic
        • 2. Pandas Assignments
          • 1. Reading and Loading the Data
          • 2. Data frame Functions and Properties
          • 3. Series - Basic Operations
          • 4. Filtering in Pandas
          • 5. Advance Filtering
          • 6. Aggregate Functions & Groupby
          • 7. Pivot Tables
          • 8. Datetime
          • 9. String Functions
Powered by GitBook
On this page
  1. Python For Data Analytics
  2. 1.Python
  3. 2.Python Assignments

Functions- Basic Assignments

PreviousUser Input & Type CastingNextString Assignments

Last updated 6 months ago

  1. Create a non-return type function that takes the user's name and display the message "Hello user! Welcome to Python Functions"

Solution
def greeting(user_name):
    print('Hello',user_name,'!Welcome to Python Functions')
    
name=input('Enter your name:')
greeting(name)
  1. Create a non-return type function that takes the details of user like name,age, city, company, and profile and display the message- "Hello Python, I am name. I am age years old. I am a profile in company"

Solution
def introduction(user_name,user_age,user_profile,user_company):
    print('Hello Python, I am',user_name,'.I am',user_age,'years old. I am a',user_profile,'in',user_company,'.')

name=input('Enter your name:')
age=int(input('Enter your age:'))
profile=input('Enter Your profile:')
company=input('Enter your company:')

introduction(name,age,profile,company)
  1. Create a return type function that takes the length and breadth of a rectangle and calculate area of the rectangle.

Solution
def area_of_rectangle(length,breadth):
    area=length * breadth
    return area

length=int(input('Length of the rectangle:'))
breadth=int(input('breadth of the rectangle:'))

print('Area of the rectangle is ',area_of_rectangle(length,breadth))
  1. Create a return type function that takes weight and height of a user and return the bmi of the user. Depending upon the bmi show the category that the custimer belongs to.

Solution
def calculate_BMI(weight,height):
    bmi=round(weight / height ** 2 * 10000)
    return bmi


w=int(input('enter Weight:'))
h=int(input('enter height:'))
bmi=calculate_BMI(w,h)
print('Your BMI is:',bmi)

print('Your Category:')

print('Underweight:',bmi<18.5)
print('Normal range:',bmi>=18.5 and bmi<=24.9)
print('Overweight:',bmi>=25.0 and bmi<=29.9)
print('Obese:',bmi>=30)
  1. Create a return type function that takes principle, rate, and time from the user and then return simple interest after calculation.Afterwards Calculate amount that the user has to repay.

Solution
def calculate_simple_interest(principle,rate,time):
    simple_interest=principle * rate * time / 100
    return simple_interest

principle=int(input('Enter principle:'))
rate=int(input('Enter Rate:'))
time=int(input('Enter time:'))

si=calculate_simple_interest(principle,rate,time)
print('Your interest charged will be:',si)

amount=principle + si
print('Amount you will repay is',amount,'Rs')
  1. Create a return function that takes the radius and height of a cylinder and return the total surface area. TSA = 2πr*(r + h).

Solution
def total_surface_area_cylinder(radius,height,pi=3.14):
    total_surface_area = 2 * pi * radius *(radius + height)
    return total_surface_area

radius= int(input('Enter radius of the cylinder:'))
height= int(input('Enter height of the cylinder:'))

print('the total surface area of the cylinder is',total_surface_area_cylinder(radius,height))
  1. Create a function that takes the radius and height of a cone and return the volume. V=1/3hπr²

Solution
def volume_of_cone(radius,height,pi=3.14):
    volume = (pi * radius ** 2 * height) * 1 / 3
    return volume


radius= int(input('Enter radius of the cone:'))
height= int(input('Enter height of the cone:'))


v= volume_of_cone(radius,height)
print('Volumeof the cone',v)
  1. Create a function that returns the quotient and remainder after dividing two numbers.

Solution
def calculate_quotient_remainder(num1,num2):
    res1=num1//num2
    res2=num1%num2
    return res1,res2

a=int(input('enter first number:'))
b=int(input('enter second number:'))

quot,rem=calculate_quotient_remainder(a,b)

print('quotient:',quot)
print('remainder:',rem)
  1. Create a return type function that takes marks of 5 subjects from a student and calculates the percentage of the student.

Solution
def percentage(m1,m2,m3,m4,m5):
    sum=m1+m2+m3+m4+m5
    percent= sum * 100/500
    return percent

phys=int(input('Enter Physics marks:'))
chem=int(input('Enter chemistry marks:'))
maths=int(input('Enter maths marks:'))
hindi=int(input('Enter hindi marks:'))
english=int(input('Enter english marks:'))

per=percentage(phys,chem,maths,hindi,english)

print('Your percentage is:',per,'%')
  1. Create a function called create_bill that takes product name,price, and qty and return the bill.

Solution
def create_bill(product_name,product_price,product_qty):
    bill=product_price * product_qty
    return bill

product=input('enter name of the product:')
price=int(input('enter price:'))
quantity=int(input('Enter quantity:'))

amount=create_bill(product,price,quantity)

print('The bill of',product,'of',price,'Rs for',quantity,'pieces is Rs',amount)