75. Python Program to Get the Last Few Temperatures from a List
MediumSlicing
Overview
Slice from the end of a list, with a number the user chooses.
Problem Statement
A week of temperatures is stored in a list: 30, 32, 29, 31, 35, 33, 28 (the last one is today). Read a whole number n. If it is from 1 to 7, print the last n temperatures, using one slice. Otherwise print Enter a number from 1 to 7. For example, for 3:
Temperatures: [35, 33, 28]
Use input() with no prompt text: the tests type the input for you, and a prompt would end up in your output.
Input
One value per line, in this order. Example:
3
Output
The output for that example:
Temperatures: [35, 33, 28]
The tests try 5 different inputs.