0% found this document useful (0 votes)
657 views

PWP Practical No. 3

This document provides examples of simple Python programs using various operators and functions. It includes programs to: 1) Convert dollars to rupees using arithmetic operators 2) Convert bytes to megabytes, gigabytes, and terabytes using logical operators 3) Find the square root of a number using mathematical operators

Uploaded by

Rutuja Bhagat
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
657 views

PWP Practical No. 3

This document provides examples of simple Python programs using various operators and functions. It includes programs to: 1) Convert dollars to rupees using arithmetic operators 2) Convert bytes to megabytes, gigabytes, and terabytes using logical operators 3) Find the square root of a number using mathematical operators

Uploaded by

Rutuja Bhagat
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Practical No.

3: Write simple Python program using operators: Arithmetic


Operators, Logical Operators, Bitwise Operators

1. Write a program to convert U.S. dollars to Indian rupees.

dollars = float(input("Please enter dollars:"))


rupees = dollars * 64
print(rupees, " Rupees")

2. Write a program to convert bits to Megabytes, Gigabytes and Terabytes

def convert_bytes(bytes_number):
tags = [ "Byte", "Kilobyte", "Megabyte", "Gigabyte", "Terabyte" ]

i=0
double_bytes = bytes_number

while (i < len(tags) and bytes_number >= 1024):


double_bytes = bytes_number / 1024.0
i=i+1
bytes_number = bytes_number / 1024

return str(round(double_bytes, 2)) + " " + tags[i]

print(convert_bytes(4896587482345))
print(convert_bytes(9876524362))
print(convert_bytes(10248000))
print(convert_bytes(1048576))
print(convert_bytes(1024000))
print(convert_bytes(475445))
print(convert_bytes(1024))
print(convert_bytes(75))
print(convert_bytes(0))

3. Write a program to find the square root of a number

number = int(input("Enter a number to find the square root : "))

if number < 0 :
print("Please enter a valid number.")
else :
sq_root = number ** 0.5
print("Square root of {} is {} ".format(number,sq_root))
4. Write a program to find the area of Rectangle

width = float(input('Please Enter the Width of a Rectangle: '))


height = float(input('Please Enter the Height of a Rectangle: '))
# calculate the area
Area = width * height
# calculate the Perimeter
Perimeter = 2 * (width + height)
print("\n Area of a Rectangle is: %.2f" %Area)
print(" Perimeter of Rectangle is: %.2f" %Perimeter)

5. Write a program to calculate area and perimeter of the square

side=int(input("Enter the side:"))


area=side*side
perimeter= 4* side
print("Area: {}".format(area))
print("Perimeter: {}".format(perimeter))

6. Write a program to calculate surface volume and area of a cylinder.

pi=22/7
height = float(input('Height of cylinder: '))
radian = float(input('Radius of cylinder: '))
volume = pi * radian * radian * height
sur_area = ((2*pi*radian) * height) + ((pi*radian**2)*2)
print("Volume is: ", volume);
print("Surface Area is: ", sur_area);

7. Write a program to swap the value of two variables

# Python swap program


x = input('Enter value of x: ')
y = input('Enter value of y: ')

# create a temporary variable and swap the values


temp = x
x=y
y = temp

print('The value of x after swapping: {}'.format(x))


print('The value of y after swapping: {}'.format(y))

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy