CMPT 120 Chapter Notes - Chapter 2: Type Conversion

10 views2 pages
meghan78 and 39786 others unlocked
CMPT 120 Full Course Notes
29
CMPT 120 Full Course Notes
Verified Note
29 documents

Document Summary

The division operation does different things with integers than with floating point values. So, 10, 0, and -100 are all integers. Numbers with fractional parts, like 3. 14, -0. 201, and 10. 0, are stored as floating point values. These two types are represented differently in the computer"s memory, different types of values given. In the case of integer division (10/3), the rule is that the result must be an integer. The floating point result has its fractional part rounded down to give the integer 3. For floating point division, the result can have a fractional part, so the result is what you"d probably expect. You can trick python into treating a whole number like a floating point number by giving it a fractional part with you type it. So 10 is an integer (or int for short), but 10. 0 is a floating point value (or float ). Suppose you want to calculate the average of several integers.

Get access

Grade+
$40 USD/m
Billed monthly
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
10 Verified Answers
Class+
$30 USD/m
Billed monthly
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
7 Verified Answers

Related Documents

Related Questions