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

Week 1

Uploaded by

Gopika Srividhya
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Week 1

Uploaded by

Gopika Srividhya
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 28

Python for Data

Science
Live Interactive Problem-Solving Session
U. Sethu Vinayagam
PhD Scholar
Department of Civil Engineering, IIT
Madras
Introduction to Python

Overview • Programming in Python


• Advantages
• Different Coding Environments

Introduction to Spyder

• GUI
• Setting Working Directory
• Working with Scripts
• File Execution
• Using the Console

Variables and Data Types

• Naming Rules
• Basic Data Types – Identification, Verification and Coercion

Operators

• Operators vs. Operands


• Types – Arithmetic, Assignment, Relational, Logical, Bitwise, etc.
• Precedence of Operators

Python for Data Science (noc24-ce68) Week 1 2


Which of the following are operators, and which are
Question 1 values?

a) *
b) 'hello'
c) -88.8
d) -
e) /
f) +
g) 5

Python for Data Science (noc24-ce68) Week 1 3


Which of the following is a variable, and which is a
Question 2 string?

a) spam
b) 'spam'

Python for Data Science (noc24-ce68) Week 1 4


Name three data types.
Question 3

Python for Data Science (noc24-ce68) Week 1 5


What is an expression made up of? What do all
Question 4 expressions do?

Python for Data Science (noc24-ce68) Week 1 6


What does the variable bacon contain after the
Question 5 following lines of code run?

bacon = 20
bacon + 1

Python for Data Science (noc24-ce68) Week 1 7


What should the following two expressions evaluate
Question 6 to?

'spam' + 'spamspam'
'spam' * 3

Python for Data Science (noc24-ce68) Week 1 8


Why is eggs a valid variable name while 100 is
Question 7 invalid?

Python for Data Science (noc24-ce68) Week 1 9


What three functions can be used to get the integer,
Question 8 floating-point number, or string version of a value?

Python for Data Science (noc24-ce68) Week 1 10


Why does the following expression cause an error?
Question 9 How can you fix it?

'I have eaten ' + 99 + ' burritos.'

Python for Data Science (noc24-ce68) Week 1 11


Which of the following is a valid variable name in
Question 10 Python?

a) 1st_name
b) my-variable
c) my_variable
d) @variable

Python for Data Science (noc24-ce68) Week 1 12


What is the correct way to assign the value 10 to a
Question 11 variable named number?

a) number = 10
b) 10 = number
c) number := 10
d) let number = 10

Python for Data Science (noc24-ce68) Week 1 13


Which of the following data types is used to
Question 12 represent text in Python?

a) int
b) float
c) str
d) bool

Python for Data Science (noc24-ce68) Week 1 14


What is the output of the following code?
Question 13 x=5
y=3
print(x + y)

a) 8
b) 53
c) 2
d) Error

Python for Data Science (noc24-ce68) Week 1 15


Which operator is used for exponentiation in
Question 14 Python?

a) **
b) ^
c) //
d) %

Python for Data Science (noc24-ce68) Week 1 16


What is the result of the expression 5 % 2?
Question 15
a) 2
b) 1
c) 0
d) Error

Python for Data Science (noc24-ce68) Week 1 17


Which operator is used for floor division in Python?
Question 16
a) /
b) //
c) %
d) *

Python for Data Science (noc24-ce68) Week 1 18


Which data type is used to represent decimal
Question 17 numbers in Python?

a) int
b) float
c) str
d) bool

Python for Data Science (noc24-ce68) Week 1 19


What is the output of the following code?
Question 18 x = "hello"
y = "world"
print(x + " " + y)

a) helloworld
b) hello world
c) hello+world
d) Error

Python for Data Science (noc24-ce68) Week 1 20


Which data type is used to represent boolean values
Question 19 (True or False) in Python?

a) int
b) float
c) str
d) bool

Python for Data Science (noc24-ce68) Week 1 21


Which of the following is a valid way to declare
Question 20 multiple variables in a single line in Python?

a) x, y, z = 1, 2, "hello"
b) x = 1; y = 2; z = "hello"
c) x = 1 y = 2 z = "hello"
d) All of the above

Python for Data Science (noc24-ce68) Week 1 22


What is the data type of the following expression?
Question 21 3 + 4.5j

a) int
b) float
c) complex
d) str

Python for Data Science (noc24-ce68) Week 1 23


Consider the following code:
Question 22 x = "5"
y = int(x)
What is the data type of y?

a) str
b) int
c) float
d) None

Python for Data Science (noc24-ce68) Week 1 24


What is the result of the following expression?
Question 23 True and not False

a) True
b) False
c) None
d) Error

Python for Data Science (noc24-ce68) Week 1 25


Given the following code:
Question 24 x=5
y=2
z = x // y
What is the value of z?

a) 2.5
b) 2
c) 3
d) Error

Python for Data Science (noc24-ce68) Week 1 26


Which of the following operators has the highest
Question 25 precedence?

a) +
b) *
c) **
d) //

Python for Data Science (noc24-ce68) Week 1 27


What is the output of the following code?
Question 26 x=5
y=3
z=x%y
print(z)

a) 1
b) 2
c) 1.66
d) Error

Python for Data Science (noc24-ce68) Week 1 28

You might also like