Which of the following codes are better ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
- 2

Which of the following codes are better ?

https://code.sololearn.com/cQr4nC6pSz6y/?ref=app

24th Aug 2021, 12:32 PM
Sacar
Sacar - avatar
5 Answers
+ 2
Hi Sacar! I would like to choose code #1. In your second code, it breaks the loop when q entered and the rest will be ignored. So, it gives you 0 output if your first input is q so and on. For example, Input: 1 4 q 7 8 Output1: 20 Output2: 5
24th Aug 2021, 1:10 PM
Python Learner
Python Learner - avatar
+ 1
I favor the second one because it gives the user the chance to quit… But do notice that there is a syntax error in ‘if’ statement~ if x == ‘q’
24th Aug 2021, 12:51 PM
Wenkai Qu
Wenkai Qu - avatar
+ 1
Sacar Very welcome~
24th Aug 2021, 1:01 PM
Wenkai Qu
Wenkai Qu - avatar
+ 1
JUMP_LINK__&&__Python__&&__JUMP_LINK Learner If user forget to enter q in the 2nd code, the code crashes so i think 1st one is better but people say nested try except is not a good choice( i don't know why they said that )
24th Aug 2021, 1:24 PM
Sacar
Sacar - avatar
0
QWKKK oops thank you:)
24th Aug 2021, 12:59 PM
Sacar
Sacar - avatar