Professional Documents
Culture Documents
36 Exercício - Criar Um Loop 'While' - Training - Microsoft Learn
36 Exercício - Criar Um Loop 'While' - Training - Microsoft Learn
" 100 XP
Uma área restrita fornece acesso a recursos gratuitos. Não haverá cobranças na sua assinatura pessoal. A área
restrita poderá ser usada somente para concluir o treinamento no Microsoft Learn. O uso por qualquer outro motivo
é proibido e poderá levar à perda permanente do acesso à área restrita.
A Microsoft fornece essa experiência de laboratório e o conteúdo relacionado para fins educacionais. Todas as
informações apresentadas são de propriedade da Microsoft e destinam-se exclusivamente à aprendizagem sobre os
produtos e os serviços abordados neste módulo do Microsoft Learn.
In this exercise, you're creating an application that prompts a user to enter a list of planets. In a later exercise, you'll add
code that displays the list. For now, though, you'll create only the code that prompts the user.
This exercise is broken into a series of steps. For each step you will be presented with the goal for the step, followed by
an empty cell. Enter your Python into the cell and run it. The solution for each step will follow each cell.
Start by adding two variables, one for the input from the user, named new_planet , and another variable for the list of
planets named planets
new_planet = ''
planets = []
Create a while loop
Starting with the variables you've just created, create a while loop. The while loop will run while new_planet is not
set to done.
Inside the loop, check to see whether the new_planet variable contains a value, which should be the name of a planet.
This is a quick way to see whether the user has entered a value. If they have, your code will append that value to the
planets variable.
Complete the while loop by using input to prompt the user to enter a new planet name or done if they're done
# Enter
entering code below:
planet names. You'll store the value from input in the new_planet variable.
[2]
Finally, outside of the while loop, print the list of planets by using print .
A l t thi t f th i tt ti t t bl l t d i t th t ti
Your code should look like this:
print(planets)
Desired output
When you run your notebook you will be prompted for new planet names until you enter done. (Enter a planet name
and select "Submit". For each new entry, overtype the previous entry and select "Submit".) Then you will be presented
with a list of the planets you entered.
Continuar T