You are on page 1of 2

R Anterior Unidade 3 de 7 S Avançar T

" 100 XP

Exercício: trabalhar com a saída


8 minutos

Todas as áreas restritas do Microsoft Learn estão em uso no momento. Aguarde de cinco a dez minutos e tente
novamente.

Para obter mais informações, confira a página de orientação para a solução de problemas.

Tentar ativar a área restrita novamente

 Tempo de execução Arquivo Editar Exibir  Comentários

 Executar tudo   Kernel   Computação não conectado

    

Your first program


You will use a Jupyter notebook to create your first program. Your senior officer wants you to create code to perform a
couple of utilities. You will start by displaying today's date. Then you will add code to convert parsecs to lightyears.

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.

Display today's date


In the cell below, add the code to display today's date. Remember you can use the date object from the datetime
library to access calendar information.

# Add the code below

Your code should look like the following:

from datetime import date

print(date.today())
Build a unit converter
Now it's time to turn your attention to the second utility, converting parsecs to lightyears. One parsec is 3.26 lightyears,
so you will multiply parsecs by that value to determine lightyears.

Create a variable named parsecs and set it to 11 . Then add the code to perform the appropriate calculation and
# Enter code below
store the result in a variable named lightyears . Finally print the result on the screen with so it displays a message
which resembles the following:

11 parsecs is ___ lightyears


YourRemember to you
code should can use
resemble thestr to convert numbers to strings
following:

parsecs = 11
lightyears = parsecs * 3.26
print(str(parsecs) + " parsecs is " + str(lightyears) + " lightyears")

Desired output
When you run the notebook you should see the following result:

11 parsecs is 35.86 lightyears

 Sem computação Computação não conectado  Exibição Kernel não conectado

Unidade seguinte: Coletar entrada

Continuar T

You might also like