Python Practice Lab
easyUnit 6 · Lists & Tuples

P17. Rotate a List

Lists & Tuples

Read a list of integers and a number k. Rotate the list to the left by k positions using slicing. If k is larger than the list length, use k % length. Then print the first and last elements of the rotated list as a tuple.

Input Format

  • Line 1: integers separated by spaces
  • Line 2: k

Output Format

  • Line 1: Rotated: <list>
  • Line 2: Ends: <(first, last)>

Constraints

  • 1 ≤ number of integers ≤ 100
  • 0 ≤ k ≤ 1000

Sample Test Cases

Sample 1
Input
1 2 3 4 5
2
Output
Rotated: [3, 4, 5, 1, 2]
Ends: (3, 2)
Sample 2
Input
10 20 30
0
Output
Rotated: [10, 20, 30]
Ends: (10, 30)

Submitting checks 2 sample cases and 3 hidden test cases.

Hints

Saved
Custom 1

This is your own input, so Run will show what your program prints but can't say whether it's correct.