Day7_100days of code in python

Indentation:

def my_function():
   print("Hello")

Spaces vs. Tabs

PEP 8 -- Style Guide for Python Code | Python.orgDay7_100days of code in pythonhttps://www.python.org/dev/peps/pep-0008/

While loops

What about the for loop:

for item in list_of_items:
  #Do something to each item
for number in range(a,b):
  print(number)

While

while something_is_true
  #Do something repeatedly

while +condintion:

Infinite loop

if you don't know why it is an infinite loop, just print the condition.

def turn_right():
    turn_left()
    turn_left()
    turn_left()
def jump():
    turn_left()
    while front_is_clear() and wall_on_right():
        move() 
    turn_right()
    move()
    turn_right()
    move()
    while front_is_clear() and wall_on_right():
        move() 
    turn_left()
while not at_goal():
    if front_is_clear():
        move()
    elif wall_in_front():
        jump()

成功啦!!!

上一篇:java – 重新设置项目而不更改所有项目的排名


下一篇:Day7 类型转换