Created
November 17, 2020 05:29
-
-
Save imohammedmq/6928cadfb8550e3dc7815742397a9992 to your computer and use it in GitHub Desktop.
These two code works for assignment 5.2 python for everybody
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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