-1

in this program to find smallest number i get output a blank

a = None
z = input("enter 5 numbers")

for x in z:
    if a is None:
        a = x
    elif x<a:
        a=x

print("smallest number is" , a)
DjaouadNM
  • 22,013
  • 4
  • 33
  • 55
oddgamer
  • 11
  • 6

2 Answers2

1

input returns a string, and if the numbers are separated by a space, you need to split the string by space and convert each to an int to handle numbers with more than one digit (because iterating over a string will return each digit individually), and you can use Python's built-in min function to get the smallest number:

z = map(int, input("enter 5 numbers").split())
a = min(z)

# you can really enter any number of numbers this way, not just 5
DjaouadNM
  • 22,013
  • 4
  • 33
  • 55
0

You are missing two steps, split the string, and convert to float.

Here is a corrected version of your program:

a = None
z = input("enter 5 numbers: ")

for x in z.split():
    x=float( str(x) )
    if a is None:
        a = x
    elif x<a:
        a=x

print("smallest number is" , a)
DrM
  • 2,404
  • 15
  • 29