+ 3
Challenge
I have a little challenge for you guys. I don't know how to do it myself, but I'm curious to see what you all can come up with. Write a code that will take a set of data of ANY size (so you don't know how many data points the user will enter) and then find the median. Also note that you have to get the program to rearrange the data into numerical order if it isn't in order already. NOTE: If you don't already know how to find a median anyway, go to bit.ly/HowToMedian Keep in mind that if a user enters a data set with an odd number of points, you have to take the average of the two center points. For example, if the data set is [1, 3, 5, 8] then you would have to take the average of 3 and 5, which is 4.
18 ответов
+ 1
https://imgur.com/a/ngCrlmY
as i said, our inputs likely differ, as the code can't return different things for the same input
+ 3
smells a bit like homework, but i did it anyways, here you go.
https://code.sololearn.com/c084Pz6d0Qiw/?ref=app
+ 3
https://code.sololearn.com/c7LJuhX86uZi/?ref=app
+ 1
It's not my homework, I've just been thinking on it for about a day now and can't figure it out. I don't even take a programming class lol.
+ 1
Jackson Meddows the first line takes the input and turns it into an array of integers, the second line sorts it in rising order, and the third one checks whether or not the length of the array is odd. if it is, then it just prints out the element at the middle. if not, it prints the average of the two elements at the middle
+ 1
Jackson Meddows the ordered data set is [8 9 9 9 9 10 11 11 11 13 13]. the length is 11, so the median is the 6th element which is 10, the code should output that too
edit: for me it outputs 10, your input was probably wrong
+ 1
oh that makes sense. When I tried to read it, I was so overloaded by information and confusion that I didn't process any of it lol.
sorry about that!
0
Wow your program is complicated.... i don't understand it at all lmao
0
I'm not sure it works.... I put in the data set [9 13 9 11 9 13 11 9 10 8 11] and the output should have been 10 but it was 9.... i don't know
0
I'm going to run the code again and see what happens.
0
It just outputs 9. Try it yourself
0
Jackson Meddows tried it multiple times now, keeps giving me 10. if you wish i can provide screenshots
0
This is really weird.... idk what's going on
0
@hinanawi I believe you. I don't think you're lying or anything. I just don't understand why we're running the same code with the same input and getting different outputs.
Did you check that your input is 9 13 9 11 9 13 11 9 10 8 11?
0
Doesn't it say that multiple inputs have to be on different lines?
0
Jackson Meddows i specified in my code that it takes a single line input, separated by spaces
0
Is it possible to rewrite that code so that it accepts input on separate lines? Just out of curiosity....
0
Jackson Meddows indeed it is. you would input a number, create an array of that size, fill it with a for loop and then perform line 2 onwards