[docs] Question

Angela Grima amgrima58 at gmail.com
Mon Mar 9 19:37:20 CET 2015


I have reviewed my earlier program and made some edits.  It includes edits
to the data (adding a nonsensical inequality sign preceded by a space), and
using the find statement in the revised program.

The program reads two decimal numerals, decides whether the number read is
less than or equal to a certain amount, prints the number and a letter
grade.  I made the number print two digits after the decimal.

By including a  couple of tricks, the situation which requires reading a
decimal numeral, even if Python requires X-Professional computer and XP
system, you can still make it do what you want.  See attached.

On Thu, Mar 5, 2015 at 10:39 AM, Angela Grima <amgrima58 at gmail.com> wrote:

> I have not received a response from you.  However, I think I know what the
> problem is.  My laptop is XP (important in terms of programming in
> mathematics and science for obvious reasons).  However, my operating system
> is Professional only - no XP.  It doesn't seem to make a difference in most
> situations, but it is unable to read the decimal point in as a string
> variable in Python.  It reads it as a literal and therefore it is unable to
> change to a floating number.  In other words, Python does not have the
> ability to change the "." into an equivalent decimal point in the system
> that I have.  But please note, that the underlying assumption here is that
> Python is able to do so in an XP system.
>
> Angela Grima
>
> On Tue, Feb 24, 2015 at 4:24 PM, Angela Grima <amgrima58 at gmail.com> wrote:
>
>> 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/20150309/06da22e5/attachment-0001.html>
-------------- next part --------------
Y 0.45
Y 0.56
Y 0.69
Y 0.75
Y 0.85
Y 0.95
Y 0.15
Y 0.10
Y 0.25
Y 0.35
-------------- next part --------------

import re
hand = open('datang.txt')

print 'Score Grade'
for line in hand:


  atpos = line.find('.')
#  print  atpos
  spos = line.find(' ',atpos)
#  print spos
  guest = line[atpos+1:spos]
#  print guest
  x = float(guest)
  



  x = x*.01 +.05
#  print x
  
  y =  '.'+guest[0:4]
#  print y

  if x > 1:
    print y,'Error number is greater than 1'
  elif x>=.9:
    print  y,'   A'
  elif x>=.8:
     print  y,'   B'
  elif x>=.7:
     print  y,'   C'
  elif x>=.6:
     print  y,'   D'
  elif x>=0.0:
  	 print  y,'   F'
  else: 
    print y,'Error number is less than 0'
 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Output from Revised Program.docx
Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document
Size: 13586 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/docs/attachments/20150309/06da22e5/attachment-0001.docx>


More information about the docs mailing list