attempting to add cost from the end of a line but only getting a blank space

user3346105

I'm attempting to get the cost (the values at the end of each line) total from all the logs but when price is printed it doesn't print anything just a blank space. Each line has varying length before the value. This code does not yet add the cost but I'm making sure I'm getting.

log record entered into function (rec.dat): *this log would be the record entered into the function

@ 2014 2 14 00:03:01 Matt "login" 0.01

@ 2014 2 14 02:06:12 Mary "login" 0.01

@ 2014 2 14 17:12:05 Mary "cd ~/cs150/projects" 0.01

function: the goal of the function is to add how much the cost would be for all actions (in this case cost should end up totaling .03)

def cost(rec):
    s = Scanner(rec)
    cost = 0
    line = s.readline()
    for i in range(0, len(rec), 1):
        info = len(line) - 3
        price = line[info:0]
        print("price: ",price)
        cost += price
        line = s.readline()
    s.close()
    return cost
Christian Aichinger

Make that:

price = line[-3:]

You can delete info completely. Look up how Python's slice notation works, it provides handy shortcuts for a large number of problems, including yours :-)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

Removing blank line from end of result in java

From Dev

How to add a blank space when replacing a line in a file

From Dev

remove white space from the end of line in linux

From Dev

NoClassDefFoundError when attempting to run from command line

From Dev

Where is this blank space coming from?

From Dev

Attempting to Query only data from cells that are not blank

From Dev

Eclipse formatter : add blank line at the end of the class

From Dev

StringLengthAttribute MVC Blank Space at end

From Dev

SQL fields with blank space at end of fields

From Dev

Add spaces at the end of a line

From Dev

Strip first space to end of line

From Dev

Add space to the end of the RecyclerView

From Dev

Android - When attempting to add an image creates a blank image

From Dev

NSKernAttributeName space at end of line in an NSAttributedString

From Dev

Non breaking space at the end of the line

From Dev

Add empty (blank) space under (in the end of) UITableView

From Dev

Getting read.line() to skip a blank line

From Dev

StringLengthAttribute MVC Blank Space at end

From Dev

SQL fields with blank space at end of fields

From Dev

Unwanted blank space generated at the end of page

From Dev

Strip first space to end of line

From Dev

sed remove last space only on end of line,combined with awk

From Dev

Getting blank SyntaxError on the last line

From Dev

Is it possible to add blank space to the end of a tableview

From Dev

add / at the end of each line

From Dev

how to replace every 6th ooccurrence blank space with new line from a file?

From Dev

Getting Order Cost from Order Line in MDX

From Dev

Haskell blank space after new line

From Dev

NSKernAttributeName space at end of line in an NSAttributedString

Related Related

  1. 1

    Removing blank line from end of result in java

  2. 2

    How to add a blank space when replacing a line in a file

  3. 3

    remove white space from the end of line in linux

  4. 4

    NoClassDefFoundError when attempting to run from command line

  5. 5

    Where is this blank space coming from?

  6. 6

    Attempting to Query only data from cells that are not blank

  7. 7

    Eclipse formatter : add blank line at the end of the class

  8. 8

    StringLengthAttribute MVC Blank Space at end

  9. 9

    SQL fields with blank space at end of fields

  10. 10

    Add spaces at the end of a line

  11. 11

    Strip first space to end of line

  12. 12

    Add space to the end of the RecyclerView

  13. 13

    Android - When attempting to add an image creates a blank image

  14. 14

    NSKernAttributeName space at end of line in an NSAttributedString

  15. 15

    Non breaking space at the end of the line

  16. 16

    Add empty (blank) space under (in the end of) UITableView

  17. 17

    Getting read.line() to skip a blank line

  18. 18

    StringLengthAttribute MVC Blank Space at end

  19. 19

    SQL fields with blank space at end of fields

  20. 20

    Unwanted blank space generated at the end of page

  21. 21

    Strip first space to end of line

  22. 22

    sed remove last space only on end of line,combined with awk

  23. 23

    Getting blank SyntaxError on the last line

  24. 24

    Is it possible to add blank space to the end of a tableview

  25. 25

    add / at the end of each line

  26. 26

    how to replace every 6th ooccurrence blank space with new line from a file?

  27. 27

    Getting Order Cost from Order Line in MDX

  28. 28

    Haskell blank space after new line

  29. 29

    NSKernAttributeName space at end of line in an NSAttributedString

HotTag

Archive