20160131 [Codecademy] Python(1)

Lesson:Python SyntaxTip Calculator

[ 筆記內容 ] Python SyntaxTip Calculator
  • (一)Variables and Data Types
  • 1.  Variables
  • 2.  Booleans
  • 3.  Reassigned
  • (二)Whitespace and Statements
  • 1.  Whitespace
  • (三)Comments
  • 1.  Single Line Comments
  • 2.  Multi-Line Comments
  • (四)Math Operations
  • 1.  Math
  • 2.  Exponentiation
  • 3.  Modulo
  • (五)Review
  • Tip Calculator
  • 1.  The Meal
  • 2.  The Tax
  • 3.  The Tip
  • 4.  Reassign in a Single Line
  • 5.  The Total
 
 
 
 

(一)Variables and Data Types

1.  Variables
  • A variable stores a piece of data, and gives it a specific name.
  • [ 範例 1 ] Variables
  • Set the variable my_variable equal to the value 10.
# Write your code below!
my_variable = 10
 
 
2.  Booleans
  • A boolean is like a light switch. It can only have two values. Just like a light switch can only be on or off, a boolean can only be True or False.
  • [ 範例 2 ] Booleans
  • Set the following variables to the corresponding values:
  1. my_int to the value 7
  1. my_float to the value 1.23
  1. my_bool to the value True
# Set the variables to the values listed in the instructions!
 
my_int = 7        # interger
my_float = 1.23   # float
my_bool = True    # boolean