Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Think my math is wrong?
#4
How would one do this?

tried slipping in a cheeky
 l = [int(lst) for lst in l] 
directly above the lst.append but that seemed to cause more issues

(Nov-05-2019, 02:56 PM)buran Wrote: With even number of elements median should be the mean of the middle two numbers (i.e. the true division of the middle 2 elements)- mid and mid+1, not mid-1
med = (srt[mid] + srt[mid+1]) / 2

Also because of using floor division you don't need to explicitly convert to int on line 8 (but this is just a note)

that said, you better add argument to median function, instead of using global variable lst

With these amendments i get the error "int expected str received" in turn it kills itself. Also declaring the "l = input()" to be int it also kills itself with "ValueError: invalid literal for int() with base 10: ''"


furthermore, with the script it its original state and changing the -1 to +1 were told too the input is 8 8 8 8 by the user my median is apparently 44?

Actually.

Applying the suggested math changes and by simplying changing the append to lst.append(int(l))

it bloody worked, so cheers
Reply


Messages In This Thread
Think my math is wrong? - by edwdas - Nov-05-2019, 02:40 PM
RE: Think my math is wrong? - by ichabod801 - Nov-05-2019, 02:48 PM
RE: Think my math is wrong? - by buran - Nov-05-2019, 02:56 PM
RE: Think my math is wrong? - by edwdas - Nov-05-2019, 02:58 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Am I wrong or is Udemy wrong? String Slicing! Mavoz 3 2,577 Nov-05-2022, 11:33 AM
Last Post: Mavoz
  math.log versus math.log10 stevendaprano 10 2,427 May-23-2022, 08:59 PM
Last Post: jefsummers
  Why getting ValueError : Math domain error in trig. function, math.asin() ? jahuja73 3 3,783 Feb-24-2021, 05:09 PM
Last Post: bowlofred
  python gives wrong string length and wrong character thienson30 2 3,025 Oct-15-2019, 08:54 PM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020