Java não conheço.
O curso a seguir que estou a pensar tirar, que também é de python, é este:
https://www.coursera.org/course/interactivepythonhttps://www.coursera.org/course/interactivepython2já completei a 7.ª semana e resolvi a questão, mas com um pouco de batota.
Take the following Python code that stores a string:‘
str = 'X-DSPAM-Confidence: 0.8475'
Use find and string slicing to extract the portion of the string after the colon character and then use the float function to convert the extracted string into a floating point number.
eu resolvi da seguinte forma:
count = 0
total = 0
try:
fhand = open (fname)
except:
print 'File cannot be opened:', fname
exit()
for line in fhand:
if line.startswith ('X-DSPAM-Confidence:'):
line = line.rstrip ()
new_line = line [19:]
numero = float (new_line)
count = count + 1
total = total + numero
print 'Average spam confidence: ', total/count
Como sei que o string dos números iniciou-se no index 19, fiz essa batota, mas para usar o "find" será que deveria ser assim?
iline = line.find (':')
fline = line.find (' ',iline)
numero = data [iline+1:fline]