Single code should run both on python version 3 and version 2.7 | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Single code should run both on python version 3 and version 2.7

How to take list of list (matrix) as input from the user such that the same code should run on both python version 3 and version 2.7 Also the type of the 2D list must be of same type(i.e. int)

4th Dec 2018, 6:24 PM
Initiator
1 Answer
+ 1
You can use an "if" statement to run different code according to Python version: from sys import version_info if(version_info >= 3.0.0) your_list = input() else your_list = raw_input() You can also create different functions for different Python versions and call either one from a similar "if" statement.
5th Dec 2018, 1:13 AM
Emerson Prado
Emerson Prado - avatar