-4

Trying to sum two items instead of combining them such as 500 for rent, 50 utilities returns 50050 instead of the desired 550.

from sys import argv

def bills(rent, utilities):
     raw_input("How much is your rent?") % (rent)
     raw_input("How much are utilities?") % (utilities)

rent = raw_input("How much is your rent? ")
utilities = raw_input("How much are utilities? ")

total = rent + utilities

print total
Sean
  • 165
  • 1
  • 1
  • 6
  • 1
    `int()` and `float()` are basically the first built ins in the docs. Surely it took you more effort to come on here and ask this than spend five seconds reading. – Gareth Latty Jun 24 '13 at 23:20
  • 2
    Google the first part of your question title. – Blender Jun 24 '13 at 23:21
  • possible duplicate of [Parse String to Float or Int](http://stackoverflow.com/questions/379906/parse-string-to-float-or-int) – Gareth Latty Jun 24 '13 at 23:22
  • Also, I'm not sure what the `bills()` function is meant to do, but it doesn't make sense. – Gareth Latty Jun 24 '13 at 23:23
  • thanks, tried the following: total = int(rent + utilities) , which didn't work (working version below) - adding in case other newbies have a related issue – Sean Jun 24 '13 at 23:25
  • Float or int wasn't my issue (either would be fine), it was getting rid of the combining result – Sean Jun 24 '13 at 23:28
  • It's not a great idea to represent amounts of money with floats – John La Rooy Jun 24 '13 at 23:32

2 Answers2

1

Use int(variable) if you want an integer from a string

total = int(rent) + int(utilities)
Cob013
  • 1,057
  • 9
  • 22
0
total = rent + utilities

rent and utilities are both strings, which is why they're being concatenated.

To convert them to integers:

total = int(rent) + int(utilities)
user123
  • 8,970
  • 2
  • 31
  • 52