0

Which path should I choose

Option 1: numbers = [] numbers.append(int(input('Enter First Number: '))) numbers.append(int(input('Enter Second Number: '))) total = numbers[0] + numbers[1] print('Your Total: %d' % total) Option 2: number_one = int(input('Enter First Number: ')) number_two = int(input('Enter Second Number: ')) total = number_one + number_two print('Your Total: ' + str(total)) -------------------------------------------------------- I'm just starting out programming so I'm still asking alot of dumb questions I apologize. I've been doing a little bit from SoloLearn Python but I'm also reading some book called 'Python Crash Course'. As I've stated I'm just starting out about 2 weeks into coding now and it's starting to get really fun even though I can hardly do anything ;D But back to the question, should I start expirimenting with list as I continue learning or make it simple like option 2? I'm in chapter 3 of this book and it says i'll be using list in alot of the things I program with python in the future so I'm wondering is it better than option 2?

20th Nov 2018, 6:37 PM
Brandon
Brandon - avatar
2 Respuestas
+ 6
This is a really simple case, but it already shows how fundamental planning beforehand is to coding. The second solution seems obvious and trivial for completing the task. It gets the job done and prints out the result. The first one does just the same. But what the second solution lacks is the potential scalability. Let's say you'll want to develop this tiny code in the future. You'll want to add (indefinitely) more than two variables, implement new operators, catch input errors to all user inputs and so on. With list you are keeping them in relation to each other and make iterative processes scalable by using loops and code reuse. Without lists and by using only separate variables to each input you are not going very far with scaling up :)
20th Nov 2018, 10:15 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
0
Kuba Siekierzyński Hey man thanks for that bit of detailed information. I’ll keep that in mind while writing code.
20th Nov 2018, 10:25 PM
Brandon
Brandon - avatar