0% found this document useful (0 votes)
5 views2 pages

Python Variable Types and Operations

Python lab programs
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)
5 views2 pages

Python Variable Types and Operations

Python lab programs
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

# Define variables of different types

name = "Meena" # str


age = 21 # int
height = 5.6 # float
is_student = True # bool
grades = [85, 90, 95] # list
info = {"id": 101, "dept": "CSE"} # dict
data = (1, 2, 3) # tuple
unique = {1, 2, 3} # set
nothing = None # NoneType
byte_val = b'Hello' # bytes

# Print variable types


print("Type of name:", type(name))
print("Type of age:", type(age))
print("Type of height:", type(height))
print("Type of is_student:", type(is_student))
print("Type of grades:", type(grades))
print("Type of info:", type(info))
print("Type of data:", type(data))
print("Type of unique:", type(unique))
print("Type of nothing:", type(nothing))
print("Type of byte_val:", type(byte_val))
=================================================================
# indentation
num = 50

if num > 0: # Level 1


print("Number is positive")

if num > 10: # Level 2


print("Number is greater than 10")

if num < 100: # Level 3


print("Number is less than 100")

if num == 50: # Level 4 (deepest)


print("Number is exactly 50")
else:
print("Number is not 50")
else:
print("Number is 100 or more")
else:
print("Number is 10 or less")
else:
print("Number is not positive")

====================================================
# Program 2b: Another example
x = 10 # Integer
y = 2.5 # Float
z = complex(x, y) # Complex
fruits = ["apple", "banana"]
info = {"course": "Python", "duration": "3 months"}

print("Complex number:", z)
print("Fruits List:", fruits)
print("Course Info Dictionary:", info)

==================================================================
===
# Program 3a: Arithmetic operations
a = 10
b = 3

print("Addition:", a + b)
print("Subtraction:", a - b)
print("Multiplication:", a * b)
print("Division:", a / b)
print("Floor Division:", a // b)
print("Modulus:", a % b)
print("Exponent:", a ** b)
=========================================================
# Program 4: Convert USD to INR
usd = float(input("Enter amount in USD: "))
inr = usd * 83.0 # Assuming 1 USD = 83 INR
print(f"{usd} USD is equal to {inr} INR")

==================================================================
==========

# Program to convert bits to Megabytes, Gigabytes, and Terabytes

bits = int(input("Enter the number of bits: "))

# Conversion calculations
bytes_val = bits / 8
kb = bytes_val / 1024
mb = kb / 1024
gb = mb / 1024
tb = gb / 1024

# Output results
print(f"\nConversion for {bits} bits:")
print(f"Bytes: {bytes_val:.2f} B")
print(f"Kilobytes: {kb:.6f} KB")
print(f"Megabytes: {mb:.6f} MB")
print(f"Gigabytes: {gb:.6f} GB")
print(f"Terabytes: {tb:.6f} TB")

You might also like