3.7 Type Conversion
What is the result of each expression? str(99)
'99'
What is the result of each expression? 1) int(1.55)
1
Type the program's output number = 2 new_number = number * 5 print(new_number)
10
num_items = 5 item_weight = 0.5 For any floating-point answer, type answer to tenths. Ex: 8.0, 6.5, or 0.1 1) num_items + num_items
10
Type the program's output: number = 3 new_number = number * 4 print(new_number)
12
Type the program's output number = 1.0 new_number = number * 2.0 print(new_number)
2.0
num_items = 5 item_weight = 0.5 For any floating-point answer, type answer to tenths. Ex: 8.0, 6.5, or 0.1 2) item_weight * num_items
2.5
Type the program's output number = 3.0 new_number = number * 1 print(new_number)
3.0
num_items = 5 item_weight = 0.5 For any floating-point answer, type answer to tenths. Ex: 8.0, 6.5, or 0.1 3) (num_items + num_items) * item_weight
5.0
Type the output Input: 5.7 number_string = input() number_float = float(number_string) number_int = int(number_float) print(number_string) print(number_float) print(number_int)
5.7 5.7 5
Type the program's output number = 6.5 new_number = int(number) print(new_number)
6
What is the result of each expression? 2) float("7.99")
7.99
Type the program's output number = 9 new_number = float(number) print(new_number)
9.0
Creates strings and Converts Any
str()
a conversion of one type to another, such as an integer to a float.
type conversion
Creates floats Converts integer, float, strings w/integers or fractions
float()
a type conversion automatically made by the interpreter, usually between numeric types
implicit conversion
Creates integers converts integer, float, strings w/integers only
int()