Question
Please help me with this homework problem, using python 2.X Given the following python statement avg_str = 'Average value read: 0.72903' Use the find() method
Please help me with this homework problem, using python 2.X
Given the following python statement
avg_str = 'Average value read: 0.72903'
Use the find() method 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 value. Your code should provide a general solution, meaning that the number you extract could be any floating point number (it may or may not be preceded by a space, it may or may not begin with 0, it may or may not end with 3, and its length is not known before your program executes). A generalized solution will successfully extract values such as 0.72903, 3.14159265359, 2.81, etc.. In other words, your solution will not make any a priori assumptions regarding the format or content of the number, other than it being a floating point value that follows the colon character. Save your code in a file named parse_float.py.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started