I\'m in the process of learning Python programming, but I\'m still very new to i
ID: 3795456 • Letter: I
Question
I'm in the process of learning Python programming, but I'm still very new to it can be challening. The following is a step-by-step practice exercise, which I'm having some difficulty with and can't seem to envision in Python code. It would be very helpful if someone could write this scenario into Python code, with explaination if possible, so I can get a better idea.
Take the following Python code that stores a string: str = 'X-DSPAM-Confidence: 0.8475'
The program should have the follow functionalities:
1. Stores a string: string = 'X-DSPAM-Confidence: 0.8475'
2. Use string slice to get the letter part ('X-DSPAM-Confidence) and the numeric part (0.8475), and store them in two different string variables.
3. Use the float function to convert the numeric part intoa floating point number
4. Ask the user to input a numeric value
5. If the user input non-numeric value, keep on prompting the user to input numeric value
6. Add the user input numeric value with the value converted from numeric part, this is the new numeric part.
7. Change the letter part to lower case
8. Replace the “- “ in letter part with empty space, this is now the new letter part.
9. Concatenate the new letter part and the new numeric part together with an empty space between and print them out.
Explanation / Answer
string = 'X-DSPAM-Confidence: 0.8475'
print string
stringSplit = string.split(':')
word = stringSplit[0]
decimal = float(stringSplit[1].strip())
print decimal
print word
while True:
n = input()
print n
if n.isdigit():
total = float(n) + decimal
word.lower()
word.replace("-", " ")
print word + " " + total
break
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.