[docs] Question

Angela Grima amgrima58 at gmail.com
Tue Feb 24 22:24:28 CET 2015


Hello,
\
I am a beginner at Python and I am trying to write a program that allows me
to read in a list of decimal numerals, assign a grade to each one, and
write each one with the corresponding grade. Unfortunately, it Python
thinks that each score is a string but does not allow me to convert it to a
floating point.  I have tried different statements using Python but I am
still stuck.  Attached are a copy of the program, data being used.  Below
is the printed output.


Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.
C:\Users\Ange\Documents\Computer Science\Python Class>docbright.py
Score Grade
Traceback (most recent call last):
  File "C:\Users\Ange\Documents\Computer Science\Python
Class\docbright.py", lin
e 18, in <module>
    x = float(x) + .005
ValueError: could not convert string to float:ss>

Your help is appreciated.

Angela Grima
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/docs/attachments/20150224/7d475212/attachment-0001.html>
-------------- next part --------------


file = open("datang.txt","r")
count = 0
print 'Score Grade'
if count <= 10:
 char = file.readline(4)
 
 
 

 for line in file:
  x = line.strip() 
  count = count + 1
#  print 'line count:', count,x


  x = float(x) + .005
  y = line.strip()




  if x > 1:
   print y[0:4],'Error number is greater than 1'
  elif x>=.9:
   print  y[0:4],'   A'
  elif x>=.8:
   print  y[0:4],'   B'
  elif x>=.7:
   print  y[0:4],'   C'
  elif x>=.6:
   print  y[0:4],'   D'
  elif x>=0.0:
   print  y[0:4],'   F'
  else: 
   print y[0:5],'Error number is less than 0'
 
file.close()
-------------- next part --------------
0.45
0.56
0.69
0.75
0.85
0.95
0.15
0.10
0.25
0.35


More information about the docs mailing list