I am currently working through this book: Introduction to Computation and Programming Using Python.
The question I am currently working on is:
Let s be a string that contains a sequence of decimal numbers separated by commas, e.g.,
s = '1.23,2.4,3.123'. Write a program that prints the sum of the numbers ins.
I have figured out how to this for integers:
s = raw_input('Enter any positive integers: ')
total = 0
for c in s:
c = int(c)
total += c
print total
I tried several methods including try and except method, but I can figure out how to solve the
Valuerror:invalid literal for int() with base 10: '.'
I appreciate any help. Thank you.
Update: I want to thank every one for their help. It is good to know that there are people who are willing to help the small joe.
inttofloat?int())