• Cursussen
  • Code Compiler
  • Discussiëren
  • Prijzen
  • Teams
Menu
0

Optimizing and Shortening Code

How can I optimize the given code which calculates the factorial of a number. https://code.sololearn.com/c7m1MD6M4IsP/?ref=app

factorialoptimize
5th Feb 2020, 4:01 PM
Utkarsh Prajapati
Utkarsh Prajapati - avatar
2 Antwoorden
+ 5
I'd go like this. n=1 for i in range(2, int(input()+1)): n*=i print(n) Regard the +1: input of 5 should give 120 as a result, but range(5) stops after 4.
5th Feb 2020, 4:17 PM
HonFu
HonFu - avatar
+ 4
https://code.sololearn.com/c3eg8MvlATAf/?ref=app https://code.sololearn.com/cOInw4yJq7wi/?ref=app https://code.sololearn.com/cE7lXk0wwKMN/?ref=app https://code.sololearn.com/c4phTP2wUQ3u/?ref=app https://code.sololearn.com/cOfMIY803RdZ/?ref=app https://code.sololearn.com/c4Q0rFUFxZIP/?ref=app https://code.sololearn.com/cj7pAcAEmqTm/?ref=app
17th Feb 2020, 2:45 AM
Jesus Eduardo CanulK
Jesus Eduardo CanulK - avatar

Heb je vaak vragen zoals deze?

Leer efficiënter, gratis:

  • Inleiding tot Python

    7,1 miljoen leerlingen

  • Inleiding tot Java

    4,7 miljoen leerlingen

  • Inleiding tot C

    1,5 miljoen leerlingen

  • Inleiding tot HTML

    7,5 miljoen leerlingen

Bekijk alle cursussen
Populair vandaag
Python stressed me out
1 Votes
How often can you become a fully stuck developer?
1 Votes
Improve accessibility of this page
0 Votes
Course Doubt
1 Votes
If we already have the DELETE command in SQL, why do we need TRUNCATE?
2 Votes
What is a simple and easy way to learn ruby? :)
0 Votes
Lesson Takeaways
0 Votes
Data analysis
0 Votes
Saved code
0 Votes
How do i make a lexer and parser
1 Votes