Paper-2 Lab-1 (1)
Paper-2 Lab-1 (1)
AIM: Write a python program to demonstrate the usage of various arithmetic operators.
PROGRAM CODE:
OUTPUT:
>>>
Enter First number: 12
Enter Second number 3
Sum of 12 and 3 is : 15
Difference of 12 and 3 is : 9
Product of 12 and 3 is : 36
Division of 12 and 3 is : 4.0
Floor Division of 12 and 3 is : 4
Exponent of 12 and 3 is : 1728
Modulus of 12 and 3 is : 0
>>>
EXPERIMENT-2(a)
PROGRAM CODE:
fahrenheit = float(input("Enter temperature in fahrenheit: "))
OUTPUT:
>>>
Enter temperature in Fahrenheit: 140
140.0 degree Fahrenheit is equal to 60.0 degree Celsius.
>>>
EXPERIMENT-2(b)
PROGRAM CODE:
OUTPUT:
>>>
=== RESTART: C:/Users/HP7/AppData/Local/Programs/Python/Python39/SKM/NEP2b.py ==
Enter temperature in celsius: 60
60.0 degree Celsius is equal to 140.0 degree Fahrenheit.
>>>
EXPERIENT-3
AIM: Write a python program that will find the roots of a quadratic equation: ax² + bx + c =
0
PROGRAM CODE:
OUTPUT
>>>
=== RESTART: C:\Users\HP7\AppData\Local\Programs\Python\Python39\SKM\NEP31.py
==
Enter a: 3
Enter b: 4
Enter c: 5
The solution are (-0.6666666666666666-1.1055415967851332j) and (-
0.6666666666666666+1.1055415967851332j)
>>>
EXPERIMENT-4
AIM: Write a python program that demonstrates the usage of various String functions.
.
PROGRAM CODE:
# Python3 program to show the
OUTPUT:
>>>
=== RESTART: C:/Users/HP7/AppData/Local/Programs/Python/Python39/SKM/NEP4.py ===
Converted String:
SOUMENDRA KUMAR MOHANTY
Converted String:
soumendra kumar mohanty
Converted String:
Soumendra Kumar Mohanty
Converted String:
SOUmenDRA kUmaR MOhaNTY
Converted String:
Soumendra kumar mohanty
Original String
souMENdra KuMAr moHAnty
>>>
EXPERIMENT-5
AIM: Write a python program that will ask you to enter your name, through keyboard, and
perform following operations
a. Find the middle name
b. Find the last name (using string slicing)
c. Re-write the name with surname first.
PROGRAM CODE:
OUTPUT:
>>>
=== RESTART: C:\Users\HP7\AppData\Local\Programs\Python\Python39\SKM\NEP5.py ===
What is your name? SOUMENDRA KUMAR MOHANTY
My name is: SOUMENDRA KUMAR MOHANTY
first name - SOUMENDRA
middle name - KUMAR
last name - MOHANTY
The middle name is:
Middle name - KUMAR
The last name is:
Last name - MOHANTY
The modified name with Surname First
MOHANTY SOUMENDRA KUMAR
>>>
EXPERIMENT-6
AIM: Write a python program to find out whether the integer entered by the user, through the
keyboard, is even or odd number.
PROGRAM CODE:
# Prompt the user to enter a number and convert the input to an integer
num = int(input("Enter a number: "))
OUTPUT:
>>>
=== RESTART: C:/Users/HP7/AppData/Local/Programs/Python/Python39/SKM/NEP6.py ===
Enter a number: 12
This is an even number.
>>>
=== RESTART: C:/Users/HP7/AppData/Local/Programs/Python/Python39/SKM/NEP6.py ===
Enter a number: 37
This is an odd number.
>>>
EXPERIMENT-7
AIM: Write a python program to find out the youngest among Shyam, Dugu and Ishan
whose ages are entered by the user through keyboard.
.
PROGRAM CODE:
OUTPUT:
Python 3.9.1 (tags/v3.9.1:1e5d33e, Dec 7 2020, 17:08:21) [MSC v.1927 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>>
=== RESTART: C:/Users/HP7/AppData/Local/Programs/Python/Python39/SKM/NEP7.py ===
Enter the Age of Shyam :45
Enter the Age of Dugu :34
Enter the Age of Ishan :78
The Youngest Age is Dugu
>>>
=== RESTART: C:/Users/HP7/AppData/Local/Programs/Python/Python39/SKM/NEP7.py ===
Enter the Age of Shyam :12
Enter the Age of Dugu :34
Enter the Age of Ishan :56
The Youngest Age is Shyam
>>>
=== RESTART: C:/Users/HP7/AppData/Local/Programs/Python/Python39/SKM/NEP7.py ===
Enter the Age of Shyam :65
Enter the Age of Dugu :45
Enter the Age of Ishan :23
The Youngest Age is Ishan
>>>
EXPERIMENT-9
PROGRAM CODE:
iList = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]
print('iList: ',iList)
iList.append(111)
iList.sort()
# popping an element
print('Popped elements is: ',iList.pop())
iList.remove(80)
iList.insert(2, 100)
iList.reverse()
OUTPUT:
Python 3.9.1 (tags/v3.9.1:1e5d33e, Dec 7 2020, 17:08:21) [MSC v.1927 64 bit (AMD64)] on win32
>>>
iList: [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]
first element: 10
fourth element: 40
iList elements from 0 to 4 index: [10, 20, 30, 40, 50]
iList after append(): [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 111]
index of '80': 7
after sorting: [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 111]
after pop(): [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]
after removing '80': [10, 20, 30, 40, 50, 60, 70, 90, 100]
after insert: [10, 20, 100, 30, 40, 50, 60, 70, 90, 100]
after extending: [10, 20, 100, 30, 40, 50, 60, 70, 90, 100, 11, 22, 33]
after reversing: [33, 22, 11, 100, 90, 70, 60, 50, 40, 30, 100, 20, 10]
>>>
EXPERIMENT-10
AIM: Write a python program to demonstrate stack and queue operations using a list of
numbers.
PROGRAM CODE:
print(stack)
print("The resulting stack elements are after appending Ram in the stack")
stack.append("Ram")
print(stack)
print("The resulting stack elements are after appending Iqbal in the stack")
stack.append("Iqbal")
print(stack)
print("The resulting stack elements are after removing Iqbal in the stack")
print(stack.pop())
print(stack)
print("The resulting stack elements are after removing Ram in the stack")
print(stack.pop())
print(stack)
queue.append("Ram")
print(queue)
print("The resulting queue elements are after appending Iqbal in the REAR END of the queue")
queue.append("Iqbal")
print(queue)
print("The resulting queue elements are after removing the first element in the queue")
print(queue.pop(0))
print(queue)
print("The resulting queue elements are after removing the first element in the queue")
print(queue.pop(0))
print(queue)
OUTPUT:
>>>
The resulting stack elements are after appending Ram in the stack
The resulting stack elements are after appending Iqbal in the stack
The resulting stack elements are after removing Iqbal in the stack
Iqbal
Ram
The resulting queue elements are after appending Ram in the REAR END of the queue
The resulting queue elements are after appending Iqbal in the REAR END of the queue
The resulting queue elements are after removing the first element in the queue
Amar
The resulting queue elements are after removing the first element in the queue
Akbar
>>>