Question #101645

Write a program that asks the user to input a word or phrase and then outputs the following information about that phrase:


All numbers if the input is all numbers.

Does not contain numbers if the input does not contain any numbers.

Contains a {digit} for each number in the phrase.

Expert's answer

word = input('Write word or a phrase: ')

try:

word = int(word)

print(word)

except ValueError:

checker = []

for i in word:

if i.isdigit():

print('Contains a: {' + i + '}')

checker.append(i)

if len(checker) == 0:

print('Does not contain numbers')

LATEST TUTORIALS
APPROVED BY CLIENTS