2017.8.31 Codecademy

練習1

  1. def a function called cube that takes an argument called number.
  2. make that function return the cube of that number (i.e. that number multiplied by itself and multiplied by itself once again).
  3. def a second function called by_three that takes an argument called number.
  4. if that number is divisible by 3, by_three should call cube(number) and return its result.
  5. otherwise, by_three should return False.
def cube(number):
   return number * number * number

def by_three(number):
   if number % 3 == 0:
     return cube(number)
 else:
     return False

print(cube(2))
print(by_three(3))
print(by_three(4))

8
27
False

閱讀更多»

2017.8.29 Codecademy

  1. “%s" 可以被 “% ( )"內的字串給取代 (按照順序) (s=substitution)
  2.  " \ " 用來將程式碼換行
name='Jumping'
quest='learning Python'
color='black'

print('Ah, so your name is %s, your quest is %s,' \
' and your favorite color is %s.' % (name, quest, color))

Ah, so your name is Jumping, your quest is learning Python, and your favorite color is black.

閱讀更多»