ese-msc / introduction-to-python

"Introduction to Python" course for future Imperial College London MSc students
BSD 3-Clause "New" or "Revised" License
75 stars 94 forks source link

Exercise 1.9 in lecture 1 #47

Closed gems-rk23 closed 1 year ago

gems-rk23 commented 1 year ago

This is my code:

Uncomment and complete this code - keep the names the same for testing purposes.

from math import pi, sqrt

def period(a, m_planet, m_sun=2e30, G=6.67e-11): P_mars = sqrt(4*pi2(1.5a)3/(G(m_sun + 0.1m_planet))) P_earth = sqrt(4*pi*2a*3/G/(m_sun + m_planet)) birthdays = 10P_mars/P_earth return P_mars, P_earth, birthdays

but when I test it by pybryt, it shows this comment below:

REFERENCE: exercise-1_9 SATISFIED: False MESSAGES:

What is wrong with my code?

marijanbeg commented 1 year ago

Hi @gems-68239853, thank you for raising the issue and we hope you enjoy working on your Python exercises.

Function period should compute and return the period of a single planet. Then you should call it separately for Mars and for Earth. In your case, you are computing all periods, including birthday in the function, and return a tuple. We believe that fixing this would make PyBryt tests pass.

gems-rk23 commented 1 year ago

Hello Mr. Marijanbeg, thank you for responding to me.

Thank you for the hint, I fixed my code and it worked perfectly!

marijanbeg commented 1 year ago

Great, thank you for letting us know.