Calculating average from Python Script
Hello, I'm trying to write a python script that will calculate my test scores from a text file named "exams."
Sample input would be: Calculus 85 90 Physics 90 85 93 Output will look like: Calculus 87.5 Physics 89.3 I have the following code: Code:
#!/usr/bin/python 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:
Code:
>>> int('230498') |
print int(L[0])
The int operator gives you the conversion you need. |
Quote:
|
Quote:
Thanks again! |
Maybe try something like this:
Code:
average = 0 |
All times are GMT -5. The time now is 05:57 PM. |