Skip to content

Instantly share code, notes, and snippets.

@imohammedmq
Created November 17, 2020 05:29
Show Gist options
  • Save imohammedmq/6928cadfb8550e3dc7815742397a9992 to your computer and use it in GitHub Desktop.
Save imohammedmq/6928cadfb8550e3dc7815742397a9992 to your computer and use it in GitHub Desktop.
These two code works for assignment 5.2 python for everybody
# These two code works for assignment 5.2 python for everybody
# code 1
largest = None
smallest = None
while True:
num = input("Enter a number: ")
if num == "done":
break
try:
num = int(num)
except:
print("Invalid input")
continue
if smallest is None:
smallest = num
elif num < smallest:
smallest = num
if largest is None:
largest = num
elif num > largest:
largest = num
print("Maximum is", largest)
print("Minimum is", smallest)
# code 1 ends here
# code 2
largest = None
smallest = None
while True:
try:
num = input("Enter a number: ")
if num == "done":
break
# print (num)
num = int(num)
for number in range(num):
if largest is None or largest < num:
largest = num
continue
elif smallest is None or smallest > num:
smallest = num
except ValueError:
print("Invalid input")
print ("Maximum is", largest)
print ("Minimum is", smallest)
# code 2 ends here
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment