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 8932061
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:15:23+00:00 2026-06-15T09:15:23+00:00

I am trying to learn basic python and I can’t seem to be able

  • 0

I am trying to learn basic python and I can’t seem to be able to return values using a while loop. I am copying the syntax from guides I am reading but it doesn’t seem to work when I run it. I may have a different version, I am not sure.

Anyways I was just messing around and got this code

def fact(x):
 count = 1
 sum = 0
 while count <= x:
     sum =  count * sum
     count + 1
 else:
     return sum   

I don’t even know if this correctly computes factorial, I don’t care, I am just trying to get it to return a value. What is wrong? Why can’t I use return? I am not sure what is wrong, when I replace return with

       display,

it still doesn’t work.

  • 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-06-15T09:15:24+00:00Added an answer on June 15, 2026 at 9:15 am
    def fact(x):
        count = 1
        sumi = 1
        while count <= x:
            sumi =  count * sumi
            count = count + 1
    
        return sumi
    

    Some mistakes here :

    • sumi = 0 at the beginning is wrong, it will make your function always returns 0
    • count + 1 does not change the value of count if you don’t assign it to anything
    • put your return statement after the while. When the loop is done it will return the value of sumi
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to learn Sencha Touch 2 and I can't seem to find out how
While trying to learn c++, I tried to implement class representing very basic trie.
I am trying to learn the basic of 3d for Mac using Xcode, so
I'm trying to learn how to do XPath queries from Python using this sample
I am trying to learn basic javascript and using jsfiddle as my tool of
I am trying to learn how to build a basic Flask application with Python.
I'm trying to learn some basic ajax using Django. My simple project is an
I am trying to learn basic cursors using PostgreSQL. This is my script: DECLARE
I'm trying to learn C++ using Qt for some basic visual applications. I want
I'm trying to learn this basic thing about processors that should be taught in

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.