You are on page 1of 2

1/24/24, 4:36 PM Exercice : travailler avec une sortie - Training | Microsoft Learn

R Précédent Unité 3 sur 7 S Suivant T

" 100 XP

Exercice : travailler avec une sortie


8 minutes

Bac à sable activé. Temps restant : 53 min

Vous avez utilisé 2 bacs à sable sur la limite de 10 disponible aujourd’hui. D’autres bacs à sable seront
disponibles demain.

 Runtime Fichier Modifier Voir  Commentaires

 Tout exécuter   Noyau   non connecté du calcul

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,
follo ed b an empt cell Enter o r P thon into the cell and r n it The sol tion for each step ill follo each

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())

    

https://learn.microsoft.com/fr-fr/training/modules/python-create-run-program/3-exercise-print 1/2
1/24/24, 4:36 PM Exercice : travailler avec une sortie - Training | Microsoft Learn

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 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
code should resemble
to you thestr
can use following:
to convert numbers to strings

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

 learn-notebooks-d078fe10-e421-4b5d-b2db-b4a0e0c27aff non connecté du calcul  Consultation Noyau non connecté

Unité suivante: Collecter les entrées

Continuer T

https://learn.microsoft.com/fr-fr/training/modules/python-create-run-program/3-exercise-print 2/2

You might also like