Modular division:
Answer must be smaller than the denominator, answer must be whole number:
For 4, you can only get answers 0, 1, 2, 3. For 7, 0, 1, 2, 3, 4, 5, 6.
Floor Division:
Rounds down. For 9/4, you would just get 2. Even if the answer is 9.9, it still rounds to 9
and not 10.
Integer:
Data type used to represent ONLY WHOLE NUMBERS. Pos or Neg, includes 0. Has:
Unlimited Precision:
Work with very small or very large numbers with accuracy.
Immutable:
Cannot be changed once assigned
Integer-Specific Functions:
abs():
Calculates absolute value
pow()
For exponentiation
Casting Functions:
int()
Converting other data types to integers.
When used on floats, it tosses out the decimals. When used on strings,
only works on number strings and just converts it.
float()
Same as int(), but becomes floating point number.
Adds .0 onto integers.
string()
Same as int(), but becomes a string.
CALCULATING HOURLY WAGE
● Variables needed in program:
We need two inputs: hours_worked and pay_rate.
Then we need one output: gross_pay.
● What kind of string formatting should you use for your output?
1. Concatenation
2. With the % operator
3. With the format() method
4. With string literals, f-strings
● Research how you will keep your decimal points to 2 decimal places and implement it.
Use some variation of round(x, 2), which should round it to the nearest 2 decimal places.
● Flowchart:
START
INPUT: Ask for hours_worked and pay_rate: Both floats.
PROCESSING: multiply the hours_worked by the pay_rate to get gross_pay.
OUTPUT: Round gross_pay to 2 decimal spaces and print the gross_pay.
TEMPERATURE CONVRSION
● Research how to turn a Celsius temperature into a Fahrenheit temperature.
Celcius temp * 1.8 + 32 = Fahrenheit Temp.
● Decomposition
temp_celcius (input) * 1.8 + 32 = temp_fahr (output)
● Test cases
1. 17.92 into 64.256
2. 2026.01 into 3678.818
3. -440 into -760
4. 0 into 32
5. 1 billion (1000000000) into 1800000032