More On Data Types Ans.

Home / U2: Math & Logic / More On Data Types Ans.
2.2_answers

Print the type of all of the following variables. Try to guess what it is beforehand.

In [4]:
w = "1"

x = 2.0

y = 3

z = x + y

print(type(w))
print(type(x))
print(type(y))
print(type(z))
<class 'str'>
<class 'float'>
<class 'int'>
<class 'float'>
In [8]:
# one will need conversion!
answer = int(w) + x + y + z
print(answer)
11.0

Now, add all of them together. If an error is produced, find and fix it.

Get this program to run:

w = 10

x = "1"

y = "20"

z = 30.0

answer = x + y + z

print(answer)

I did the following. It is normal to see some variation, as long as the answer is right.

In [12]:
w = 10 

x = "1"

y = "20"

z = 30.0

answer = w + int(x) + int(y) + z

print(answer)
61.0

What is the type of the answer?

In [13]:
print(type(answer))
<class 'float'>