Programming Programming Languages

# Get An Introduction to Python and LaTeX (draft) PDF

By Pramode C.E

Read or Download An Introduction to Python and LaTeX (draft) PDF

Best programming: programming languages books

Naftalin M., Wadler Ph.'s Generics and Collections in Java 5 PDF

This finished advisor exhibits you the way to grasp crucial adjustments to Java because it used to be first published. Generics and the significantly elevated assortment libraries have enormously elevated the facility of Java five and Java 6. yet they've got additionally harassed many builders who have not recognized tips to reap the benefits of those new positive aspects.

Additional resources for An Introduction to Python and LaTeX (draft)

Example text

3 Finding HCF using Euclid’s method The term algorithm is commonly used in computer programming. It refers to a precise set of rules for solving a problem. A very famous numerical algorithm exists to find out the highest common factor (also called the greatest common divisor) of two numbers. The algorithm was invented by Euclid; it’s therefore called the Euclid’s algorithm. Here is how the algorithm works. Say you wish to find out the HCF of two numbers A and B. Simply repeat the following steps until both numbers become equal: • If A is greater than B, change A to A-B and do not modify B • If B is greater than A, change B to B-A and do not modify A The value of A (and B) when both become equal will be the Highest Common Factor!

Return guess ... 000023178253949 >>> For finding square root of 16, we will call our function like this: square_root(1, 16) This will result in the parameter guess getting the value 1 and parameter x getting the value 16. 3. 01 Python calls the function good_enough with parameters 1 and 16 - good_enough will return False. The “not” operator, when it acts on the boolean value False, returns the value True. So we have the boolean value True in the condition part of the while loop. As condition is true, the body will get executed.

Try: ... m = (y2 - y1) / (x2 - x1) ... print ’computed slope’ ... except ZeroDivisionError: ... print ’unable to compute slope’ ... m = ’undefined’ ... return m ... 2. 01 unable to compute slope undefined >>> You can see two new keywords here: try and except. Python first attempts to execute statements between the try and the except (note that these statements are indented). If there is no zero division error, the except block (the indented set of statements after the line “except ZeroDivisionError:”) is skipped and the remaining part of the function (which is only a single return statement) gets executed.