Question

Write python code that reads a string with numbers and letters and outputs sum of the...

Write python code that reads a string with numbers and letters and outputs sum of the numbers and number of letters.

Homework Answers

Answer #1
s = input("Enter input: ")
sumOfNumber = 0
numberOfLetters = 0
for x in s:
    if x>='0' and x<='9':
        sumOfNumber += int(x)
    else:
        numberOfLetters += 1
print("Sum of numbers:",sumOfNumber)
print("Number of letters:",numberOfLetters)

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Python code Write a complete program with for loop which calculates the sum of the numbers...
Python code Write a complete program with for loop which calculates the sum of the numbers from 1 to 100
Write a Python program that reads in a string and determines whether the string is a...
Write a Python program that reads in a string and determines whether the string is a palindrome or not. note that a sentence that reads the same forwards and backwards by resequencing the spaces is also a palindrome and your program should consider this. sample run enter string: mom output: mom is a polindrame enter string: a nut for a jar of tuna output: a nut for a jar of tuna is a palindrome
Write a program that reads a string and outputs the number of lowercase vowels in the...
Write a program that reads a string and outputs the number of lowercase vowels in the string. Your program must contain a function with a parameter of a char variable that returns an int. The function will return a 1 if the char being passed in is a lowercase vowel, and a 0 for any other character. The output for your main program should be: There are XXXX lowercase vowels in string yyyyyyyyyyyyyyyyyyyyyy Where XXXX is the count of lowercase...
Write a program that prompts the user to input a string and outputs the string in...
Write a program that prompts the user to input a string and outputs the string in uppercase letters. (Use dynamic arrays to store the string.) my code below: /* Your code from Chapter 8, exercise 5 is below. Rewrite the following code to using dynamic arrays. */ #include <iostream> #include <cstring> #include <cctype> using namespace std; int main() { //char str[81]; //creating memory for str array of size 80 using dynamic memory allocation char *str = new char[80]; int len;...
Write a Python program to ask user input of a string, then ask user input of...
Write a Python program to ask user input of a string, then ask user input of what letters they want to remove from the string. User can either put in "odd", "even" or a number "n" that is greater than 2. When user input "odd", it will remove the characters which have odd numbers in the sequence of the string. When user input "even", it will remove the characters which have even numbers in the sequence of the string. When...
python question lets say you had a string that was returned from a block of code...
python question lets say you had a string that was returned from a block of code that converted it from letters to numbers. for example, the user input was "hi", the code converted it into "89" as a string with a dictionary how could you take that "89" and go back into hi again? lets say the dictionary was keys and values of keys = alphabet and values = numbers the output would be back at "hi" again Convert into...
Write an algorithm that adds up a sequence of twenty numbers and outputs the sum of...
Write an algorithm that adds up a sequence of twenty numbers and outputs the sum of the numbers as well as the average of the numbers. (Your algorithm MUST use the repetition control structure to read in and process the inputs.)
Perl language and by using VS Code: Write a program that reads a number, adds up...
Perl language and by using VS Code: Write a program that reads a number, adds up the cube of all the digits, and displays the result. Run your code with the following test number: 1242 It should give 81. Please include screenshots of your outputs.
The code needs to be in C #. Write a simple program that reads from the...
The code needs to be in C #. Write a simple program that reads from the console a set of numbers and prints back onto the console the smallest number from the collection
Write a python program to find the sum of the first n natural numbers, where the...
Write a python program to find the sum of the first n natural numbers, where the value of n is provided by the user. What is the sum of the first 200 numbers? Write a program that finds the average of a series of numbers entered by the user. As in the previous problem, the program will first ask the user how many numbers there are. Note: the average should always be a float. What is the average of 10.2,...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT