Question about process: I am working on ps1, q1, and I would like to know if I should be working on the program in IDLE directly, or write it in full, save it, then run it in IDLE. I'm a newbie so please don't laugh at me.
It's better to write a new file. Space is cheap nowadays, and the fact that you can debug a lot easier with a new file surely outperforms the space usage. More than that, you will be able to reuse code you've already written. :-) Welcome to the course / group.
The first task anyone does when learning a new programming language is write the Hello World program, which is a simple program that just prints "Hello, world." Yes, it's simple, but it means you've gotten all the applications installed correctly that's necessary to write a program and run a program, and you know how to use those applications. That's not necessarily simple. As bmp says, you should be writing and saving your code in a .py file, then load (Run->Run Module, or F5) that code into the IDLE interpreter to run it. You can also just type commands into the IDLE window directly when you're just trying out some new syntax or functions you learned about. I'm using Windows. When I want to start writing a new program this is what I do: 1. Use Windows Explorer to find the folder I want to create the file in. 2. Create a new text document, and name it [something].py. 3. Right-click the file and choose Edit (when you installed IDLE it should have set up this context menu item). 4. Write some python code, and save it periodically. 5. When I think my code might be ready to run, hit F5. This opens an IDLE window which runs my code. If I have to run my code by calling one of my functions, I call it explicitly at the IDLE ">>>" prompt. 6. If it didn't work (as usual) I just go back to the edit window and change the code, and hit F5 again which runs my code in the same IDLE window that was already open. 7. Repeat step 6 while cursing a lot. 8. When I'm done, close all the edit windows and IDLE window. Python makes this process as easy as possible, but it IS still a process, and it takes some practice to get to the point where you can not have to think about the mechanics of programming, and just think about writing programs.
Thanks guys, I did get that far by completing ps0, the enter first name, last name one. Now I'm working on ps1, much more difficult.
Oh yes, I found PS1 to be quite intimidating coming from the first name-last name program. The best advice is to solve small parts of the problem first. Write a program that finds the first few primes. Then expand. The lectures & readings haven't gone over this before PS1 (which I found frustrating- "why didn't they tell me this in the beginning?!?), but another good idea is to write out what you want the program to do. Solve the problems by hand to make sure it's going to do what you think it should, then turn it into a program.
dmancine- How did you know I do step 7 exactly like that?
@Julie, Because that's how programming works. I'd say, even before trying to find a few primes, determine if one single number is prime. On your way to doing that, create a variable to hold the number that's being tested (like numberToTest), and write a for loop that iterates over possible divisors for that number (numbers from 2 to divisor-1), and prints each divisor. That way you can verify the loop does what you expect it to. Then add more functionality one tiny piece at a time, have it print what it's doing, then run the program and make sure it's printing what you expect. Get each little step to work before moving on to the next step.
Join our real-time social learning platform and learn together with your friends!