You are on page 1of 4

Assignment 1

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

'*' -> Multiplication Operator


'hello' -> Value
-88.8 -> Value
'-' -> Subtraction Operator
/ -> Division Operator
'+' -> Addition Operator
5 -> Value

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

spam -> Variable


'spam' -> String

3. Name three data types.

1) Textual Datatype -> str


2) Numeral Datatype -> int, float, complex
3) Logical Boolean Datatype -> bool

4. What does the variable bacon contain after the following code runs?

bacon = 20 -> It contains 20


bacon + 1 -> It contains 21

5. What should the following two expressions evaluate to?

'spam' + 'spamspam' -> String Concatenation 'spamspamspam'


'spam' * 3 -> -> String Multiply 'spamspamspam'

6. Why is eggs a valid variable name while 100 is invalid?

'eggs' -> It is a variable since it is starting with a letter.


100 -> It is invalid because it starts with a number.
7. What three functions can be used to get the integer, floating-point number, or string
version of a value?

Integer -> int()


Floating-point -> float()
String -> str()

7. Why does this expression cause an error? How can you fix it?

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


It causes and error since we are concatenating string and integer.
Solution will be to use 99 as a string, i.e., '99'
'I have eaten ' + '99' + ' burritos.'

8. What are the two values of the Boolean data type? How do you write them?

The two Booleans are True and False.


We write them as True, False

9. What are the three Boolean operators?

They are 'and', 'or' and 'not'.

3. Write out the truth tables of each Boolean operator

AND Truth Table
A B O/p
000
010
100
111
OR Truth Table
A B O/p
000
011
101
111
NOT Truth table
A O/p
01
10

4. What do the following expressions evaluate to?

(5 > 4) and (3 == 5) -> False


not (5 > 4) -> False
(5 > 4) or (3 == 5) -> True
not ((5 > 4) or (3 == 5)) -> False
(True and True) and (True == False) -> -> False
(not False) or (not True) -> True
Que. What are the six comparison operators?
== -> Equal
!= -> Not equal
'>' -> Greater than
'<' -> Less than
'>=' -> Greater than or equal to
'<=' -> Less than or equal to
Que. What is the difference between the equal to operator and the assignment operator?
Equal to Operator --> == (Double sign)
Assignment Operator --> = (Single sign)

7. Explain what a condition is and where you would use one.

Condition is similar as Where clause, in which thw next flow or operation is dependent on
the mentioned condition whether it is true or false.
The condition can be used in a situation where the tickets of various blocks in a show are
issued on the basis of price paid.

10. What keys can you press if your program is stuck in an infinite loop?

Ctrl + C

11. What is the difference between break and continue?

Break: Breaks or Stops the current iteration of loop.


Continue: It skips the current iteration and the control moves forward to next step or
iteration.

12. What is the difference between below in a for loop?


range(10) -> One arguement means where the loop should stop.
range(0, 10) -> Means the start and stop range of a loop.
range(0, 10, 1) -> Start, stop and steps to be taken by a loop.

You might also like