0% found this document useful (0 votes)
38 views

Prime - Factorization (Num) :: '''Prime - Factorization (Num) STR Returns A String With The Prime Factorization of Num'''

Python has two division operators, / and //, that return a float and integer respectively. The % operator returns the modulus or remainder of a division. Strings can be enclosed in single, double, or triple quotes. The range function specifies the values to loop over, and we can loop over strings, lists, tuples, and dictionary keys. List methods like sort() and count() are also useful. The break and continue keywords allow early exits or skipping iterations in loops. Docstrings should describe functions, and functions should have docstrings for help systems. Descriptive naming conventions make code easier to read. Blank lines help separate parts of functions and programs. The main steps of programming are planning the algorithm, writing code, and testing and

Uploaded by

Anonymous User
Copyright
© © All Rights Reserved
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views

Prime - Factorization (Num) :: '''Prime - Factorization (Num) STR Returns A String With The Prime Factorization of Num'''

Python has two division operators, / and //, that return a float and integer respectively. The % operator returns the modulus or remainder of a division. Strings can be enclosed in single, double, or triple quotes. The range function specifies the values to loop over, and we can loop over strings, lists, tuples, and dictionary keys. List methods like sort() and count() are also useful. The break and continue keywords allow early exits or skipping iterations in loops. Docstrings should describe functions, and functions should have docstrings for help systems. Descriptive naming conventions make code easier to read. Blank lines help separate parts of functions and programs. The main steps of programming are planning the algorithm, writing code, and testing and

Uploaded by

Anonymous User
Copyright
© © All Rights Reserved
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 2

Python has two different divisions: / will return a float and //

will return an int. Often // is used in conjunction with %, the


modulus (or remainder) operator. Ex. 5//3 = 1, 10//4 = 2.

Strings can be enclosed in either single-quotes or double-


quotes. Or, a string can be enclosed in three quotes to be
extended over multiple lines -- this is called a docstring.

We can specify the values that it loops over using the range
function, or we can loop over a string, a list, a tuple, or a
dict. (When we loop over a dict, note that we loop over the
keys of the dict.) Notice that range(a,b) starts at a and stops
just before, but does not include, b. range(10) is the same as
range(0,10), and loops through 0,1,2,3,...,9.

Other list methods that are important are sort() to sort the
list, and count(element) to count the number of occurrences
of element in the list.

We can break out of either type of loop early using the break
keyword, or we can go immediately to the next iteration of
the loop using the continue keyword.

We should always follow our function declaration with a


docstring describing the functions. That's because IDLE's
help system can access your docstrings!
def prime_factorization(num):
    '''prime_factorization(num) ­> str
    returns a string with the prime factorization of 
num'''
Related to this: every function should have a docstring. I
don't want you to do things because of grades alone, but you
should know that your style score will suffer if there are
missing docstrings.
Use descriptive variable names. A single letter is almost
always a bad variable name except for the simplest of loops.
Use names_with_underscores() all lowercase for functions
and namesWithMixedCase (starting with a lowercase letter)
for variables -- that makes it easy to tell them apart. We'll
use names starting with uppercase for classes when we
cover object-oriented programming later in this course,
starting in Week 3. If you use a consistent naming
convention, it makes your code much easier to read.

Use blank lines to separate functions, or even to separate


significant parts of the same function.

Broadly speaking, there are three main steps in computer


programming:
* Plan out the algorithm.
* Turn the algorithm into actual computer code.
* Test the program to see if it works, and fix it if it's not.

You might also like