Day7_100days of code in python

2021/10/24 1:10:05

本文主要是介绍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()

成功啦!!!



这篇关于Day7_100days of code in python的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程