Iā€™m looking for a more efficient code in the last part of the code to print ā€˜trueā€™ or ā€˜falseā€™ (last if.... )Any suggest? Thx | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
0

Iā€™m looking for a more efficient code in the last part of the code to print ā€˜trueā€™ or ā€˜falseā€™ (last if.... )Any suggest? Thx

https://sololearn.com/coach/86/?ref=app

24th Mar 2020, 12:58 PM
marco
7 Respostas
+ 1
thanks John, it works but code coach expect ā€˜falseā€™, print(y==1) returns ā€˜Falseā€™ ( or ā€˜Trueā€™)
25th Mar 2020, 1:25 PM
marco
0
can't open your link.
24th Mar 2020, 1:03 PM
John Robotane
John Robotane - avatar
0
nb=int(input()) li=[int(input()) for i in range (nb)] s=0 for k in range(1,nb): s=li[k-1]+s if li[k]>s: y=1 else: y=0 break #print (li) if y==1: print('true') else: print('false')
24th Mar 2020, 2:55 PM
marco
0
the if statement can be remplaced with print(y==1).
24th Mar 2020, 6:44 PM
John Robotane
John Robotane - avatar
0
you might also use print("true" if y==1 else "false").
25th Mar 2020, 5:12 PM
John Robotane
John Robotane - avatar
0
I like it! thank you John šŸ™
25th Mar 2020, 8:31 PM
marco
0
you're welcome marco !
26th Mar 2020, 12:40 AM
John Robotane
John Robotane - avatar