-1

python program ask the user to input n number and tell him the biggest among these numbers when the user type 0 the program should stop and 0 shouldn't be compared to the other numbers (if he input 0 in number 1 it should input the first number till he inputs a correct number )

number = -1
i = 1

while not (number == 0):
    number = float(input(f"Number {i} : "))
    while number == 0 and i == 1:
        number = float(input(f"Number {i} : "))

    if i == 1 or number > max:
        max = number
        position = i

    i += 1

if i == 1:
    print("thank u ...")
else:
    print(f"the greatest number is {max}, his postion is {position}.")
Swetsen
  • 50
  • 8

1 Answers1

0

you can solve your probleme like below. In your example your first while loop should be executed just until it's getting the right number for 'n'.

n = 0
while n <=0:
    n = float(input(f"Number of el : "))
position = 1
max = None
i = 1
while i <= n:
    number = float(input(f"Number {i}: "))
    if max is None or number > max:
        max = number
        position = i
    i+=1
print(f"the greatest number is {max}, his postion is {position}.")
pycooker
  • 1
  • 1
  • But there is no input for the number of elements... Did you read the question? The user inputs numbers until the input 0 stops the process. In that case, why even use the second loop as a `while`? Why not just `for i in range(n)`? – Tomerikoo Dec 02 '21 at 11:23