1.
Integer and Float Addition
# Program to add two numbers
a = 10 # integer
b = 5.5 # float
sum_result = a + b
print("Sum:", sum_result)
Output:
Sum: 15.5
2. String Concatenation
# Program to join two strings
first = "Hello"
second = "World"
result = first + " " + second
print("Concatenated String:", result)
Output:
Concatenated String: Hello World
3. Taking User Input (String)
# Program to take user input
name = input("Enter your name: ")
print("Welcome,", name)
Output (if user enters John):
Welcome, John
4. Arithmetic Operators
# Demonstration of arithmetic operators
x = 7
y = 3
print("Addition:", x + y)
print("Subtraction:", x - y)
print("Multiplication:", x * y)
print("Division:", x / y)
print("Modulus:", x % y)
print("Power:", x ** y)
5. Boolean and Comparison Operators
# Boolean operations
a = 10
b = 20
print("a > b:", a > b)
print("a < b:", a < b)
print("a == b:", a == b)
print("a != b:", a != b)
6. Type Conversion
# Convert string to integer
num_str = "100"
num_int = int(num_str) # type conversion
print("String:", num_str, type(num_str))
print("Integer:", num_int, type(num_int))
7. List Data Type
# List example
fruits = ["apple", "banana", "mango"]
print("First fruit:", fruits[0])
fruits.append("grape")
print("Updated List:", fruits)
8. Tuple Data Type
# Tuple example
colors = ("red", "green", "blue")
print("Tuple:", colors)
print("Second element:", colors[1])
9. Dictionary Data Type
# Dictionary example
student = {"name": "Amit", "age": 20, "marks": 85}
print("Student Name:", student["name"])
print("Student Age:", student["age"])
10. Taking Numeric Input and Performing Calculation
# Taking numeric input
num1 = int(input("Enter first number: "))
num2 = int(input("Enter second number: "))
print("Product:", num1 * num2)
Output (if input 4 and 5):
Product: 20