Variable & Data Type
Save the result of (42 - 11) * 22 to result.
Print result.
2.variabel
Store the value 15 in a variable named a_value.
Store the result of (25 - 7) * 17 to a variable named a_result.
Using the print() command, display the following:
The value stored in the a_value variable.
The result of adding 12 to the variable a_result.
The result of adding a_value to a_result.
3.Variable names
In the code editor on the right, we attempted to store 34000 in a variable named old-income, and 40000 in a variable named new income. But both of these variable names cause syntax errors, so we commented-out the code.
Change the variable name old-income to old_income to prevent a syntax error.
Change the variable name new income to new_income to prevent a syntax error.
The variable income is already shown in the code editor on the right.
Print income.
5. Syntax Shortcuts
Assign a value of 20 to a variable named variable_1.
Assign a value of 20 to a variable named variable_2.
Update the value of variable_2 by adding 10 to its current value. You can take advantage of the += operator.
Update the value of variable_1 by multiplying its current value by 4. You can take advantage of the *= operator.
Display variable_1 and variable_2 using print().
6. Integers & Floats
Assign the integer 10 to a variable named variable_1.
Assign the float 2.5 to a variable named variable_2.
Update the value of variable_1 by adding the float 6.5 to its current value. You can use the += operator.
Update the value of variable_2 by multiplying its current value by the integer 2. You can use the *= operator.
Display variable_1 and variable_2 using print().
7. Conversion Between Types
Assign the value 2.8 to a variable named variable_b.
Round variable_a using the round() command, and assign back the rounded value to variable_a.
Convert variable_b from a float to an integer using the int() command, and assign back the converted value to variable_b.
Display variable_a and variable_b using the print() command.
Komentar
Posting Komentar