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
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 a python code that will ask the user to enter an integer number n. Construct...
Write a python code that will ask the user to enter an integer number n. Construct a recursive function that prints numbers 1 to n in the form “11223344..nn”.
Use C++ Write a program that first reads in how many whole numbers the user wants...
Use C++ Write a program that first reads in how many whole numbers the user wants to sum, then reads in that many whole numbers, and finally outputs the sum of all the numbers greater than zero, the sum of all the numbers less than zero (which will be a negative number or zero), and the sum of all the numbers, whether positive, negative, or zero. The user enters the numbers just once each and the user can enter them...
Write a Python program to find the sum of the binary numbers in list L, where...
Write a Python program to find the sum of the binary numbers in list L, where the binary numbers do not have the quote marks necessary for the int() function. For example, if L = [101, 11, 1010] then the sum is 5 + 3 + 10 = 18. What is the sum when L is L = [10100, 101000, 100000, 1011111, 1000, 1010111, 1010010, 11001, 101100, 10111, 11011, 1011010, 11101, 10, 110011, 1001111, 110010, 101100, 100001, 111001]
IN PYTHON : Write a program that asks the user for a number. Write the number...
IN PYTHON : Write a program that asks the user for a number. Write the number to a file called total.txt. Then ask the user for a second number. Write the new number on line 2 with the total for both numbers next to it separated by a comma. Then ask the user for a third number and do the same. Keep asking for numbers until the person puts in a zero to terminate the program. Close the file. Be...
Hello, I am trying to create a Java program that reads a .txt file and outputs...
Hello, I am trying to create a Java program that reads a .txt file and outputs how many times the word "and" is used. I attempted modifying a code I had previously used for counting the total number of tokens, but now it is saying there is an input mismatch. Please help! My code is below: import java.util.*; import java.io.*; public class Hamlet2 { public static void main(String[] args) throws FileNotFoundException { File file = new File("hamlet.txt"); Scanner fileRead =...
Create a python script that reads in an unknown number of positive numbers and negative numbers....
Create a python script that reads in an unknown number of positive numbers and negative numbers. These numbers are to be stored in two different collections. Once the user enters a zero value, the script will output all of the values in both collections, separately. Sample Usage/Output: Please enter a positive or negative number (enter a zero to end): 5 Please enter a positive or negative number (enter a zero to end): -7 Please enter a positive or negative number...
How to code this in python Write a program that computes and prints the first 1000...
How to code this in python Write a program that computes and prints the first 1000 prime numbers - simply write out each prime number on a new line. In implementing this solution I want you to define 2 functions: is_prime which can be used to test whether a number is a prime (e.g. is_prime(17) returns True but is_prime(9) returns False) and compute_primes which will return an array (or Python list) of the first n primes where n is passed...