ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
f = open('exams',"r")
l = f.readline()
while l :
l = l.split(None,10)
L = l[1:]
print 'Scores ', L
print 'Number of Values ', len(L)
l = f.readline()
My intent is to sum the values found in L and divide by len(L).
I think my issue is that when I split the values, I get a string array (ex. ['85', '90'] ), which makes it hard to do calculations.
You can convert strings to integers in Python by passing the value to the int() function, like so:
Thanks for the advice indienick. However, it's still not working. My code takes each line of text and parses it into a array so that it looks like this: ['Calculus', '85', '90']. Using L = l[1:], gives me ['85', '90'], which is close. If I used your method (L = int(l[1:])), I get an error.
The int operator gives you the conversion you need.
Mara, thank you very much for your help. Your method does work for individual iterations, but how can I make it so that it goes through my entire exam list? For example, I may have two test scores for one subject and four in another.