1. This built-in function can be used to convert an float value to a int.
float_to_int()
float()
convert()
int()
D. int()
2. Which of the following statements will cause an error?
num = 17
17 = num
num = 99999
num = '17'
B. 17 = num
3. A string literal in Python must be enclosed in
parentheses
single-quotes
double-quotes
either single-quotes or double-quotes
D. either single-quotes or double-quotes
4. Which of the following is the valid variable name:
global
99flag
sum
an$wer
C. sum
5. Which are correct arithmetical operations?
num = 1*2
4 = 2+2
5 + 6 = x
Seven = 3 * 4
A and D
6. Which operations result in 6?
50 // 8
16 % 5
2 * * 3
36 * * 0.5
A,B and D
7. If the value of a = 20 and b = 10, then a += b will assign ________ to a
40
30
20
10
B. 30
8. The _____ is the modulus operator.
*
%
**
//
B. %
Short Answer
9. If a math expression adds a float to an int, what will the data type of the result be?
float
10. What would the following display?
num = 20
num = 5
print(num)
5
11. What will the following statement display?
print('John', 'David', 'Rahul', 'Rita', sep='@')
John@David@Rahul@Rita
12. What is the type of the following result:
1 + 2.0 + 3
float
13. What is a variable? What names may variable have?
A variable is a name that represents a value in the computer’s memory.
You must follow these rules for naming the variable:
A variable name can be of any size
A variable name have allowed characters, which are a-z, A-Z, 0-9 and underscore (_)
A variable name should begin with an alphabet or underscore
A variable name should not be a keyword
A variable name cannot contain spaces.
Uppercase and lowercase characters are distinct.
14. How are keywords different from variable names?
There are some reserved words in Python which have predefined meaning called keywords.
These words may not be used as variable name.
15. What is Runtime error. Explain with example.
Run time errors arise when the python knows what to do with a piece of code but is unable to perform the action. Example: using an undefined variable. This can also occur if you use capital letters inconsistently in a variable name:
day = "Sunday"
print(Day)