[Tutor] Question on running a small Python program
Joel Goldstick
joel.goldstick at gmail.com
Thu Aug 13 19:17:28 EDT 2020
On Thu, Aug 13, 2020 at 7:15 PM eric grunfeld <grunfelderic at gmail.com> wrote:
>
> Good Afternoon Everyone:
>
> I have been working on this small program in Python.
>
> The underlying point here is that the fractional_part function divides the
> numerator by the denominator.
>
> And then it returns just the fractional part (some number between 0 and 1).
>
> I am seeking to complete the body of the function so that it returns the
> right number
>
> However, I have been getting an error message (down below)
>
> Here is the code that I have inputted:
>
> def fractional_part(numerator, denominator):
> if denominator != 0
the next line needs to be indented . The previous line needs a :
> return (numerator % denominator)/denominator
>
> print(fractional_part(5, 5)) # Should be 0
> print(fractional_part(5, 4)) # Should be 0.25
> print(fractional_part(5, 3)) # Should be 0.66...
> print(fractional_part(5, 2)) # Should be 0.5
> print(fractional_part(5, 0)) # Should be 0
> print(fractional_part(0, 5)) # Should be 0
>
> This has been my error message: Error on line 4: if denominator != 0 ^
> SyntaxError: invalid syntax
>
> I look forward to your thoughts on this.
>
> Thank you.
> Eric
> _______________________________________________
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
--
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays
More information about the Tutor
mailing list