Python Exp 1 2 7 10 11 12
Python Exp 1 2 7 10 11 12
1
Aim : Install & configure Python IDE
Step 1:
Step 2 :
Step 3 :
Step 4 :
Step 5 :
Experiment No . 2
Aim : Write a simple Python program using Operators
• Arithmetic Operators
Code :
a = 10
b = 5
sum_result = a + b
print("Sum:", sum_result)
difference = a - b
print("Difference:", difference)
product = a * b
print("Product:", product)
division_result = a / b
print("Division:", division_result)
remainder = a % b
print("Remainder:", remainder)
exponentiation = a ** b
print("Exponentiation:", exponentiation)
floor_division = a // b
print("Floor Division:", floor_division)
Output :
• Comparison Operators:
Code :
x = 5
y = 5
print("Equal:", x == y)
print("Not Equal:", x != y)
Output :
• Logical Operators:
Code :
a = True
b = False
print("AND:", a and b)
print("OR:", a or b)
print("NOT:", not a)
Output :
• Assignment Operators:
Code :
x = 10
print("assign: ", x)
x += 5 # Equivalent to x = x + 5
print("Add and assign: ", x)
x -= 3 # Equivalent to x = x - 3
print("Subtract and assign: ", x)
x *= 2 # Equivalent to x = x * 2
print("Multiply and assign: ", x)
x /= 4 # Equivalent to x = x / 4
print("Divide and assign: ", x)
x %= 2 # Equivalent to x = x % 2
print("Modulus and assign: ", x)
x **= 3 # Equivalent to x = x ** 3
print("Exponentiation and assign: ", x)
x //= 3 # Equivalent to x = x // 3
print("Floor Division and assign: ", x)
Output :
Experiment No . 7
Aim : Write a Python program to demonstrate the use of if
and if else.
• If statement
Code:
num = int(input("Enter a number : "))
if num < 0 :
print("Number is less than zero.")
if num > 0 :
print("Number is greater than zero.")
if num == 0 :
print("Number is equal to zero.")
Output :
• If-else statement
Code :
age = int(input("Enter your age: "))
if age > 18 :
print("You are an adult you can vote..!")
else:
print("You are not an adult you can't vote..!")
Output :
Experiment No . 10
Aim : Write a Python program to read keyboard input &
print it to the screen.
Code :
user_input = input("Please enter something: ")
Output :
Experiment No . 11
Aim : Write a Python program to display a message on the
screen.
Code :
message = "This is how you can display message on the screen"
print(message)
Output :
Code :
text = "Hello World"
print(text)
Output :
Experiment No . 12
Aim : Write a Python program to demonstrate the use of
looping statements.
• While loop
Code :
num = 1
Limit = 10
Output :
• For loop
Code :
students = ["Sahil" , "Ayush" , "Prithvi" , "Falashree" , "Anshika"]
for s in students:
print(s)
num_of_students = 0
for n in students:
num_of_students += len(n)
print("Total number of students is : ",num_of_students)
Output :
• Nested loop
Code :
row = int(input("Enter number of rows : "))
for i in range(row):
for j in range(i + 1):
print("*", end=" ")
print()
Output :