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"
Trending nowThis is a popular solution!
Step by stepSolved in 3 steps with 2 images
- Write a function named encode_string(sentence) that takes a string value as its input and returns an encoded string, where each character of the input string is replaced by its ASCII code plus 3 values. Whitespace characters should not be encoded. For example, if the function was passed the input string: Hello World then it should return: Khoor Zruog For example: Test sentence "Hello World" print (encode_string(sentence)) Result Khoor Zruogarrow_forwardWrite a function filter_codes(list_codes) that receives a list of codes and returns another list containing those codes that: Only have numeric characters; and Are at least 2 characters long; and At most 6 characters long Hint: remember that Python has a built-in function for determining if a string only contains numeric characters. solve using pythonarrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education