I need to create a program that takes a user's input until they enter a 0 and then outputs the largest and smallest numbers out of what's been inputted
Woops, meant to say python
>>272458
This is really easy anon, here's some code. I haven't written in python before but I believe this is pretty close to what you need.
low = sys.max_int
high = sys.min_int
if input==0:
print min + "," + max
return
low = min(low,input)
high = max(high,input)
What's that got to do with snake?
What are the conditions for the input numbers, integers only?
>>272466
You need a while loop in there for the input
>>272467
I forgot about main methods, it has been so long since I've written anything that wasn't in a self contained method that you just call when you need it
Yup, the conditions are that it has to be an int the second anon's got the right idea
low = sys.max_int
high = sys.min_int
if input==0:
print (min + "," + max)
return
low = min(low,input)
high = max(high,input)
Trying to use return gave me a bug, try using this to test and adjust the program, using Py3 btw
https://repl.it/languages/python3 - test thing
Assuming that 0 isn't supposed to be counted towards min and max and assuming there will be at least one input before 0, this should work. It needlessly saves all the inputs, so the other solution might be better. Considering that this might be your 101 homework, I think it won't matter that much.
http://pastebin.com/Fw7hV2qE
>>272473
I think anon meant something like this
http://pastebin.com/4eLJ8pim
>>272478
Should be noted that line 4 is redundant on the second solution, I didn't bother reading through or thinking about it enough to notice immediately
#272479 Works great, but would it work without appends and breaking? As this is meant to be beginner work that I can understand and keep working from for further programs
>>272481
No appends means no lists
http://pastebin.com/pDgkMPYH
Now about system, would I be able to replace it with max, range, etc? As I haven't even heard about system until posting this thread. Also, I just wanna say thank you for your continued support, this goes out to all you guys.
>>272487
It comes down to prerequisites. Can you assume at least one input will be given before the user inputs 0? If so then you can just assign low and high to be the first input outside the loop. Should the program also work if the user just inputs 0 as their first number? Then you need to know what the program is supposed to do in that case, right now it just throws arbitrary numbers (at least to the user) as output.
Also, don't be afraid to do your own research and experiment, you can't expect everyone to spoonfeed you for everything like I have so far.
intHigh = 0
intLow = 0
userInput = int(input('Enter a number: '))
while userInput != 0:
userInput = int(input('Enter a number: '))
if intHigh < userInput:
intHigh = userInput
elif intLow > userInput:
intLow = userInput
print('Lowest:%s Highest:%s' % (intLow, intHigh))
This is my ideal set up for the program and what I kinda had before this thread, but it only outputs 0, the problem I see is that it wont update the integer's I've declared properly.
>>272491
http://pastebin.com/GGAhZeFh
Sorry about the constant requests, kind of a newfag when it comes to programming, and I think I'm getting what you're trying to set up, its just that my lowest only becomes the most recent number that is below the highest number
e.g
10
9
20
17
Output:
Highest = 20
Lowest = 17
http://pastebin.com/Ek2iy2yS
What I understand is that it isn't storing the older numbers and I don't exactly know how I'd be able to store that extra number.
>>272503
That's because you're comparing both with the intHighestNumber
Alright, I've managed to get it working properly by creating a mid point, now I've got to put boundary checks in, but thank you so much for all the help, couldn't have done it without you.
http://pastebin.com/m91TcLCX
Probably also worth clarifying (with your TA/whatever) how the input is defined.
All one string? "15243"
One per line? "Enter Number: 1"
Delimited by some character? "1,5,2,4,3"
Are decimals included? "1, 5.24, 3.0"
Lastly, reminder to do some arbitrary error handling (ignore letters and most symbols).