Answer to Question #305990 in Python for Kent

Question #305990

Write a program that accepts a list of numbers separated by space. Use any() function


Sample output 1:

Enter numbers separated by space: 0 0 0 0 0 0

All input are zero


Sample output 2:

Enter numbers separated by space: 0 0 0 0 0 0 1

Not all inputs are zero


1
Expert's answer
2022-03-04T04:04:51-0500
def zero(arr):
    nozero = 0
    for i in range(len(arr)):
        if arr[i] != 0:
            nozero = 1
    if nozero == 1:
        mess = 'Not all inputs are zero'
    else:
        mess = 'All input are zero'   
    return mess

print('Enter list of numbers separated by space: ', end='')
A = input().split(' ')
for i in range(len(A)):
    A[i] = int(A[i])
print(zero(A))

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS