Forum in maintenance, we will back soon 🙂
Python Script
Hi I am going through the course and am on the loop module. I added the following code, it prints "Even number detected" but it doesnt print the odd number, what is wrong please?
@google-rayazsiddiqi you need to indent the "else:" statement so that it is in the same column position as the "if" statement.
Regards,
Earnie Boyd, CEO
Seasoned Solutions Advisor LLC
Schedule 1-on-1 help
Join me on Slack
@ssadvisor Many thanks Ernie, really appreciate it, I'll give it a try!
@ssadvisor Thanks Ernie, it's working now!!
Can someone explain what this code does: sum_numbers+=number
What does the "+" sign do?
Thanks
@google-rayazsiddiqi It's a shorter version of
sum_numbers = sum_numbers + number
Those who program like to program in short cuts so we don't have to type as much. You will also see:
a -= b a *= b a /= b
You can read it as take the value of the left variable, do the indicated arithmetic with the value of the right variable and then store the result into the left variable.
Regards,
Earnie Boyd, CEO
Seasoned Solutions Advisor LLC
Schedule 1-on-1 help
Join me on Slack
@ssadvisor thanks very much, makes sense now!
Hi, I am running the module script and it sin't working:
This is the module code:
def print_list_elements(my_list):
for element in my_list:
print(f"{element}")
And here is the script calling the module:
import my_module
fruits = ["apple", "banana", "cherry"]
my_module.print_list_elements(fruits)
This is the error I am getting:
AttributeError: module 'my_module' has no attribute 'print_list_elements'
Can someone please help?
Many Thanks
@google-rayazsiddiqi You've got to share this code with the code icon (<>) above to preserve the formatting. Python is indentation sensitive.
Regards,
Earnie Boyd, CEO
Seasoned Solutions Advisor LLC
Schedule 1-on-1 help
Join me on Slack
@google-rayazsiddiqi, please do what @ssadvisor mentioned to see if indentation in the code caused the problem.
But, anyway, are both files in the same folder? This error used to pop up when I had the module file outside the main script folder.
@ssadvisor Hi I couldn't find the <> code icon, so please see screenshots below, thanks for your help
@husein hi, the module code and the script code are in the same folder (althouhg this is not the same as the Pythin folder, is this the problem)?
@google-rayazsiddiqi I see from this picture that you haven't saved the changes to the my_modules.py file. In VS Code when in that module enter CTRL-S to save the code.
You should see the code icon <> when you comment in the middle of the icons.
Regards,
Earnie Boyd, CEO
Seasoned Solutions Advisor LLC
Schedule 1-on-1 help
Join me on Slack
@google-rayazsiddiqi They should show that they're in the same folder in the VS code, too.
I see it's very messy in VS code; try putting every project alone in a distant folder. It will facilitate navigation and provide a clear structure of your codes and folders (this has nothing to do with errors; it's to make things clearer for you)