P-1 # Demonstrating Basic Data Types in Python
# Integer
num_int = 10
print("Integer value:", num_int)
print("Type:", type(num_int))
print()
# Float
num_float = 10.5
print("Float value:", num_float)
print("Type:", type(num_float))
print()
# String
text = "Hello, Python!"
print("String value:", text)
print("Type:", type(text))
print()
# Boolean
is_python_fun = True
print("Boolean value:", is_python_fun)
print("Type:", type(is_python_fun))
print()
# List
my_list = [1, 2, 3, "Python", 4.5]
print("List value:", my_list)
print("Type:", type(my_list))
print()
# Tuple
my_tuple = (1, 2, 3, "Python", 4.5)
print("Tuple value:", my_tuple)
print("Type:", type(my_tuple))
print()
# Set
my_set = {1, 2, 3, 3, 4}
print("Set value:", my_set)
print("Type:", type(my_set))
print()
# Dictionary
my_dict = {"name": "Alice", "age": 25}
print("Dictionary value:", my_dict)
print("Type:", type(my_dict))
print()
P-2 Write a program in python to compute distance between two points taking input from the user.
# Program to calculate distance between two points
import math
# Taking input from the user
x1 = float(input("Enter x-coordinate of first point: "))
y1 = float(input("Enter y-coordinate of first point: "))
x2 = float(input("Enter x-coordinate of second point: "))
y2 = float(input("Enter y-coordinate of second point: "))
# Calculating distance using distance formula
distance = [Link]((x2 - x1)**2 + (y2 - y1)**2)
# Displaying the result
print("Distance between the two points is:", distance)
P-3 Write a program [Link] that takes 2 numbers as command line arguments and prints its sum.
# [Link]
import sys
# Check if exactly two arguments are provided
if len([Link]) != 3:
print("Usage: python [Link] <num1> <num2>")
[Link](1)
# Convert command line arguments to float
num1 = float([Link][1])
num2 = float([Link][2])
# Calculate sum
result = num1 + num2
# Display result
print("Sum:", result)
P-4 Write a Program for checking whether the given number is an even number or not.
# Program to check whether a number is even or odd
# Taking input from the user
num = int(input("Enter a number: "))
# Checking if the number is even
if num % 2 == 0:
print(num, "is an Even number.")
else:
print(num, "is an Odd number.")
P-5 Using a for loop, write a program that prints out the decimal equivalents of 1/2, 1/3, 1/4, . . . , 1/10
# Program to print decimal equivalents of 1/2 to 1/10
for i in range(2, 11):
value = 1 / i
print("1/{0} = {1}".format(i, value))
If you want the output rounded to 2 decimal places, you can use:
print("1/{0} = {1:.2f}".format(i, value))
format() is used to insert values into a string in a clean and organized way.
"1/{0} = {1}" → This is a string with placeholders.
{0} → Refers to the first value inside format()
{1} → Refers to the second value inside format()
.format(i, value) → Replaces {0} with i and {1} with value