Practical1-Python Programming
Practical1-Python Programming
Problem Statements:
1. Write a program to enter a number and print its square, cube and square root.
2. WAP to calculate the average of 3 numbers.
3. Write a program to calculate the area of a right-angle triangle.
4. WAP to calculate simple interest.
5. WAP to convert temperature in Celsius into Fahrenheit.
6. WAP to find Euclidean distance between two points on a plane.
7. Write a Python program to swap two variables.
1. Using temp variable
2. Using the comma operator
3. Using bitwise XOR operator
Theory:
Data types:
Number: int, float, complex
String
a = 11.80
x = 100
y = “Hello”
z = 3+5.j
print(a)
print(x)
print(y)
print(z)
Output:
11.8
100
Hello
(3+5j)
1|Page
SVKM’s NMIMS University
Mukesh Patel School of Technology Management & Engineering
Course: Python Programming
PROGRAMME: B.(Tech.)/MBA(Tech.)
First Year AY 2023-2024 Semester: II
# to accept numbers
num=int(input(‘Enter a number: ‘))
print(num)
Output:
Enter a number: 10
‘10’
Enter a number: 45
45
Enter a number: 78
78.0
x=6
y=89
print('The value of x is {1} and y is {0}'.format(x,y))
x = 12.3456789
print('The value of x is %3.2f' %x)
Output:
The value of x is 89 and y is 6
The value of x is 12.35
The value of x is 12.3457
The 12.35 and 456.8
Operators:
Operators are used to perform operations on variables and values.
Python divides the operators in the following groups:
Arithmetic operators
Assignment operators
Relational/Comparison operators
2|Page
SVKM’s NMIMS University
Mukesh Patel School of Technology Management & Engineering
Course: Python Programming
PROGRAMME: B.(Tech.)/MBA(Tech.)
First Year AY 2023-2024 Semester: II
Logical operators
Identity operators
Membership operators
Bitwise operators
+ x+y
- x-y
* x*y
/ x/y
% x%y
** x ** y
// x // y
= x=5
+= x += 3
-= x -= 3
*= x *= 3
/= x /= 3
%= x %= 3
//= x //= 3
**= x **= 3
&= x &= 3
|= x |= 3
3|Page
SVKM’s NMIMS University
Mukesh Patel School of Technology Management & Engineering
Course: Python Programming
PROGRAMME: B.(Tech.)/MBA(Tech.)
First Year AY 2023-2024 Semester: II
^= x ^= 3
>>= x >>= 3
<<= x <<= 3
== x == y
!= x != y
> x>y
< x<y
>= x >= y
<= x <= y
and Returns True if both statements are true x < 5 and x < 10
not Reverse the result, returns False if the result is not(x < 5 and x < 10)
true
4|Page
SVKM’s NMIMS University
Mukesh Patel School of Technology Management & Engineering
Course: Python Programming
PROGRAMME: B.(Tech.)/MBA(Tech.)
First Year AY 2023-2024 Semester: II
<< Zero fill left Shift left by pushing zeros in from the right and
shift let the leftmost bits fall off
>> Signed right Shift right by pushing copies of the leftmost bit
shift in from the left, and let the rightmost bits fall
off
PRACTICAL 1
Part B (to be completed by students)
5|Page
SVKM’s NMIMS University
Mukesh Patel School of Technology Management & Engineering
Course: Python Programming
PROGRAMME: B.(Tech.)/MBA(Tech.)
First Year AY 2023-2024 Semester: II
1. All the students are required to perform the given tasks in Jupyter Notebook
2. Create a new notebook for each experiment. The filename should be
RollNo_Name_Exp1)
3. In the first cell, the student must write his/her Name, roll no and class in the form of
comments
4. Every program should be written in separate cells and in the given sequence
5. After completing the experiment, download the notebook in pdf format. The filename
should be RollNo_Name_Exp1.pdf).
6. Upload the pdf on the web portal
6|Page