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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T00:41:53+00:00 2026-06-01T00:41:53+00:00

The user is prompted for a file, which in this case is ‘histogram.txt’. The

  • 0

The user is prompted for a file, which in this case is ‘histogram.txt’. The program takes each score in the text file and makes a histogram out of all the grades in the file, organizing them so that the user can see how many of each range there are. I wrote out a very simple code:

filename = raw_input('Enter filename of grades: ')

histogram10 = 0
histogram9 = 0
histogram8 = 0
histogram7 = 0
histogram6 = 0
histogram5 = 0
histogram4 = 0
histogram3 = 0
histogram2 = 0
histogram1 = 0
histogram0 = 0

for score in open(filename):
    if score >= 100:
        histogram10 = histogram10 + 1
    elif score >= 90: 
        histogram9 = histogram9 + 1
    elif score >= 80:
        histogram8 = histogram8 + 1
    elif score >= 70:
        histogram7 = histogram7 + 1
    elif score >= 60:
        histogram6 = histogram6 + 1
    elif score >= 50:
        histogram5 = histogram5 + 1
    elif score >= 40:
        histogram4 = histogram4 + 1
    elif score >= 30:
        histogram3 = histogram3 + 1
    elif score >= 20:
        histogram2 = histogram2 + 1
    elif score >= 10:
        histogram1 = histogram1 + 1
    elif score >= 0:
        histogram0 = histogram0 + 1

print    
print 'Grade Distribution'
print '------------------'
print '100     :',('*' * histogram10)
print '90 - 99 :',('*' * histogram9)
print '80 - 89 :',('*' * histogram8)
print '70 - 79 :',('*' * histogram7)
print '60 - 69 :',('*' * histogram6)
print '50 - 59 :',('*' * histogram5)
print '40 - 49 :',('*' * histogram4)
print '30 - 39 :',('*' * histogram3)
print '20 - 29 :',('*' * histogram2)
print '10 - 19 :',('*' * histogram1)
print '00 - 09 :',('*' * histogram0)

however whenever i run the program, all twenty grades get recorded onto the >= 100
like this:

100    : ********************
90-99  : 
80-89  : 

etc.
… How do I make it so that the program puts the stars in the correct places?

  • 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-01T00:41:55+00:00Added an answer on June 1, 2026 at 12:41 am

    You need to convert score to int before comparing.

    score = int(score)  # convert to int
    if score >= 100:
        histogram10 = histogram10 + 1
    # other cases
    

    If you have blank lines in input file then you have to add necessary check before converting to int. Also instead of ten different variables you can easily use a list.

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

Sidebar

Related Questions

I had a bash file which prompted the user for some parameters and used
I'm trying to build a simple user authorization system where a .txt file stores
I'm making a command-line word editor program. The user is prompted to input a
I'm trying make a login window where a user is prompted to enter their
There are 3 types of food orders: Fish, Chips, Drink. The user is prompted
User Story: Action for Facebook that has open graph object. For this I need
User inserts a string in a html form input on browser. This string is
User Defined Function (UDFs) are functions that one can program and can be dynamically
I have a html page which lists all the file names in a folder
I am developing a simple text based Dungeon game using Python3. First the user

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.