-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPractice_Questions.txt
More file actions
80 lines (64 loc) · 3.91 KB
/
Copy pathPractice_Questions.txt
File metadata and controls
80 lines (64 loc) · 3.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
********************************************************************************************************************************************************
1. Which of the following are operators, and which are values?
*
'hello'
-88.8
-
/
+
5
Ans:
'*' is an operator, it is used for 'multiplicaiton'
'hello' is a string, so it is a value
'-88.8' is a float, so it is a value
'-' is an operator, it is used for 'substraction'
'/' is an operator, it is used for 'division'
'+' is an operator, it is used for 'addition'
'5' is an integer, so it is a value
********************************************************************************************************************************************************
2. Which of the following is a variable, and which is a string?
spam
'spam'
Ans:
spam - is a variable name
'spam' - is a string
********************************************************************************************************************************************************
3. Name three data types.
Ans:Integers, Floats and Strings
********************************************************************************************************************************************************
4. What is an expression made up of? What do all expressions do?
Ans: Expression is a combination of values, variables, operators, and calls to functions. Expressions need to be evaluated.
********************************************************************************************************************************************************
5. This chapter introduced assignment statements, like spam = 10. What is
the difference between an expression and a statement?
Ans:
Expression is a combination of values, variables, operators, and calls to functions. Expressions need to be evaluated.
Statements does something. Statements represent an action or command, example: print(statements), assign(statements)
********************************************************************************************************************************************************
6. What does the variable bacon contain after the following code runs?
bacon = 20
bacon + 1
Ans: 21
********************************************************************************************************************************************************
7. What should the following two expressions evaluate to?
'spam' + 'spamspam'
'spam' * 3
Ans:
'spam' + 'spamspam' = 'spamspamspam' - As they both are strings so get concatinated and added
'spam' * 3 = 'spamspamspam' - It multiplied the string * 3
********************************************************************************************************************************************************
8. Why is eggs a valid variable name while 100 is invalid?
Ans:
eggs is valid because the Python interpretter doesn't know it as a value
100 is invalid because the Python interpretter knows it as a value
********************************************************************************************************************************************************
9. What three functions can be used to get the integer, floating-point
number, or string version of a value?
Ans: int(),float(), str() functions will evaulate to the integer, floating-point number and string versions of the value
********************************************************************************************************************************************************
10. Why does this expression cause an error? How can you fix it?
'I have eaten ' + 99 + ' burritos.'
Ans:
When we execute the above expression we see the error as "TypeError: can only concatenate str (not "int") to str". 99 is an 'int' and it can't concatinate an 'int' with 'string', hence we should modify it as string as follow:
'I have eaten ' + str(int(99)) + ' burritos.'
********************************************************************************************************************************************************