def sum_string(string: str) -> int: """ Given a string , return the sum of this string, as computed by the formula given below: To compute the sum of a string as defined by this function, we add every odd positioned digit, and subtract every even positioned digit. For example, if we had an input of "54321", we would add 5, subtract 4, add 3, subtract 2, and add 1, bringing us to a total of 3. In other words, you would add the first digit, subtract the second digit, and keep alternating until you reach the end of the string. If the string is empty, then the sum is 0. Note: since we give the input as a string, you will have to do some type conversion in order to solve this problem. Precondition: will only contain the characters 0-9. """ pass   " please do this on python and don't use any import functions"

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter6: Modularity Using Functions
Section6.4: A Case Study: Rectangular To Polar Coordinate Conversion
Problem 9E: (Numerical) Write a program that tests the effectiveness of the rand() library function. Start by...
icon
Related questions
Question

def sum_string(string: str) -> int:
"""
Given a string <string>, return the sum of this string, as computed by the
formula given below:

To compute the sum of a string as defined by this function, we add every
odd positioned digit, and subtract every even positioned digit. For example,
if we had an input of "54321", we would add 5, subtract 4, add 3, subtract
2, and add 1, bringing us to a total of 3. In other words, you would add the
first digit, subtract the second digit, and keep alternating until you reach
the end of the string. If the string is empty, then the sum is 0.

Note: since we give the input as a string, you will have to do some type
conversion in order to solve this problem.

Precondition: <string> will only contain the characters 0-9.
"""
pass

 

" please do this on python and don't use any import functions"

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr