Problem

4/7

Operations with tuples. Comparison

Theory Click to read/hide

Comparing tuples

When comparing tuples: 
- numbers are compared by value; 
- strings in lexicographical order; 
- in case of equality of elements in the same positions, the following elements are compared; 
- comparison of elements will occur until the first inequality; 
- when comparing, elements must be cast to the same type (you cannot compare a number and a string). 

 
Example
1
2
3
4
5
6
7
8
9
10
eleven
12

A=4 B=8 C = 'a', D = 'z', E = (14, 'maximum', 'minimum') F = (14, 'maximum', 'min') K=999 print(A < B)    # True print(C < D)    # True print(E > F)    # True print(K < F)    # False print(C < K)    # TypeError: '<' not supported # between instances of 'str' and 'int'

Problem

4 lines are input:

1-2) character strings;
3-4) a sequence of numbers (each number separated by a space).

Complete the following tasks:
1) Write a code snippet that will create 2 tuples my_tuple_1 and my_tuple_2 containing a string and a nested tuple containing numbers from the sequence. In my_tuple_1 source data comes from odd lines, in my_tuple_2 - from even lines.
The created tuples are displayed on the screen (you don't need to do this, it's done automatically).

2) Write a program fragment that displays the first element of the first tuple if the first tuple is greater than the second, otherwise the second element of the second tuple.

 

Examples
# Input Output
1 Hello
Hello
1 2 3 4
1 2 
('Hello', (1, 2, 3, 4))
('Hello', (1, 2))
Hello