Python Programs
Python Programs
#strings
print("Hello")
print('Hello')
#ex2
x=”python”
print(x)
#Ex 3
x = ” Strings in python are surrounded by either single quotation marks, or double quotation
marks.”
Print(x)
#tuples
numbers = (20, -12, 8)
print(numbers)
#Example of index
languages=('Python', 'programming', 5)
# access the first item
print(languages[0])
# access the third item
print(languages[2])
list
# a list of three elements
ages = [19, 26, 29]
print(ages)
Ex2
lan = [‘python’, ‘c’, ‘java’]
print(lan)
Dictionaries
# creating a dictionary
teams = {
"virat": "rcb",
"rohith": "mumbai",
"gill": "gt"
}
# printing the dictionary
print(teams)
#division (/)
x=10
y=6
Division=x/y
Print(x/y)
#floor division
x=10
y=6
Fllordivision=x//y
Print(x//y)
#modulus
x=10
y=6
Modulus=x%y
Print(x%y)
#type conversions
#integer to float
Num=4
num_float=float (num)
print (num_float)
#float to integer
num=9.0
num_int=int (num)
print (num_int)
#string to integer
str="9"
str_int=int (str)
print (str_int)
#str to float
str="9.0"
str_float=float (str)
print (str_float)
Byte:- A byte is a unit of data memory equal to eight bits, depending on whether it requires error
correction. One byte is equivalent to eight bits. A byte is a unit most computers use to describe a
character such as a number, letter, or typographic symbol. 1 Byte = 8 bits.
KiloByte (KB):- A KiloByte is a unit of computer information or memory equivalent to 1024 bytes. 1
KB = 1024 bytes.
Megabyte (MB):- A Megabyte is a unit of computer information or memory equivalent to 1,048,576
bytes. 1 MB = 1024 KB = 1024 * 1024 bytes = 1,048,576 bytes.
Gigabyte (GB):- A Gigabyte is a unit of computer information or memory that is approximately
equivalent to 1 billion bytes. 1 GB = 1024 MB = 1024 * 1024 * 1024 bytes = 1,07,37,41,824 bytes.
Terabyte (TB):- A Terabyte is a unit of computer information or memory that is approximately
equivalent to about 1 trillion bytes. 1 TB = 1024 GB = 1024 * 1024 * 1024 * 1024 bytes =
1.099511628×10¹² bytes.
Now let us see how we can convert Bytes to KB, MB, GB, and TB in Python programming language.
Below we have developed separate programs for these conversions and also for Python code to convert
bytes to GB.
//To find Area and Perimeter of a Square
side = int (input ("Enter the side of a square: " ))
area = side*side #Formula for Area of square
perimeter = 4*side #Formula for Perimeter of square
print("Area of a square : ",area)
print("Perimeter of a square : ",perimeter)
import math
def cone_vol(r, h):
#calculating the volume
vol = (1/3)*(math.pi)*r*r*h
print("Volume: ", str(vol))
l=6
h=5
r=2
cone_vol(r, h)