Don't like ads? PRO users don't see any ads ;-)
Guest

6-5

By: Mars83 on Oct 9th, 2011  |  syntax: Python  |  size: 0.60 KB  |  hits: 55  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #! /usr/bin/env python3.2
  2. # -*- coding: utf-8 -*-
  3.  
  4. # main.py
  5. """ Task: Exercise 6.5
  6.    Take the following Python code that stores a string:
  7.    str = 'X-DSPAM-Confidence: 0.8475'
  8.    Use find and string slicing to extract the portion of the string after the
  9.    colon character and then use the float function to convert the extracted
  10.    string into a floating point number.
  11. """
  12.  
  13. ''' Main '''
  14. string = 'X-DSPAM-Confidence: 0.8475'
  15. strPos = string.find(':')
  16. fpNumber = string[strPos+1:]
  17. fpNumber = fpNumber.strip()
  18. fpNumber = float(fpNumber)
  19. print(str(fpNumber) + " - " + str(type(fpNumber)))
  20.