Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6011859
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:19:13+00:00 2026-05-23T02:19:13+00:00

Here is what i wrote: number = raw_input(‘Enter an integer= ‘) if number <

  • 0

Here is what i wrote:

number = raw_input('Enter an integer= ')
if number < 0:
    print 'Invalid number'

else:
    for k in range(1,(number)):
        number *= k

print number

I want to be able to input any number (that is greater than 0), but when i input a number say 4 (the factorial of 4 is 24) i get this error:

Traceback (most recent call last):
  File "problem.py", line 6, in <module>
    for k in range(1,(number)):
TypeError: range() integer end argument expected, got str.

I don’t understand what it means and as far as i know the code should be working, Please Help!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T02:19:13+00:00Added an answer on May 23, 2026 at 2:19 am

    This works perfectly: factorial.py

    #!/usr/bin/env python
    
    # imports go here
    
    __author__ = 'Michael O. Duffy'
    __status__ = "Development"
    
    def factorial(n):
        """ Calculate a factorial of an integer """
        factorial = 1
        if n < 0:
            print 'Invalid number'
        else:
            for k in range(1,n+1):
                factorial *= k
        return factorial
    
    if __name__ == '__main__':
    
        for number in range(1, 20):
            print 'n: ', number, 'n!: ', factorial(number)
    

    You should know that this is an inefficient, academic implementation that shouldn’t be used in any serious application. You’ll be a lot better off using a gamma or lngamma implementation and a dictionary cache to save on calculations if you use values repeatedly:

    http://mathworld.wolfram.com/GammaFunction.html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

here's a function I wrote to print every digit of a float number in
Here's the code I wrote for finding the n-th Fibonacci number: unsigned long long
Here's a simple validation attribute I wrote to enforce number-only strings (I use it
I wrote method that return random number between two given numbers. Here it's header:
Here is v1.0 of the binary_to_decimal converter I wrote. I want to make several
here's the stored procedure i wrote.In this proc p_subjectid is an array of numbers
As comment to one of the questions here a commenter wrote (emphasis mine): ...
Here is a function I wrote to break a long string into lines not
Here's a Django model class I wrote. This class gets a keyerror when I
Here is a related manager I wrote: class PortfolioItemManager(models.Manager): use_for_related_fields = True def extended(self):

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.