Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wondering why this while loop isn't stopping

Tags:

python

end_number = -99
num = (input("Enter Nnumber: "))
list_of_numbers = []
list_of_numbers.append(num)
while num != end_number:
    num = (input("Enter Nnumber: "))
print("The smallest number was", min(list_of_numbers))
print("The smallest number was", max(list_of_numbers))

I am trying to a have a person enter a bunch of int and stop when they ender -99. Then I'm wanting to print the smallest and largest in they entered.

like image 930
Shoople Avatar asked Oct 21 '25 14:10

Shoople


1 Answers

input() returns a string and end_number is int, either convert the result of input() to int, with

num = int(input("Enter Nnumber: "))

or convert end_number to string, with

end_number = "-99"  # Double quotes to represent -99 as a String of characters
like image 59
Antony Hatchkins Avatar answered Oct 23 '25 04:10

Antony Hatchkins



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!