二手产品经理

二手产品经理

THIS IS RENO

Learn Python Online in 100 Days - Week 3 Day 1

Record#

  1. Today I learned about while loops. While is a looping function. It repeats execution when the condition is not met.
  2. When using looping functions, pay attention to the number of loops and parameters, and be sure not to fall into an infinite loop.
  3. Common errors include:
    1. The number does not change with each execution, the counter does not change. Generally, the parameter increases by 1 with each execution. Exit when the condition is met.
    2. It is not necessary for the counter to change with each execution, it can also be a string or similar. When I see this, I remember the game code from yesterday, where I could repeat execution using while. When the user does not input 'rsp', repeatedly prompt the user for input.
    3. The looping structure of while is very important, just like the indentation in Python. If there are indentation errors with the counter, and they are not within the while loop, the program may encounter unexpected situations.

CODE#

exit = "no"
while exit != "yes":
  animal = input("What animal sound would you like to hear? ")
  print("The sound of", animal, "!")
  exit= input("Can you exit now? yes or no: ")
Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.