Advertisement
Mars83

6-5

Oct 9th, 2011
636
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.60 KB | None | 0 0
  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.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement