-
Notifications
You must be signed in to change notification settings - Fork 0
/
Storing three numbersNew.py
60 lines (54 loc) · 3.05 KB
/
Storing three numbersNew.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
def main(): # Main procedure starts here
print('Please enter 3 different numbers below... ')
First = int(input('First number: '))
Second = int(input('Second number: ')) # User sets variables here
Third = int(input('Third number: '))
Mean = (First+Second+Third)/3 # Uses user input to calculate mean
# before the main series of statements
# begins.
############################################################
if (First==Second)or(First==Third)or(Second==Third):
print('Please enter 3 different numbers: ')
else:
if (First>Second) and (First>Third): # Compound statement
Largest=First # checks for largest,
if (Second>Third): # middle, and smallest.
Middle= Second
Smallest= Third
else: # If the conditions are
Middle= Third # not the above, run this:
Smallest= Second
elif (Second>First) and (Second>Third):
Largest=Second
if (First>Third): # Checks third number against
Middle=First # first number.
Smallest=Third
else: # Second else checks for
Middle= Third # conformations that certain
Smallest= First # variables are not third and
elif (Third>Second) and (Third>First): # first.
Largest=Third
if (First>Second): # Second if compound statement is checked
Middle = First # again, instead however is checked under
Smallest= Second # a single if statement in this instance.
else:
Middle= Second
Smallest= First
else:
print('Error')
###########################################################
print ('Mean average is: ' + str(Mean))
print ('Ascending order... ' + str(Smallest) + ', ' + str(Middle) + ', ' + str(Largest)) # These lines print the new smallest
print ('Descending order... ' + str(Largest) + ', ' + str(Middle) + ', ' + str(Smallest))# middle and largest variables that
# have just been set.
playAgain = input ("Do you want to sort more numbers? Y/N ").lower() # Makes input lwrcase
if playAgain not in {"y","n"}: # If input is not y or n, then print error.
print("Please enter a valid option: ")
elif playAgain == "y": # Else if the input is "y", set invalid_input to true and run main()
invalid_input = True
main()
elif playAgain == "n": # Else if the input is "n", set invalid_input to true and run main()
invalid_input = False
print ("Exiting program...")
exit()
main()