What would you do different? | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
+ 10

What would you do different?

I just published two python codes and I'd like to know what you would add or change. Thanks https://code.sololearn.com/cLuJywYg3bRi/?ref=app https://code.sololearn.com/ca56vFeFvSK4/?ref=app

11th Sep 2019, 5:30 AM
John
3 Antworten
+ 5
Nice going! For the first one, you could use a comprehension: n = int(input()) print(sum(i**5 + 4*i**3 + 3*i**2 + 5 for i in range(1, n+1))) ...or even a one-liner: print(sum(i**5 + 4*i**3 + 3*i**2 + 5 for i in range(1, int(input())+1))) For the second one, I wouldn't use eval() as the name of a defined function because it's already the name of a built-in function. Here's a variation on the code: https://code.sololearn.com/cOgB9UfjI1vp
11th Sep 2019, 6:06 AM
David Ashton
David Ashton - avatar
+ 6
David Ashton Awesome! 😁 Thank you for the feedback!
11th Sep 2019, 6:42 AM
John
+ 1
Cristopher J Cardozo You're welcome - keep up the good work!
12th Sep 2019, 1:43 AM
David Ashton
David Ashton - avatar