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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T22:47:38+00:00 2026-06-12T22:47:38+00:00

Lloyd = { name:Lloyd, homework: [90,97,75,92], quizzes: [ 88,40,94], tests: [ 75,90] } Alice

  • 0
Lloyd = {
    "name":"Lloyd",
    "homework": [90,97,75,92],
    "quizzes": [ 88,40,94],
    "tests": [ 75,90]
    }
Alice = {
    "name":"Alice",
    "homework": [100,92,98,100],
    "quizzes": [82,83,91],
    "tests": [89,97]
    }
Tyler = {
    "name":"Tyler",
    "homework": [0,87,75,22],
    "quizzes": [0,75,78],
    "tests": [100,100]
    }

def average(value):
    avg=0
    items = len(value)
    for item in value:
        avg +=item 
    return avg/items

def getAverage(dictin):
    hw = average(dictin.get('homework'))
    quiz = average(dictin.get('quizzes'))
    tests = average(dictin.get('tests'))
    weighted_average = hw*.1 + quiz*.3 + tests*.6
    return weighted_average

def getLetterGrade(score):
    if score >=90:
        return "A"
    elif score < 90 and score >= 80:
        return "B"
    elif score < 80 and score >= 70:
        return "C"
    elif score < 70 and score >= 60:
        return "D"
    elif score < 60:
        return "F"
    else:
        return "No grades for you"

score = getAverage(Lloyd)
grade = getLetterGrade(score)
print grade

This works fine but I am told that in the case of the score being 89.5, it would not work. I tried that as well but I am not able to find out where the problem could be. Any mistakes are welcome.

  • 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-12T22:47:39+00:00Added an answer on June 12, 2026 at 10:47 pm

    The catch is probably in the average function where you divide an integer (avg) by another integer (items). Since both operands are integers, Python casts the result to an integer as well, thus the average function will never return fractional scores.

    There are many possible solutions:

    1. Cast one of the operands (either avg or items) to a float before dividing; e.g. return float(avg)/items, or return (avg+0.0)/items.

    2. Let avg start from 0.0 instead of 0 – this ensures that avg is always a float.

    3. Add from __future__ import division to the very beginning of your code. This instructs Python to use division in the Python 3.x way and always return a float.

    Update: also, according to MrGingerbear’s comment, you might consider rounding the score up or down in getLetterGrade. If you import the ceil and floor functions from the math module, you can say ceil(score) to round it up, floor(score) to round it down, or round(score) to round it to the nearest integer.

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

Sidebar

Related Questions

Hello I have following column in SSRS Report. Column Name(Title) Mehta, Natasha(18)----its Title+(count) value
Let's say I have a System.Xml.XmlDocument whose InnerXml is: <comedians><act id=1 type=single name=Harold Lloyd/><act
I have a page where I want to see if a certain value exists
Is it possible to remove items from all dropdowns, except from the one where
May I know is there a shorter way to add items to the comboBox?
I'm writing an application for windows mobile 6 and above that requires a local
I'm trying to create a web based welcome display for a building entrance. The
I've made a little game as an application for the web in silverlight using
I'm iterating through a set of json data which carries results of a few
I have a datatable being built in code which can dynamically have any given

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.