Computer Science, asked by ajarchit2409, 8 months ago

Write the output of the given python code :
#!/user/bin/python
tuple1, tuple2 = (123, ‘xyz’, ‘zara’, ‘abc’), (456, 700, 200)
print "min value element : ", min (tuple1)
print "min value element : ", min (tuple2)

Answers

Answered by NirmalPandya
2

TypeError: '<' not supported between instances of 'str' and 'int'

the output of the given python code:

#!/user/bin/python

tuple1, tuple2 = (123, 'xyz', 'zara', 'abc'), (456, 700, 200)

print ("min value element : ", min (tuple1))

print ("min value element : ", min (tuple2))

  • Python being interpreted language executes one line at a time. So it will halt throwing up above mentioned error and will not proceed to futher line.
  • In case we comment out first print statement our code will work smooth and print  'min value element: 200'
  • the reason python throws error at us is because of the fact that min and max operator can be applied on list of homogenous data type i.e. type of element must go on constant thorough out the list.

Answered by letmeanswer12
0

The output is:

min value element :  123

min value element :  200

Explanation:

Python tuple min() is a built-in method that returns minimum value for the elements from the tuple.

In the code snippet:

  • tuple1 = (123, ‘xyz’, ‘zara’, ‘abc’)  
  • tuple2 = (456, 700, 200)
  • print "min value element : ", min (tuple1)

The above statement when executed will get the minimum value element from tuple1 i.e. 123

  • print "min value element : ", min (tuple2)

The above statement when executed will get the minimum value element from tuple2 i.e. 200

The output is:

  • min value element :  123
  • min value element :  200

Similar questions