
6-5
By:
Mars83 on
Oct 9th, 2011 | syntax:
Python | size: 0.60 KB | hits: 55 | expires: Never
#! /usr/bin/env python3.2
# -*- coding: utf-8 -*-
# main.py
""" Task: Exercise 6.5
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.
"""
''' Main '''
string = 'X-DSPAM-Confidence: 0.8475'
strPos = string.find(':')
fpNumber = string[strPos+1:]
fpNumber = fpNumber.strip()
fpNumber = float(fpNumber)
print(str(fpNumber) + " - " + str(type(fpNumber)))