+ 1
What is the output of this code? Please explain your answer too because I didn't understood this question.
tuple_sets=((0,1),(2,3),(4,5)) x = tuple_sets[1][0] y = tuple_sets[2][1] z = y % x print(z)
3 ответов
+ 3
tuple_sets=((0,1),(2,3),(4,5))
x = tuple_sets[1][0] # picking 2, element index [1] = (2,3) pos index [0] = 2
y = tuple_sets[2][1] # picking 5, element index [2] = (4,5) pos index [1] = 5
z = y % x # 5%2 is 1 as % is modulo division that returns the division remainder
print(z)
# output = 1
+ 3
tuple_sets=( ( 0 , 1 ) , ( 2 , 3 ) , ( 4 , 5 ) )
| | |
tuple_sets[0] tuple_sets[1] tuple_sets[2]
| | | | | |
[0]=0 [1]=1 [0]=2 [1]=3 [0]=4 [1]=5
so,
tuple_sets[0] = (0,1)
tuple_sets[0][0]= 0
tuple_sets[0][1]=1
tuple_sets[1] = (2,3)
tuple_sets[1][0]= 2
tuple_sets[1][1]=3
tuple_sets[2] = (4,5)
tuple_sets[2][0]= 4
tuple_sets[2][1]=5
x=tuple_sets[1][0] #2
y=tuple_sets[2][1] #5
z = y % x #5%2 => 1
print(z)
#Ouput: 1
+ 1