Professional Documents
Culture Documents
Q1
• Identify the datatype for these values/ results of expressions:
a. 4 __________
b. 3.5 __________
c. “hello” __________
d. True __________
e. 3 + 4.5 __________
Q2: Conversion of Data types
a = 2
b = 1.5
c = ’12’
d = ‘alan’
With reference to the codes above, write the result of the following commands:
If the command lead to error, state “error”
If the result is a string value, enclose in quotes
a. float(a) _________
b. str(a) _________
c. int(d) _________
d. int(b) _________
e. float(c) _________
f. str(int(b)) _________
Q3.1: Variables and Data Type
Write the code to perform the following tasks:
a. Create a variable X and assign it a value of 5.
b. Create a variable y and assign it a value of 1.5
c. Create a variable z and assign it a value of “hello world”
d. Create a variable is_raining and assign it with a value of False.
e. Create another variable is_weekday and assign it with a value of True.
f. Concatenate (Join) two values “Happy” and “Birthday” with a space in
between. Assigned the result to a variable greeting.
g. Convert the integer: 42 to a float.
h. Convert the string: “5” to an integer.
i. Convert the number: 5.6 to a string.
Q3.2: Variable and Data Type
Examine each of the python command given. State the name of the variable that is
being assigned a value, the value assigned and the data type of the variable. The
answer for the first statement is given as example: