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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T05:11:13+00:00 2026-05-20T05:11:13+00:00

I would appreciate help on this code. I’m trying to get a function to

  • 0

I would appreciate help on this code. I’m trying to get a function to print results. The program takes random numbers and determines whether they are even or odd. That works. It is supposed to then give a tally of how many numbers are odd and how many are even.

I’m trying to build that into the “tally_status_count” function but can’t get it to work. I originally set up the ‘even_total’ and ‘odd_total’ variables as global variables, but then tried moving them into the function.

I’m lost. Any help would be appreciated.

Regards

Code:

import random

even_total = 0
odd_total = 0

def main():

    print 'Number\tStatus'
    print'______________'

    for count in range (10):
        number = random.randint(1, 10)
        status = odd_even(number)

        print number, '\t', status

    tally_status_count(odd_even)           

#Function to determine odd or even status
def odd_even(number):
    if (number % 2) == 0:
        status = 'Even'
    else:
        status = 'Odd'
    return status

#Function to tally odd and even counts
def tally_status_count(odd_even):

    even_total = 0
    odd_total = 0

    for status in range (status):
        if status == 'Even':
            even_total = even_total + 1
        else:          
            odd_total = odd_total + 1


    print
    print 'The total count of even numbers is: ', even_total
    print 'The total count of odd numbers is:  ', odd_total

main()
  • 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-20T05:11:14+00:00Added an answer on May 20, 2026 at 5:11 am

    I see several problems with your code.

    Problem 1: tally_status_count takes an argument which is never used. There’s nothing wrong with this, but it’s odd and it means you’re probably not sure how to do what you’re trying to do.

    Problem 2: tally_status_count uses a variable which doesn’t exist, ‘status.’ I am guessing that you probably intended status to be passed as an argument to the function. In that case, the function definition should look like this:

    def tally_status_count(status):
    

    When you fix problem 2, you end up with problem 3, which is…

    Problem 3: malformed for-loop. This:

    for status in range (status):
    

    Is nonsense and won’t work. range() is a function that takes some integers and returns a list of integers. If ‘status’ is a string, you can’t use it with range().

    Problem 4: You only get the status for the last random number, not for all of them. Every time you run this line:

    status = odd_even(number)
    

    the old value for status is thrown away.

    This is probably the code you meant to write:

    import random
    
    even_total = 0
    odd_total = 0
    
    def main():
    
        print 'Number\tStatus'
        print'______________'
        statuses = [] #the status for each random number is added to this list
    
        for count in range (10):
            number = random.randint(1, 10)
            current_status = odd_even(number)
    
            print number, '\t', current_status
    
            statuses += [current_status] #add to the list
    
        tally_status_count(statuses) #go through the list and total everything up
    
    #Function to determine odd or even status
    def odd_even(number):
        if (number % 2) == 0:
            status = 'Even'
        else:
            status = 'Odd'
        return status
    
    #Function to tally odd and even counts
    def tally_status_count(statuses):
    
        even_total = 0
        odd_total = 0
    
        for status in statuses:
            if status == 'Even':
                even_total = even_total + 1
            else:          
                odd_total = odd_total + 1
    
    
        print
        print 'The total count of even numbers is: ', even_total
        print 'The total count of odd numbers is:  ', odd_total
    
    main()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just cannot get this to work, would appreciate if someone can help. So
I am new android and I would appreciate some help. I have this code:
I would appreciate any help on this issue. Lets say I want to load
I'm relatively new to Java and would appreciate any help on this! I have
I am new to writing SQL and would greatly appreciate help on this problem.
I have a problem finding references to this subject and would appreciate some help.
I would greatly appreciate if you could help me with this in Java. Given
Any help with this problem would be fantastic. I appreciate all contributions! Let us
I am trying to get this code to work for me,but It is not
I get the error undefined is not a function when running this code locally

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.