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

Python

Uploaded by

vedantwedekar
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 views13 pages

Python

Uploaded by

vedantwedekar
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
You are on page 1/ 13

NAME :- VEDANT N WEDEKAR

PRACTICAL NO :- 1

AIM :- Write a simple program in python that prints "Hello, World!" to the
console.

PROBLEM STATEMENT:- The program should demonstrate the basic use of


the print() function in Python to display text.

CODE :-

# Simple Hello World program

print("Hello, World!")

OUTPUT :-
NAME :- VEDANT N WEDEKAR

PRACTICAL NO :- 2

AIM :- Write a program in Python that takes user input and displays it back.

PROBLEM STATEMENT:- The task is to create a Python program that asks


the user to enter some input (such as text, number, or word) and then
displays the same input back to the user.

CODE :-

# Program to take user input and display it back

# Taking input from the user

user_input = input("Enter something: ")

# Displaying the same input back

print("You entered:", user_input)

OUTPUT :-
NAME :- VEDANT N WEDEKAR

PRACTICAL NO :- 3

AIM :- Write a program in Python that performs basic arithmetic operations


(addition, subtraction, multiplication, division).

PROBLEM STATEMENT:- The task is to create a Python program that takes


two numbers from the user and performs four basic arithmetic operations:
addition, subtraction, multiplication, and division. The program should
display the results of all operations.

CODE :-

# Program to perform basic arithmetic operations

# Taking two numbers as input

num1 = float(input("Enter first number: "))

num2 = float(input("Enter second number: "))

# Performing operations

addition = num1 + num2

subtraction = num1 - num2

multiplication = num1 * num2

division = num1 / num2 if num2 != 0 else "Undefined (division by zero)"

# Displaying results

print("\nResults:")

print("Addition:", addition)

print("Subtraction:", subtraction)

print("Multiplication:", multiplication)

print("Division:", division)
OUTPUT :-
NAME :- VEDANT N WEDEKAR

PRACTICAL NO :- 4

AIM :- Write a program in Python that checks if a person is an adult or a


minor based on age.

PROBLEM STATEMENT:- The task is to create a Python program that asks


the user to enter their age and then checks whether the person is an adult
(age ≥ 18) or a minor (age < 18).

CODE :-

# Taking age as input

age = int(input("Enter your age: "))

# Checking condition

if age >= 18:

print("You are an Adult.")

else:

print("You are a Minor.")

OUTPUT :-

1] First Response

2] Second Response
NAME :- VEDANT N WEDEKAR

PRACTICAL NO :- 5

AIM :- Write a program in Python that uses for loop and while loop to
print numbers.

PROBLEM STATEMENT:- The task is to create a Python program that


demonstrates the use of both for and while loops by printing numbers from 1
to 10.

CODE :-

# Program to print numbers using for loop and while loop

print("Numbers using for loop:")

for i in range(1, 11):

print(i, end=" ")

print("\n\nNumbers using while loop:")

j=1

while j <= 10:

print(j, end=" ")

j += 1

OUTPUT :-
NAME :- VEDANT N WEDEKAR

PRACTICAL NO :- 6

AIM :- Write a program in Python that demonstrates basic list operations


such as adding and removing elements.

PROBLEM STATEMENT:- The task is to create a Python program that uses a


list to store elements and then demonstrates basic operations such as
adding elements (append, insert) and removing elements (remove, pop).

CODE :-

# Initial list

fruits = ["Apple", "Banana", "Mango"]

print("Initial List:", fruits)

# Adding elements

fruits.append("Orange") # add at end

fruits.insert(1, "Grapes") # add at specific position

print("After Adding Elements:", fruits)

# Removing elements

fruits.remove("Banana") # remove by value

fruits.pop(2) # remove by index

print("After Removing Elements:", fruits)

OUTPUT :-
NAME :- VEDANT N WEDEKAR

PRACTICAL NO :- 7

AIM :- Write a program in Python that performs basic string operations like
concatenation and slicing.

PROBLEM STATEMENT:- The task is to create a Python program that


demonstrates basic string operations. The program should concatenate two
strings into one and perform slicing operations to extract parts of a string.

CODE :-

# String concatenation

str1 = "Hello"

str2 = "Python"

concatenated = str1 + " " + str2

print("Concatenation:", concatenated)

# String slicing

text = "Programming"

print("Original String:", text)

print("Slicing [0:6]:", text[0:6]) # first 6 characters

print("Slicing [3:]:", text[3:]) # from index 3 to end

print("Slicing [:5]:", text[:5]) # from start to index 4

OUTPUT :-
NAME :- VEDANT N WEDEKAR

PRACTICAL NO :- 8

AIM :- Write a program in Python that prints numbers from 1 to 5 using a


loop.

PROBLEM STATEMENT:- The task is to create a Python program that uses a


loop to print numbers from 1 to 5 in sequence.

CODE :-

# Program to print numbers from 1 to 5 using a loop

print("Numbers from 1 to 5:")

for i in range(1, 6):

print(i)

OUTPUT :-
NAME :- VEDANT N WEDEKAR

PRACTICAL NO :- 9

AIM :- Write a program in Python to calculate the sum of numbers from 1 to


10.

PROBLEM STATEMENT:- The task is to create a Python program that


calculates the sum of numbers from 1 to 10 using a loop and displays the
result.

CODE :-

# Program to calculate the sum of numbers from 1 to 10

total = 0

for i in range(1, 11):

total += i

print("The sum of numbers from 1 to 10 is:", total)

OUTPUT :-
NAME :- VEDANT N WEDEKAR

PRACTICAL NO :- 10

AIM :- Write a program in Python to handle the Divide by Zero error.

PROBLEM STATEMENT:- The task is to create a Python program that takes


two numbers from the user, attempts division, and uses exception handling
(try-except) to prevent the program from crashing if the denominator is zero.

CODE :-

# Program to handle Divide by Zero error

try:

# Taking input from user

num1 = float(input("Enter numerator: "))

num2 = float(input("Enter denominator: "))

# Performing division

result = num1 / num2

print("Result:", result)

except ZeroDivisionError:

print("Error: Division by zero is not allowed.")

OUTPUT :-

You might also like