Courses
Log inStart Learning AI
Courses
Log inStart Learning AI
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
Sarang
2 Votes
Buggy app today
1 Votes
??
1 Votes
What kind of questions do companies ask in Data Analyst interviews (including Python, SQL, Power BI, and Excel)?
1 Votes
How many program that you've made even a smaal project are good?
0 Votes
Programming
0 Votes
Help me
1 Votes
Give some simple practice questions in C
0 Votes
how do they use javascript
0 Votes
Code coach isn't awarding xp
0 Votes