二手产品经理

二手产品经理

THIS IS RENO

Learn Python Online in 100 Days - Week 3, Day 1

Record#

  1. Today I learned about while, which is a looping function. It repeats execution until the condition is no longer satisfied.
  2. When using a looping function, it is important to pay attention to the number of loops and parameters to avoid getting stuck in an infinite loop.
  3. Common errors include:
    1. The number does not change with each execution, and the counter does not change. Usually, the parameter should be incremented after each execution. Exit when the condition is met.
    2. The counter does not necessarily change with each execution, it can also be a string or something similar. When I see this, I remember the game code from yesterday. I can use while to repeat the execution. When the user's input is not "rsp", keep asking the user for input.
    3. The structure of the while loop is very important, as well as the indentation in Python. If there are indentation errors with the counter or something similar, and they are not within the while loop, the program may behave unexpectedly.

CODE#

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