I have written a program that finds the smallest/biggest of any 10 numbers you give, and I was wondering about how I could just take any amount of numbers and then find the smallest/biggest when the user inputs, for example "done". So if anyone could help me with my problem I'd really appreciate it. I also looked through the python documents but I wasn't sure what to look for so I couldn't find anything.
Here is the code I wrote if it helps in any way
If there isn't a way to achieve this, thanks anyway
Here is the code I wrote if it helps in any way
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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
#Imports sleep from time module. from time import sleep #Gets the users name and then greets them. name = str ( input ( "Hello! What's your name? -->" )) print ( "Hey %s! Welcome to this program that finds the biggest or smallest of any 10 numbers you give!" % name) #All 10 number inputs. n1 = int ( input ( "Input the first number ->" )) sleep( 0.1 ) n2 = int ( input ( "Input the second number ->" )) sleep( 0.1 ) n3 = int ( input ( "Input the third number ->" )) sleep( 0.1 ) n4 = int ( input ( "Input the fourth number ->" )) sleep( 0.1 ) n5 = int ( input ( "Input the fifth number ->" )) sleep( 0.1 ) n6 = int ( input ( "Input the sixth number ->" )) sleep( 0.1 ) n7 = int ( input ( "Input the seventh number ->" )) sleep( 0.1 ) n8 = int ( input ( "Input the eighth number ->" )) sleep( 0.1 ) n9 = int ( input ( "Input the ninth number ->" )) sleep( 0.1 ) n10 = int ( input ( "Input the tenth number ->" )) sleep( 0.3 ) print ( "Okay, now that all the numbers are entered." ) chose = 0 outCome = 0 #Makes sure the smallest/biggest variable is correct and if not asks the user again. while chose = = 0 : choice = str ( input ( "Do you want to find the smallest(s) or biggest(b)? ->" )) sleep( 0.6 ) if choice = = "s" : print ( "You you chose smallest!" ) chose = 1 break elif choice = = "b" : print ( "You chose biggest!" ) chose = 1 break else : print ( "Your choice was invalid, check your spelling!" ) #The "smallest" decision. if choice = = "s" : if n1 < n2: outCome = n1 else : outCome = n2 if n3 < outCome: outCome = n3 if n4 < outCome: outCome = n4 if n5 < outCome: outCome = n5 if n6 < outCome: outCome = n6 if n7 < outCome: outCome = n7 if n8 < outCome: outCome = n8 if n9 < outCome: outCome = n9 if n10 < outCome: outCome = n10 #The "Biggest" decision. if choice = = "b" : if n1 > n2: outCome = n1 else : outCome = n2 if n3 > outCome: outCome = n3 if n4 > outCome: outCome = n4 if n5 > outCome: outCome = n5 if n6 > outCome: outCome = n6 if n7 > outCome: outCome = n7 if n8 > outCome: outCome = n8 if n9 > outCome: outCome = n9 if n10 > outCome: outCome = n10 sleep( 0.6 ) #Prints the correct text according to the users input. if choice = = "s" : print ( "The smallest number is %s." % outCome) sleep( 0.6 ) input ( 'Press "Enter" to exit!' ) if choice = = "b" : print ( "The biggest number is %s." % outCome) sleep( 0.6 ) input ( 'Press "Enter" to exit!' ) |
