• Courses
  • Code Compiler
  • Discuss
  • Pricing
  • 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 Answers
+ 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

Often have questions like this?

Learn more efficiently, for free:

  • Introduction to Python

    7.1M learners

  • Introduction to Java

    4.7M learners

  • Introduction to C

    1.5M learners

  • Introduction to HTML

    7.5M learners

See all courses
Hot today
How to start learning Python programming?
2 Votes
Where is the bug?
3 Votes
Is it good for student to study C++ first?
1 Votes
im beginner
2 Votes
Is code generated by chat GPT plagiarism?
1 Votes
How to fix this i feel something off
1 Votes
Pointers cpp
2 Votes
How to add two strings together in ts or css
1 Votes
finding my compiler path
1 Votes
What is Big data ?
1 Votes