编程语言
首页 > 编程语言> > Day7_100days of code in python

Day7_100days of code in python

作者:互联网

Indentation:

def my_function():
   print("Hello")

Spaces vs. Tabs

PEP 8 -- Style Guide for Python Code | Python.orgicon-default.png?t=L9C2https://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()

成功啦!!!

标签:code,Day7,move,turn,while,right,100days,front,left
来源: https://blog.csdn.net/Xiaoyu0224/article/details/120926603