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

User Input & Type Casting

PreviousOperators AssignmentNextFunctions- Basic Assignments

Last updated 24 days ago

  1. Take the name from the user and greet him in this form - Hello, username

Solution
name = input('Enter Your Name : ')
print('Hello,', name)
  1. Take input of the length and breadth of a rectangle from the user and print the area of it.

Solution

length = float(input('Enter the length : '))

breadth = float(input('Enter the breadth : '))

area = length * breadth

print('Area :', area)

  1. Body mass index (BMI) is a measure of body fat based on height and weight that applies to adult men and women. The Table below shows how healthy you are with respect to your BMI.

The Formula That we use For BMI is :

bmi=weight(kgs)/height(cms)2∗10000bmi = weight(kgs)/height(cms)^2*10000bmi=weight(kgs)/height(cms)2∗10000

Take Weight and height from the user and Calculate BMI.​

Solution

First we will take weight and height from user with the help of user input.

weight = int(input('Enter your weight : '))

height = int(input('Enter your height : '))

Then we will calculate BMI , Now say if we want only two decimal values , we can use round() Function.

bmi = round(weight / height ** 2 * 10000)

print('Your BMI is',bmi)

4. Take Principle, Rate, and Time From User and Calculate Simple Interest.

Formula For Simple Interest is:

SimpleInterest=Principle∗Rate∗Time/100Simple Interest = Principle * Rate * Time / 100SimpleInterest=Principle∗Rate∗Time/100
Solution

principle = int(input('Enter the amount : '))

rate = int(input('Rate : '))

time = int(input('Time : '))

simple_interest = principle * rate * time / 100

print('Simple Interest is',simple_interest)

5. Your task is to take name and age and location from user and print the following message :

Hello Everyone , I am xyz and i am xyz years old and i live in xyz.

Solution

name = input('Enter your name : ')

age = input('What is your age ? ')

location = input('Where do you live ? ')

print('Hello Everyone , I am' ,name, 'and i am', age, 'years old and i live in', location,'.')

6. Suppose there are many N numbers of people in the Army. We need to distribute them in G groups. Take the number of people from users and the Number of Groups and tell how many are left without Group.

Solution

n = int(input('Number of Army People : '))

g = int(input('How many groups do we need ? '))

rest = n%g

print('Remaining People :',rest)

7.Take Temperature in Fahrenheit and convert it into Celsius.

Formula: C = 5/9 * ( F - 32 )

Solution
# Ask user for temperature in Fahrenheit
fahrenheit = float(input("Enter temperature in Fahrenheit: "))

# Convert to Celsius
celsius = (fahrenheit - 32) * 5/9

# Print result
print(fahrenheit,' degrees Fahrenheit is equal to',celsius,'degrees Celsius.")
  1. Take two variables from user value and power and print the solution value raised to power. Such as value = 3 and power = 2 then solution is 9

Solution
value = int(input('Enter the Number : '))
power = int(input('Enter the power : '))

solution = value ** power
print('Solution is', solution)
  1. Tom had y amount in his bank and jeff withdrew x amount where x is always less than y. Print the remaining balance in Tom's account. Take x and y from the user.

Solution
y = int(input("Enter Tom's account balance : "))
x = int(input('Enter withdrawal amount : '))

balance = y - x
print('Remaining balance :', balance)
  1. Take the base and height of a triangle from the user and calculate the area of the triangle. area=(base * height)*1/2

Solution
base=int(input('Enter the base of the triangle:'))
height=int(input('Enter the height of the triangle:'))
area=(base*height)*1/2
print('Area of the triangle is',area)
  1. Take 5 numbers from the user and calculate average of those numbers.

(average=sum of data/number of data)

Solution
num1=int(input('Enter first number:'))
num2=int(input('Enter first number:'))
num3=int(input('Enter first number:'))
num4=int(input('Enter first number:'))
num5=int(input('Enter first number:'))

average=(num1+num2+num3+num4+num5)/5
print('Average of the numbers',average)
  1. Take the sides of a triangle and check whether it follows Pythagoras' theorem. sq. of base + sq. of height=sq. of hypotenuse

Solution
base=int(input('Enter base of the triangle:'))
height=int(input('Enter height of the triangle:'))
hypotnuse=int(input('Enter hypotnuse of the triangle:'))
result=base**2 + height **2
print('pythagoras theorem:',result==hypotnuse**2)
  1. Take the length and breadth of a rectangle and find the perimeter of the rectangle perimeter= 2 * (length + breadth)

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

perimeter= 2* (length + breadth)
print('Perimeter of the rectangle with sides', length,'and',breadth,' will be', perimeter)
  1. Take the side of a cube in cm and calculate the volume of the cube. volume= side * side * side

Solution
side=int(input('Enter side of a cube:')
volume= side ** 3

print('Volume of the cube:',volume,'cubic cm')
  1. Take the length, breadth, and height of a cuboid in cm and calculate the volume of the cuboid. volume= length * breadth * height

Solution
length= int(input('Enter length of the cuboid:'))
breadth=int(input('Enter breadth of the cuboid:'))
height= int(input('Enter height of the cuboid:'))

volume= length * breadth * height
print('Volume of the cuboid:',volume,'cubic cm')
  1. Take the radius and height of a cylinder and calculate the total surface area. total_surface_area= 2*3.14* radius *height + 2* 3.14 * sq. of radius

Solution
radius= int(input('Enter radius of the cylinder:'))
height= int(input('Enter height of the cylinder:'))
pi=3.14
total_surface_area = 2*pi*radius*height + 2*pi*radius**2
print('the total surface area of the cylinder is',total_surface_area)
  1. Take the radius and height of a cone and calculate the volume of it. volume= (3.14 * sq of radius * height) * 1/3

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

volume= (pi * radius **2 *height)*1/3
print('Volumeof the cone',volume)
  1. Take the radius and length of a cone and calculate the total surface area of it. total_surface_area= 3.14*radius*(radius + length)

Solution
radius= int(input('Enter radius of the cone:'))
length= int(input('Enter length of the cone:'))
pi=3.14

total_surface_area= pi * radius * (radius + length)
print('total surface area of the cone:',total_surface_area) 
  1. The output of the following

    A = 100 B= 30 print(A and B)

    a. True b. False c. 100 d. 30

Solution

Answer: option d

  1. print(20 or 30)

    a. False b. True c. 20 d. 30

Solution

Answer: option c