0% found this document useful (0 votes)
20 views13 pages

Python Exp 1 2 7 10 11 12

The document describes several experiments involving Python programming concepts like installing Python IDEs, using various operators, conditional statements like if/else, accepting user input, displaying messages, and using different loop structures like while, for, and nested loops. Each experiment includes the aim, code sample, and output. Key concepts covered include arithmetic, comparison, logical, and assignment operators, if/if else statements, input/output functions, and looping with while, for, and nested loops.

Uploaded by

Ayush Sonawane
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views13 pages

Python Exp 1 2 7 10 11 12

The document describes several experiments involving Python programming concepts like installing Python IDEs, using various operators, conditional statements like if/else, accepting user input, displaying messages, and using different loop structures like while, for, and nested loops. Each experiment includes the aim, code sample, and output. Key concepts covered include arithmetic, comparison, logical, and assignment operators, if/if else statements, input/output functions, and looping with while, for, and nested loops.

Uploaded by

Ayush Sonawane
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

Experiment No.

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)

print("Greater Than:", x > y)

print("Less Than:", x < y)

print("Greater Than or Equal To:", x >= y)

print("Less Than or Equal To:", 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: ")

print("You entered : ", user_input)

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

while num <= Limit:


print(num)
num += 1

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 :

You might also like