0% found this document useful (0 votes)
3 views

003 - 12-05-2020 Python Basics#1 Practicals Live

The document covers the basics of Python programming, including data types, arithmetic operators, and variable naming rules. It also discusses the installation of Python, execution modes, and provides practical examples and exercises related to string manipulation and arithmetic operations. Additionally, it highlights common errors in code and the correct syntax for various Python commands.

Uploaded by

samrosnovski003
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

003 - 12-05-2020 Python Basics#1 Practicals Live

The document covers the basics of Python programming, including data types, arithmetic operators, and variable naming rules. It also discusses the installation of Python, execution modes, and provides practical examples and exercises related to string manipulation and arithmetic operations. Additionally, it highlights common errors in code and the correct syntax for various Python commands.

Uploaded by

samrosnovski003
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 41

LIV

Python Basics #1
(Practicals)

1
LIV
List - Topics covered E

● Introduction to Python Programming


● Data types in Python
● Arithmetic Operators used with data of different
types
● Variables

2
LIV
High Level Languages E

Name four High Level


Languages other than Python.

QUESTION
C++
Pascal
Fortran
ANSWER Java

3
LIV
High Level Languages E

Python is an Interpreter based


scripting language, which can be
● create web based
used to...
applications.
QUESTION ● connect to database systems
and to read and modify files.
● handle big data and perform
complex mathematics.
ANSWER ● for rapid software
development

4
LIV
High Level Languages E

From where can we install


Python in our computer and
which version onwards it is
advisable to install ?
Python.org
QUESTION Version : 3.6
onwards
ANSWER

5
LIV
High Level Languages E

Which URL allows you to work


on your Python Programs using
your official email account?

QUESTION colab.research.google.
com
ANSWER

6
LIV
High Level Languages E

Python is a present Generation


Programming Language
because. QUESTION

● Platform Independent
● Free
● Open Source
● Simple
● Easy to Use
● GUI Programming
ANSWER ● Procedural & Object Oriented
Language

7
LIV
High Level Languages E

Mention 3 modes in which


Python codes can be executed.

QUESTION
Interactive Mode
Scripting Mode
Using Jupyter
ANSWER Notebook

8
LIV
High Level Languages E

Which two elements will form any


language (machine or natural, it
doesn’t matter) ?

QUESTION

An Alphabet
A Lexis
ANSWER

9
LIV
High Level Languages E

A Language is made up of…..

QUESTION

Syntax
Semantics
ANSWER

10
LIV
High Level Languages E

What is the datatype of the following


literals ?
"Sector 12 RK Puram"
False
95.6 QUESTION

String
Boolean
ANSWER Float

11
LIV
High Level Languages E

What is a difference between..


"True" and True

QUESTION

String literal
Boolean literal

ANSWER

12
LIV
High Level Languages E

What command will be used to


determine the datatype of integer
literal 928 ?
QUESTION

>>>type(928)
Output will be:
<class 'int'>
ANSWER

13
LIV
High Level Languages E

What are the different ways of


specifying floating point literals?

QUESTION 456.0
36.784
6E8
-13.55
0.0
ANSWER

14
LIV
High Level Languages E

Which of the following are valid string


literals?
"Python is interesting'
"I am enjoying learning 'Python"
"It's very simple" Invalid
Valid
"It supports "GUI""
Valid
'It is simple, easy to use' Invalid
QUESTION Valid
ANSWER

15
LIV
High Level Languages E

Which values are determined by the


truthfulness of a logical statement ?

QUESTION
True
False

ANSWER

16
LIV
High Level Languages E

What integer values are equivalent to


Boolean literals True and False ?

QUESTION
True : 1
False : 0

ANSWER

17
LIV
Output E

>>>"Hello","Friends"
PYTHON
_______
CODE
>>>"Hello"+"Friends"
_______
>>>"Hello",1+2 (Hello, Friends)
HelloFriends
________ (Hello, 3)
>>>"Hello","1+2" OUTPUT (Hello, 1+2)
_________

18
LIV
Output E

>>>2**3**2 PYTHON
_______ CODE
>>>(2**3)**2
_______
>>>2**(3**2) 512
64
________ 512
>>>2*3/2 OUTPUT 3.0
_________

19
LIV
Output E

>>>(2*3)/2
PYTHON
_______
CODE
>>>16 % 5 % 3
_______
>>>(16 % 5) % 3 3.0
1
________ 1
>>>16 % (5 % 3) OUTPUT 0
_________

20
LIV
Output E

>>>3*2*4
PYTHON
_________
CODE
>>>2.5*2*1.5
_________ 24
7.5
>>>"Hi"*3*2 HiHiHiHiHiHi
_________ Bye Bye Bye Bye Bye Bye
>>>3*"Bye "*2 123123123123

_________
>>>4*"123" OUTPUT
_________
21
LIV
Output E

>>>p=10/5
PYTHON
>>>q=p*4
CODE
>>>r=p*q
>>>p=p+q-r
>>>r=p-q+r
>>>q=p+q (-6.0, 2.0, 2.0)
>>>p,q,r
__________
OUTPUT

22
LIV
Output E

PYTHON
>>>12+3*4-6/2 CODE
___________
>>>12+(3**4-6)/2
___________
>>>12*(3%4)//2+6 21.0
___________ 49.5
24
>>>12%3**4//5+6
8
___________

OUTPUT
23
LIV
Output E

>>>A=12
PYTHON
>>>B="CAT" CODE
>>>B+B
________
>>>A*10
_________ CATCAT
120
>>>B*5
CATCATCATCATCAT
_________ OUTPUT

24
LIV
Output E

X=10
PYTHON
Y=5 CODE
>>>X+Y
__________
>>>"X"*Y
__________ 15
XXXXX
>>>X+Y/5*1
11.0
__________
OUTPUT

25
LIV
Output E

A=10 PYTHON
B=20 CODE
B=A-5
C=B-5
>>>A,B,C
(10, 5, 0)
__________

OUTPUT

26
LIV
Output E

PYTHON
>>>a=12
CODE
>>>b=5.5
>>>c=2
>>>a=a-b
>>>b=b*c
(6.5, 11.0)
>>>a,b
__________ OUTPUT

27
LIV
Output E

PYTHON
>>>A=10 CODE
>>>B=0.5
>>>C=3
>>>A+B-(B*10)+3
__________
8.5
>>>A**3+(C/3)+(A/5.0) 1003.0
__________ 8.0
>>> A/2+A//3
__________
OUTPUT
28
LIV
High Level Languages E

Name the 2 arithmetic operators used


to manipulate string literals ?

QUESTION
multiply operator *
addition operator +

ANSWER

29
LIV
Output E

Write a command to display a string


literal "Python" 3 times using shell
mode?

QUESTION
>>>"Python"*3

ANSWER

30
LIV
Output E

QUESTION
Write a command to display the given
string literals on same line using shell
mode :
"Python "
"is "
"Easy and "
"Simple to use"
ANSWER
>>>"Python "+"is "+"Easy and "+"Simple to use"

31
LIV
Variable E

Python variables can have ..

QUESTION ● A variable name


● An associated value
ANSWER

32
LIV
Variable Rules E

What are the rules for naming


variables in Python ? ● Alphabets in Uppercase
& Lowercase, Digits,
Underscore ( _ ) are
QUESTION allowed
● Must begin with _ or
Letter.
● Names are case sensitive
● No reserved keywords
ANSWER allowed

33
LIV
Valid or Invalid ? E

Which of the following variable


QUESTION
names are valid or invalid ?
Firstname*
Print
Invalid
Full&name Valid
Full address Invalid
Invalid
_age Valid
True Invalid
11thclass Invalid

ANSWER
34
LIV
Valid or Invalid ? E

Which of the following are


QUESTION
reserved keywords ?
print
name
If No
No
break
No
for Yes
true Yes
No
not
Yes
ANSWER
35
LIV
Code Errors ? E

Find the errors in the given code? QUESTION


class=11
name="Suzan"
perce%nt=80

Invalid name
Valid
Invalid name

ANSWER
36
LIV
Code Errors ? E

Find the errors in the given code?


QUESTION
20=a
x=10+b
20-2=y
z=5 Invalid assignment
x=z+10 Invalid(b not defined)
Invalid assignment
y=x Valid
Valid
Valid

ANSWER
37
LIV
Code Errors ? E

Find the errors in the given QUESTION


code?
a=3
s="4"+10
a="5"
a+4
Valid assignment
Invalid (str+int not allowed)
Valid
Invalid (str+int not allowed)
ANSWER
38
LIV
Code E

Write code for the given QUESTION


instructions ?
● Create a variable radius
with the value 10
● Assign an expression for
area calculation using >>>radius=10
above radius variable to >>>AREA=3.14*radius**2
>>>AREA
another variable AREA
● Print the value of the
variable AREA ANSWER
39
LIV
Code E

Write code for the given QUESTION


instructions ?
● Create 3 variables for
ANSWER
storing marks of
Phy,Chem,Computers with
any value. >>>Phy=90
>>>Chem=92
● Assign an expression for
>>>Comp=98
average calculation using >>>AVG=(Phy+Chem+Comp)/3
above variables to another >>>AVG
variable AVG
● Print the value of the 40
LIV
E

Thank You
Computer Science Department
Delhi Public School, R.K.Puram

You might also like