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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T21:09:10+00:00 2026-06-18T21:09:10+00:00

I am trying to write a program that reads from a list a series

  • 0

I am trying to write a program that reads from a list a series of names and numbers like this:

5
Jim
79 84 82
Bob
32 12 47
Kelly
90 86 93
Courtney
80 99 89
Chad
89 78 91

The format for the numbers is:

<Assignment score>   <Quiz Score>   <Exam Score>

And the multipliers for each are:

.3 .1 .6

Currently I have this:

def main():
    inFile = open("input.txt","r")

    numVals = int(inFile.readline())
    for i in range(numVals):
        name = inFile.readline()


    numbers = inFile.readline().split()
    for n in range(len(numbers)):
        numbers[n] = float(int(numbers[n]))

    avg = float(numbers[0]* .3 + numbers[1]* .1 + numbers[2]* .6)
    print(name, "'s Score is",avg,"%.")

    inFile.close()

main()

My output should look like this:

Jim’s score is <avg>.
Bob’s score is <avg>.
Kelly’s score is <avg>.
Courtney’s score is <avg>.
Chad’s score is <avg>.

But instead, I get this:

Kelly
 's Score is <avg> %.

Any ideas on how to get the print to get every name in the file and every line of numbers in the file? Thanks in advance!

  • 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-18T21:09:11+00:00Added an answer on June 18, 2026 at 9:09 pm

    You need to strip the trailing newlines from the result of readline.

    Maybe like this:

    weights = [.3, .1, .6]
    with open ('file2.txt') as f:
        count = int (f.readline ().strip () )
        for i in range (count):
            name = f.readline ().strip ()
            score = sum (w * s for w,s in zip (weights, (int (x) for x in f.readline ().strip ().split () ) ) )
            print ('{}\'s Score is {} %.'.format (name, score) )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to write a program that reads 2 numbers from the user and
I'm trying to write a program that reads 2 numbers from the user and
I'm trying to make a program that: reads a list of Chinese characters from
I am trying to write a program that reads information from a text file
I'm trying to write a java program that reads data from an image and
I am trying to write a program that reads from the console a positive
I am trying to write a simple program that reads integers from a data
I am trying to write a program for class that reads a list of
I'm trying to write a little C# program that reads from a text file
I'm trying to write a program that reads text from external file (string string

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.