from is_odd import is_odd
def display_number_report(start, stop):
"""
Shows a report on the frequency of use of each word between two numbers.
"""
if start <= stop:
step = 1
else:
step = -1
for number in range(start, stop + step, step):
print(f'{number}: ', end='')
if is_odd(number):
print('odd ', end='')
else:
print('even ', end='')
if number % 3 == 0:
print('div 3 ', end='')
if number % 5 == 0:
print('div 5 ', end='')
print()
display_number_report(1,7)
print()
return_value = display_number_report(3,3)
print(return_value)
#π Works in VS but when submitted comes up with ***Run error***
29 messages Β· Page 1 of 1 (latest)
@silk dirge
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
Closes after a period of inactivity, or when you send !close.
When submitted for marking this is shown:
Run error
Traceback (most recent call last):
File "tester.python3", line 161, in <module>
from is_odd import is_odd
ModuleNotFoundError: No module named 'is_odd'
do you have a file named is_odd?
Yes
also, what do you mean by "when submitted"
When I run the above code in Vs it returns:
1: odd
2: even
3: odd div 3
4: even
5: odd div 5
6: even div 3
7: odd
3: odd div 3
None
but when submitted the question for marking the error message shows
if youre not submitting the is_odd file it obviously wont work
The is odd file is already submitted previously
when the site runs the file it looks like it doesnt use that file
either just submit that file or move all the code in is_odd into this file and remove the import
whichever works better according to your assignment
Do not include the code for the is_odd or is_even function. If you do, your code will be rejected. Moodle has a copy of the is_odd and is_even function that it will use when testing your display_number_report function.
odd
perhaps try not importing it?
in the sense that, moodle will declare it globally for you
Create a function called display_number_report which has two parameters and returns None.
display_number_report has two parameters
start
stop
Both start and stop are mandatory. Both are integers.
start can be less than, equal to or greater than stop.
Display all the whole numbers between the start and stop values inclusively. If the number is odd or even or is divisible by 3 or by 5 (or both), inform the user as per the examples.
If the number is divisible by 3 and by 5, inform the user as per the examples with div 3 appearing before div 5.
The display_number_report function must call either the is_odd or is_even function you created for Lab 5-1-1 Q3 & Q4 respectively to work out if a number is odd or even.
The function must include an appropriate docstring.
Hints.
The code could be between 10 and 19 lines long excluding docstring, blank lines and comments.
Set the step based on the values being in ascending or descending order.
You can assume start and stop will only ever receive integers.
Code containing the break state will be rejected.
Not all the tests that are used are shown.
Thats what the instructions are but i'm feeling stuck as to why it isn't working
and not importing it from anywhere also failed?
Yeah it isn't working
whatβs the name of the file in which you defined is_odd?
that you uploaded to this site
regardless iβd just reimplement the function and try coming back to it later. checking whether a number is odd should be a single line
Ok thanks for your help
out of curiosity what course/class are you taking
Introduction to programming
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.