[Tutor] Question on running a small Python program
eric grunfeld
grunfelderic at gmail.com
Thu Aug 13 16:38:43 EDT 2020
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
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
More information about the Tutor
mailing list