I have been, off and on, dealing with trying to learn python (though not doing so well…)
The major issue I’m having is that I can’t ask the instructor of the Udemy class I’m taking what I’m doing wrong.
So I went back (now that I “have” you all to bounce stuff off) today and I’m stuck on day 9 of 100 days (it’s taking me weeks per “day” but I digress) – I wrote some code but can’t find it and am totally lost (It’s been a while since I “attacked” the problem – it’s an assignment to write a “test if this number is prime” program. – now I know that there are few numbers to check (I’ve been doing it in my head for years) – Prime numbers (other than 5 since any number ending in a 5 is divisible by 5 so only 5 is a prime) up to the square root of the number being tested – so if you’re checking, say, 119 – you know it can’t be more than 11 since 11^2 us 121 – so you need to check 3, and 7 since 9 is not prime and even numbers (other than 2 there are no prime even numbers since they are all divisible by 2) and 11 clearly doesn’t go into 119…
So I know the way to do it in my head so I need to figure out how to do it in Python – or some coding language.
There is going to have to be some functions, I would think – one to divide numbers into the input number – does python have recursion? It would seem to me a recursive function that checks lower primes to divide into the input number…Am I rambling???
Anyway, is there anyone here who “speaks fluent” Python and can help me with this???
Thanks in advance.
One important thing always to do is not recreate the wheel (no matter how much you want to do that). I looked up “test if this number is prime python” and a full array of previously written code came up in the search. Here’s an example: Python Program to Check Prime Number There’s also stuff from stackoverflow and geeksforgeeks.org that might get your creative juices flowing. Different programmers have different solutions, so there are examples of all kinds and not just “one” approach. I’m seriously impressed you can to the math in your head! Wish I could be more help, but I’m just a beginner on python, as well.
Thanks – I’m sure there are already functions or the like (pieces of code???) written for this, but the idea is for me to learn. But syntax is always the hardest part because you have to know the specific syntax for the specific language (like is there nothing at the end of a “sentence” or a comma, a semi-colon, a period or do different punctuation marks designate different purposes.
Well, if you have the stamina to do it from scratch, keep marching forward. My own preference is to beg, borrow or steal from anywhere else to help me get going. Of course, as time goes on and the work (and syntax) become more embedded in my brain, there’s a lot more whining and much less “borrowing”. Still, there’s so much help out there, I’m sure you’ll find a way to get started. Recently, I learned about Thonny, which is a debugging tool for python. Many distros have it built in, so you can check your software manager or repository. It is useful in some ways because it is soooooooooo explicit about the errors that correcting syntax errors got a whole lot easier.
Can you post a Gist or your code?
I LOVE this attitude. I think a lot of the younger generation are hurting themselves by not learning how to properly write code, or learn how it works.
Unfortunately, I can’t find the code – It’s not anywhere in the course, nor is it on the page where I have code from other assignments.
I guess I’ll have to start again…
When I get something written I’ll show it to you
I hope I connect with the Python code at some point