Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
4 views

Practical1-Python Programming

Practical

Uploaded by

Garv Saini
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Practical1-Python Programming

Practical

Uploaded by

Garv Saini
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

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
PRACTICAL 1
Part A (To be referred by students)

Data Types, Input / Output Statements, Operators (Arithmetic, Relational, Logical,


Bitwise) and Expressions

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

8. WAP to find roots of a quadratic equation ax2+bx+c=0

Learning Objective: The Learner will be able to


1. Analyze the scenario to write a script declaring variables, printing output and using
expressions.
2. Infer the features of various operators for different operations as per variable data
type.
3. Evaluate the working of the algorithm using variables, printing and inputting user
values and expressions.

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

 Accepting Input from the Console:

# if input() used it accepts input as string


num=input(‘Enter a number: ‘)
print(num)

# to accept numbers
num=int(input(‘Enter a number: ‘))
print(num)

num=float(input(‘Enter a number: ‘))


print(num)

Output:
Enter a number: 10
‘10’
Enter a number: 45
45
Enter a number: 78
78.0

 Output using print() with formatting:

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)

print('The value of x is %3.4f' %x)

print ('The %.2f and %.1f ' %(x, y))

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

 Python Arithmetic Operators


Arithmetic operators are used with numeric values to perform common mathematical
operations:
Operator Example

+ x+y

- x-y

* x*y

/ x/y

% x%y

** x ** y

// x // y

 Python Assignment Operators


Assignment operators are used to assign values to variables:
Operator Example

= 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

 Python Relational/Comparison Operators


Comparison operators are used to compare two values:
Operator Example

== x == y

!= x != y

> x>y

< x<y

>= x >= y

<= x <= y

 Python Logical Operators


Logical operators are used to combine conditional statements:
Operato Description Example
r

and Returns True if both statements are true x < 5 and x < 10

or Returns True if one of the statements is true x < 5 or x < 4

not Reverse the result, returns False if the result is not(x < 5 and x < 10)
true

 Python Bitwise Operators


Bitwise operators are used to compare (binary) numbers:
Operator Name Description

& AND Sets each bit to 1 if both bits are 1

| OR Sets each bit to 1 if one of two bits is 1

^ XOR Sets each bit to 1 if only one of two bits is 1

~ NOT Inverts all the bits

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

Data Types, Input / Output Statements, Operators (Arithmetic, Relational, Logical,


Bitwise) and Expressions

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

You might also like