Computer Science, asked by ansty, 1 month ago

Write a program to input a number. Usingwhile loopperform the followingin one single program.
a.Find the number of digits in input
b.Display all the digits in new line
c.Check whether there are even no.of digits or odd no.of digits in input
d.Find the sum of digitsSample
Input : 372
Sample Output : 3
digitsDigits in input are: 372
The given input has odd no.of digits.Sum of digits = 12

Answers

Answered by jai696
3

\huge\red{\mid{\fbox{\tt{Using\: Python\: 3}}\mid}}

digits = list(map(int, str((n := int(input("n: "))))))

digits_len = len(digits)

print("No of digits:", digits_len, "\n")

print("Digits:\n" + "\n".join(list(map(str, digits))), "\n")

print("Even digits\n") if digits_len % 2 == 0 else print("Odd digits\n")

print("Sum:", sum(digits))

\large\mathsf\color{lightgreen}useful?\: \color{white}\longrightarrow\: \color{orange}brainliest!

Answered by Japji21
0

Answer:

digits = list(map(int, str((n := int(input("n: "))))))

digits_len = len(digits)

print("No of digits:", digits_len, "\n")

print("Digits:\n" + "\n".join(list(map(str, digits))), "\n")

print("Even digits\n") if digits_len % 2 == 0 else print("Odd digits\n")

print("Sum:", sum(digits))

\large\mathsf\color{lightgreen}useful?\: \color{white}\longrightarrow\: \color{orange}brainliest!

Similar questions