Download as pdf or txt
Download as pdf or txt
You are on page 1of 19

University Institute of Engineering

Department of Computer Science & Engineering


NAME: Harpreet Singh UID:23BCS10559 CLASS:202A

Experiment: 1
Student Name: Archita Srivastava UID:23BCS12459
Branch: Computer Science & Engineering Section/Group: 202 A
Subject Name: Disruptive Technology Subject Code: 23ECH-102
DateofPerformance:29 AUGUEST 2023 Semester:1ST

1. Aim of the practical: : To perform basic programs using Arithmetic operators and strings in python

2. Tool Used: Google Collaboratory

3. Basic Concept/ Command Description: This practical introduces us to some of basic


operations in python

4. Code:
1.1 Print hello world and name
print("Hello World")

OUTPUT
Hello World
University Institute of Engineering
Department of Computer Science & Engineering
NAME: Harpreet Singh UID:23BCS10559 CLASS:202A

1.2 Variable Declaration and Print 1.2.1


a=10 OUTPUT
a 10

1.2.2
a=10 200
b=200
a b

1.2.3
b=200
b
University Institute of Engineering
Department of Computer Science & Engineering
NAME: Harpreet Singh UID:23BCS10559 CLASS:202A

1.2.5 OUTPUT
a=10
b=200
print("a=",a)
print("b=",b)
print(b)
print(a)
a= 10
b= 200
200
10
1.2.6
#INDUTATION ERROR
a=20
print(a)
a=20
print(a)
File "<ipython-input-13-cd337a211c0a>", line 4
print(a )
^
IndentationError: unexpected indent
University Institute of Engineering
Department of Computer Science & Engineering
NAME: Harpreet Singh UID:23BCS10559 CLASS:202A

1.3.1 Arithmetic operatioes OUTPUT


#arithmetic operators
a=10 b=3 c=a+b d=a-b
e=a*b f=a/b g=a//b
h=a%b i=a**b
print(a,"+",b,"=",c)
print(a,"-",b,"=",d)
print(a,"*",b,"=",e)
print(a,"/",b,"=",f)
print(a,"//",b,"=",g)
print(a,"%",b,"=",h)
print(a,"**",b,"=",i)
10 + 3 = 13 10
- 3 = 7
10 * 3 = 30
10 / 3 = 3.3333333333333335
10 // 3 = 3

10 % 3 = 1
10 ** 3 = 1000
University Institute of Engineering
Department of Computer Science & Engineering
NAME: Harpreet Singh UID:23BCS10559 CLASS:202A

1.4.1 Bitwise operator OUTCOME


#bitwise operator
a=10 b=3 c=a&b
d=a|b e=a^b f=~a
print(c) print(d)
print(e) print(f)
2
11
9
-11
University Institute of Engineering
Department of Computer Science & Engineering
NAME: Harpreet Singh UID:23BCS10559 CLASS:202A

1.6.1 Shift Right OUTCOME


# Shift
right a=10
b=1 d=2
print(a>>b)
print(a>>d)

5
2

1.6.2 Shift Left


#Shift left
a=1 b=1
University Institute of Engineering
Department of Computer Science & Engineering
NAME: Harpreet Singh UID:23BCS10559 CLASS:202A

c=2
print(a<<b)
print(a<<c)
2
4

1.7.1 Assignment Operators OUTCOME


a=10
a+=20
print("a+=20",a)
a
a+=20 30
30
a=10 a*=20

print("a*=20",a) a*=20 200

a=10 a/=20
print("a/=20",a)
a/=20 0.5
University Institute of Engineering
Department of Computer Science & Engineering
NAME: Harpreet Singh UID:23BCS10559 CLASS:202A

a=10 a//=20

print("a//=20",a) a//=20 0

1.8.1 Taking Input OUTPUT


a=input("enter any number (name or number) : ") print("your
nummber is -->\n",a)
University Institute of Engineering
Department of Computer Science & Engineering
NAME: Harpreet Singh UID:23BCS10559 CLASS:202A

enter any number (name or number) : 10


your nummber is -->
10

1.9.1 Concatenate OUTPUT


a = input("EnteR FIRST STRING: ") b =
input("ENTER THE SECOND STRING: ") c =
a + b print(c)
EnteR FIRST STRING: d ENTER
THE SECOND STRING: 10 d10

1.10 if else OUTCOME


#if else a=10 b=20
if a==10 or b==20:
print("accepted")
elif a>=b:
print("rejected") else:
print("on hold")

accepted
University Institute of Engineering
Department of Computer Science & Engineering
NAME: Harpreet Singh UID:23BCS10559 CLASS:202A

1.11 Is Not
a=10 b=20
print("\"a is a -->\"",a is a )
print("a is b -->",a is b ) print("")
print("a is not a -->",a is not a ) print("a
is not b -->",a is not b )
OUTCOME
University Institute of Engineering
Department of Computer Science & Engineering
NAME: Harpreet Singh UID:23BCS10559 CLASS:202A

"a is a -->" True a


is b --> False
a is not a -->
False a is not b --
> True

1.12 Membership operator


print(" 10 in a -->",10 in a )
print("40 is a -->",40 in a )
print("100 is a -->",100 in a )
print("") print("10 not in a -->",10
not in a ) print("40 not in a -->",40
not in a )
University Institute of Engineering
Department of Computer Science & Engineering
NAME: Harpreet Singh UID:23BCS10559 CLASS:202A

OUTCOME
10 in a --> True
40 is a --> False
100 is a --> True

10 not in a --> False


40 not in a --> True

1.13.1 while loop


i=0 while
i<=10:
print(i) i
= i+1
OUTCOME
0

1
2
3
4
University Institute of Engineering
Department of Computer Science & Engineering
NAME: Harpreet Singh UID:23BCS10559 CLASS:202A

5
6
7
8
9
10

1.13.2 while loop


#while loop
i=10 while
i>=0:
print(i)
i = i-1
OUTCOME
10
9
8
7
6
5
4
University Institute of Engineering
Department of Computer Science & Engineering
NAME: Harpreet Singh UID:23BCS10559 CLASS:202A

3
2
1
0

1.14 Using Range Operator


print("range(10) -->",list(range(10))) print("range(0,20)
-->",list(range(0,20))) print("range(10,20) --
>",list(range(10,20))) print("range(0,20,2) --
>",list(range(0,20,2))) print("range(-10,-20,2) --
>",list(range(-10,-20,2))) print("range(-10,-20,-2) --
>",list(range(-10,-20,-2)))
OUTCOME
range(10) --> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
range(0,20) --> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
18, 19] range(10,20) --> [10, 11, 12, 13, 14, 15, 16, 17,
18, 19] range(0,20,2) --> [0, 2, 4, 6, 8, 10, 12, 14,
16, 18] range(-10,-20,2) --> []
range(-10,-20,-2) --> [-10, -12, -14, -16, -18]
University Institute of Engineering
Department of Computer Science & Engineering
NAME: Harpreet Singh UID:23BCS10559 CLASS:202A

1.15 For Loop For Making Table

a=7 for i in range(1,11): print(a,"*",i,"=",a*i)


OUTCOME
7 * 1 = 7
7 * 2 = 14
7 * 3 = 21
7 * 4 = 28
7 * 5 = 35
7 * 6 = 42
7 * 7 = 49
7 * 8 = 56
7 * 9 = 63
7 * 10 = 70
University Institute of Engineering
Department of Computer Science & Engineering
NAME: Harpreet Singh UID:23BCS10559 CLASS:202A

1.16 Define operator


#define operator def
Addition(a,b,c):
d=a+b+c
return d
Addition(10,20,5 )
OUTCOME
31
University Institute of Engineering
Department of Computer Science & Engineering
NAME: Harpreet Singh UID:23BCS10559 CLASS:202A

1.17 Importing Math libraries


import math as m
print("log(100,2))-->",m.log(100,2)) print("exp(-200)--
>",m.exp(-200))
print("m.cos(30)-->",m.cos(30))
OUTCOME
log(100,2))--> 6.643856189774725 exp(-200)-->
1.3838965267367376e-87
m.cos(30)--> 0.15425144988758405

6. Result and Summary: I have learned about the basic syntax for Python, how to declare a variable, use different
types of operators like assignment operators, bitwise logical operators, and assignment operators. Moreover,
if else, while loop and importing library
University Institute of Engineering
Department of Computer Science & Engineering
NAME: Harpreet Singh UID:23BCS10559 CLASS:202A

7. Additional Creative Inputs

Learning outcomes (What I have learnt):

1. .Understanding Python Syntax: I was able to demonstrate a fundamental understanding of the


basic syntax used in the Python programming language, including the proper structure and organization of
code

2. Variable Declaration: I was able to declare variablesin Python, understanding the concept of
assigning a value to a variable and the role it plays in storing and manipulating data.

3. Operator Usage: I was able to differentiate and apply different types of operators in Python, including
assignment operators to modify variable values, bitwise and logical operators for performing bitwise
operations and logical evaluations.

4. . Logical Expression Handling: I was able to gain proficiency in utilizing logical expressions
involving variables and operators, allowing us to make decisions and perform computations based on condition

5. Import Of Library: I was able to import mathlibrary and used it for various math formaulas

6. While Loop : created a table of 7 using this loop.

Evaluation Grid:
Sr. Parameters Marks Obtained Maximum Marks
No.
1. Student Performance 12
(Conduct of experiment)
2. Viva Voce 10
3. Submission of Work Sheet (Record) 8

Signature of Faculty (with Date): Total Marks Obtained: 30


University Institute of Engineering
Department of Computer Science & Engineering
NAME: Harpreet Singh UID:23BCS10559 CLASS:202A

You might also like