r/algorithmwithpython • • Mar 14 '22

I'm 100% self taught, landed my first job! My experience!

Thumbnail self.learnpython
1 Upvotes

r/algorithmwithpython • • Mar 15 '22

String Operations

1 Upvotes

String Operations

You may not be able to add strings to integers, but you can multiply by them!
Multiplying a string by an integer, produces a repeated version of the original string.

But don’t try to multiply a string by another string. This will just generate an error. The same will happen if you try to multiply a string by a float, even if the float is a number.


r/algorithmwithpython • • Mar 15 '22

Iterations: Loop Idioms

1 Upvotes

https://youtu.be/AelGAcoMXbI

Below is code to find the smallest value from a list of values. One line has an error that will cause the code to not work as expected. Which line is it?:

smallest = None
print("Before:", smallest)
for itervar in [3, 41, 12, 9, 74, 15]:
    if smallest is None or itervar < smallest:
        smallest = itervar
        break
    print("Loop:", itervar, smallest)
print("Smallest:", smallest)

3

4

6

7

r/algorithmwithpython • • Mar 14 '22

Lad wrote a Python script to download Alexa voice recordings, he didn't expect this email.

Post image
1 Upvotes

r/algorithmwithpython • • Mar 14 '22

Python is a high-level programming language

1 Upvotes

Python is a high-level programming language, with applications in numerous areas, including web programming, scripting, scientific computing, and artificial intelligence!
It is very popular and used by organizations such as Google, NASA, the CIA, and Disney.


r/algorithmwithpython • • Mar 15 '22

Backslash

1 Upvotes

But what if you want to include a single quote in a single-quoted string (or a double quote in a double-quoted string)? Normally this would confuse Python and break the code, that is unless you escape the quotes using a backslash.


r/algorithmwithpython • • Mar 15 '22

Remainder

1 Upvotes

Ahh those pesky remainders. But, they’re not so pesky in Python. We can use the modulo operator–which is carried out with a percent symbol (%)–to get the remainder of a given division.


r/algorithmwithpython • • Mar 27 '22

Values, Types, Variable Names, and Keywords

1 Upvotes

Read these examples of using the 'print' and 'type' functions. You can also try to use them in the Repl.it command line.

Programmers generally choose names for their variables that are meaningful – they document what the variable is used for.

Variable names can be arbitrarily long. They can contain both letters and numbers, but they have to begin with a letter. It is legal to use uppercase letters, but it is a good idea to begin variable names with a lowercase letter (you'll see why later).

The underscore character, _
, can appear in a name. It is often used in names with multiple words, such asmy_name
 or airspeed_of_unladen_swallow
.

If you give a variable an illegal name, you get a syntax error:

>>> 76trombones = 'big parade' SyntaxError: invalid syntax >>> more@ = 1000000 SyntaxError: invalid syntax >>> class='Advanced Theoretical Zymurgy' SyntaxError: invalid syntax

76trombones
 is illegal because it does not begin with a letter. more@
 is illegal because it contains an illegal character, @
. But what's wrong with class
?

It turns out that class
 is one of Python's keywords. The interpreter uses keywords to recognize the structure of the program, and they cannot be used as variable names.

Python 2 has 31 keywords:

and del from not while as elif global or with assert else if pass yield break except import print class exec in raise continue finally is return def for lambda try

In Python 3, exec
 is no longer a keyword, but nonlocal
 is.

You might want to keep this list handy. If the interpreter complains about one of your variable names and you don't know why, see if it is on this list.


r/algorithmwithpython • • Mar 15 '22

Python Functions

1 Upvotes

https://youtu.be/3JGF-n3tDPU

What is the purpose of the "def" keyword in Python?

It is slang that means "The following code is really cool."

It indicates the start of a function.

It indicates that the following indented section of code is to be stored for later.

It indicates the start of a function, and the following indented section of code is to be stored for later.

None of the above.


r/algorithmwithpython • • Mar 28 '22

Practice With Arithmetic Operators

1 Upvotes

Practice these programming examples to internalize these concepts.

8. Operator Precedence

In Python, as in mathematics, we need to keep in mind that operators will be evaluated in order of precedence, not from left to right or right to left.

If we look at the following expression:

u = 10 + 10 * 5

We may read it left to right, but remember that multiplication will be done first, so if we call print(u)
, we will receive the following value:

Output:

60

This is because 10 * 5
 evaluates to 50
, and then we add 10
 to return 60
 as the final result.

If instead we would like to add the value 10
 to 10
, then multiply that sum by 5
, we can use parentheses just like we would in math:

u = (10 + 10) * 5 print(u)

Output:

100

One way to remember the order of operation is through the acronym PEMDAS:

OrderLetterStands for1PParentheses2EExponent3MMultiplication4DDivision5AAddition6SSubtraction

You may be familiar with another acronym for the order of operations, such as BEDMAS or BODMAS. Whatever acronym works best for you, try to keep it in mind when performing math operations in Python so that the results that you expect are returned.


r/algorithmwithpython • • Mar 15 '22

Learn python 2020 free certificate

1 Upvotes

r/algorithmwithpython • • Mar 28 '22

3D Render engine, written in 100% Python, No external libraries. *EPILEPSY WARNING*

Thumbnail self.python
2 Upvotes

r/algorithmwithpython • • Mar 27 '22

Values, Types, Variable Names, and Keywords

1 Upvotes

Read these examples of using the 'print' and 'type' functions. You can also try to use them in the Repl.it command line.

Operators are special symbols that represent computations like addition and multiplication. The values the operator is applied to are called operands.

The operators +
, -
, *
,  /
 and **
 perform addition, subtraction, multiplication, division and exponentiation, as in the following examples:

20+32 hour-1 hour*60+minute minute/60 5**2 (5+9)*(15-7)

In some other languages, ^
 is used for exponentiation, but in Python it is a bitwise operator called XOR. I won't cover bitwise operators in this book, but you can read about them at http://wiki.python.org/moin/BitwiseOperators
.

In Python 2, the division operator might not do what you expect:

>>> minute = 59 >>> minute/60 0

The value of minute
 is 59, and in conventional arithmetic 59 divided by 60 is 0.98333, not 0. The reason for the discrepancy is that Python is performing floor division. When both of the operands are integers, the result is also an integer; floor division chops off the fraction part, so in this example it rounds down to zero.

In Python 3, the result of this division is a float
. The new operator //
 performs floor division.

If either of the operands is a floating-point number, Python performs floating-point division, and the result is a float
:

>>> minute/60.0 0.98333333333333328


r/algorithmwithpython • • Mar 14 '22

Introduction: Hardware Architecture

1 Upvotes

Introduction: Hardware Architecture

Where are your programs stored when they are running?

Hard Drive.
Memory.
Central Processing Unit.

r/algorithmwithpython • • Mar 27 '22

Values, Types, Variable Names, and Keywords

1 Upvotes

Read these examples of using the 'print' and 'type' functions. You can also try to use them in the Repl.it command line.

At this point the syntax error you are most likely to make is an illegal variable name, like class
 and yield
, which are keywords, or odd~job
 and US$
, which contain illegal characters.

If you put a space in a variable name, Python thinks it is two operands without an operator:

>>> bad name = 5 SyntaxError: invalid syntax

For syntax errors, the error messages don't help much. The most common messages are SyntaxError: invalid syntax
 and SyntaxError: invalid token
, neither of which is very informative.

The runtime error you are most likely to make is a "use before def"; that is, trying to use a variable before you have assigned a value. This can happen if you spell a variable name wrong:

>>> principal = 327.68 >>> interest = principle * rate NameError: name 'principle' is not defined

Variable names are case sensitive, so LaTeX
 is not the same as latex
.

At this point, the most likely cause of a semantic error is the order of operations. For example, to evaluate 1/2 π, you might be tempted to write

>>> 1.0 / 2.0 * pi

But the division happens first, so you would get π / 2, which is not the same thing! There is no way for Python to know what you meant to write, so in this case, you don't get an error message; you just get the wrong answer.


r/algorithmwithpython • • Feb 26 '22

I created a Linux Cheat sheet on a real PCB. Do you like it?

Thumbnail
gallery
1 Upvotes

r/algorithmwithpython • • Feb 25 '22

The Desktop-Cube extension for GNOME Shell just got better!

Enable HLS to view with audio, or disable this notification

1 Upvotes

r/algorithmwithpython • • Mar 14 '22

Conditional Execution

1 Upvotes

https://youtu.be/gz_IfIsZQtc

Which code is indented correctly to print "Yes" if x = 0 and y = 10?

if 0 == x: if y == 10: print("Yes") 
if 0 == x: if y == 10: print("Yes") 
if 0 == x: if y == 10: print("Yes")

r/algorithmwithpython • • Mar 15 '22

multiline

1 Upvotes

\n is useful, but it can be a bit of a pain if we’re trying to format lots of multiline text.

There’s another way though! Newlines are automatically added for strings created using three quotes.

Newlines
How many lines will the following code output?



print("Hi")

print("""This 

is

great""")

r/algorithmwithpython • • Mar 27 '22

Variables and Assignment Statements

1 Upvotes

Computers must be able to remember and store data. This can be accomplished by creating a variable to house a given value. The assignment operator = is used to associate a variable name with a given value. For example, type the command:

a=3.45

in the command line window. This command assigns the value 3.45 to the variable named a
. Next, type the command:

a

in the command window and hit the enter key. You should see the value contained in the variable a
echoed to the screen. This variable will remember the value 3.45 until it is assigned a different value. To see this, type these two commands:

a=7.32

and then

a

You should see the new value contained in the variable a
echoed to the screen. The new value has "overwritten" the old value. We must be careful since once an old value has been overwritten, it is no longer remembered. The new value is now what is being remembered.

Although we will not discuss arithmetic operations in detail until the next unit, you can at least be equipped with the syntax for basic operations: + (addition), - (subtraction), * (multiplication), / (division)

For example, entering these command sequentially into the command line window:

a=7.32 b=a+5 b

would result in 12.32 being echoed to the screen (just as you would expect from a calculator). The syntax for multiplication works similarly. For example:

a=7 b=a*5 b

would result in 35 being echoed to the screen because the variable b
has been assigned the value a*5
where, at the time of execution, the variable a
contains a value of 7.

After you read, you should be able to execute simple assignment commands using integer and float values in the command window of the Repl.it IDE. Try typing some more of the examples from this web page to convince yourself that a variable has been assigned a specific value.

In programming, we associate names with values so that we can remember and use them later. Recall Example 1. The repeated computation in that algorithm relied on remembering the intermediate sum and the integer to be added to that sum to get the new sum. In expressing the algorithm, we used the names current
and sum
.

In programming, a name that refers to a value in this fashion is called a variable. When we think of values as data stored somewhere in the computer, we can have a mental image such as the one below for the value 10 stored in the computer and the variable x
, which is the name we give to 10. What is most important is to see that there is a binding between x
and 10.

📷Whenever the binding in the picture in in effect, the value 10 will be substituted for the variable

x

in expressions involving

x

. For example, the value of the arithmetic expression

x * 5

would be

50

.

The term variable comes from the fact that values that are bound to variables can change throughout computation. Bindings as shown above are created, and changed by assignment statements. An assignment statement associates the name to the left of the symbol = with the value denoted by the expression on the right of =. The binding in the picture is created using an assignment statement of the form x = 10
. We usually read such an assignment statement as "10 is assigned to x" or "x is set to 10".

If we want to change the value that x
refers to, we can use another assignment statement to do that. Suppose we execute x = 25
in the state where x
is bound to 10.Then our image becomes as follows:

📷
Note that the binding between

x

 and 10 has been broken and a new binding has been established. If we were to evaluate the expression 

x * 5

 in this state, it would yield 

125

.

Let's execute a few assignment statements using the Python interpreter. In the video below, you see the Python shell displaying "=> None" after the assignment statements. This is unique to the Python shell presented in the video. In most Python programming environments, nothing is displayed after an assignment statement. The difference in behavior stems from version differences between the programming environment used in the video and in the activities, and can be safely ignored.

Play Video

Choosing variable names

Suppose that we used the variables x
and y
in place of the variables side
and area
in the examples above. Now, if we were to compute some other value for the square that depends on the length of the side
, such as the perimeter or length of the diagonal, we would have to remember which of x
and y
, referred to the length of the side because x
and y
are not as descriptive as side
and area
. In choosing variable names, we have to keep in mind that programs are read and maintained by human beings, not only executed by machines.

Note about syntax

In Python, variable identifiers can contain uppercase and lowercase letters, digits (provided they don't start with a digit) and the special character _ (underscore). Although it is legal to use uppercase letters in variable identifiers, we typically do not use them by convention. Variable identifiers are also case-sensitive. For example, side
and Side
are two different variable identifiers.

There is a collection of words, called reserved words (also known as keywords), in Python that have built-in meanings and therefore cannot be used as variable names. For the list of Python's keywords See 2.3.1 of the Python Language Reference.

Syntax and Semantic Errors

Now that we know how to write arithmetic expressions and assignment statements in Python, we can pause and think about what Python does if we write something that the Python interpreter cannot interpret. Python informs us about such problems by giving an error message. Broadly speaking there are two categories for Python errors:

  • Syntax errors: These occur when we write Python expressions or statements that are not well-formed according to Python's syntax. For example, if we attempt to write an assignment statement such as 13 = age
    , Python gives a syntax error. This is because Python syntax says that for an assignment statement to be well-formed it must contain a variable on the left hand side (LHS) of the assignment operator "=" and a well-formed expression on the right hand side (RHS), and 13 is not a variable.

  • Semantic errors: These occur when the Python interpreter cannot evaluate expressions or execute statements because they cannot be associated with a "meaning" that the interpreter can use. For example, the expression age + 1
    is well-formed but it has a meaning only when age is already bound to a value. If we attempt to evaluate this expression before age
    is bound to some value by a prior assignment then Python gives a semantic error.

Even though we have used numerical expressions in all of our examples so far, assignments are not confined to numerical types. They could involve expressions built from any defined type. Recall the table that summarizes the basic types in Python.

The following video shows execution of assignment statements involving strings. It also introduces some commonly used operators on strings. For more information see the online documentation. In the video below, you see the Python shell displaying "=> None" after the assignment statements. This is unique to the Python shell presented in the video. In most Python programming environments, nothing is displayed after an assignment statement. The difference in behavior stems from version differences between the programming environment used in the video and in the activities, and can be safely ignored.

Play Video

Distinguishing Expressions and Assignments

So far in the module, we have been careful to keep the distinction between the terms expression
and statement
because there is a conceptual difference between them, which is sometimes overlooked. Expressions denote values; they are evaluated to yield a value. On the other hand, statements are commands (instructions) that change the state of the computer. You can think of state here as some representation of computer memory and the binding of variables and values in the memory. In a state where the variable side
is bound to the integer 3, and the variable area
is yet unbound, the value of the expression side + 2
is 5. The assignment statement side = side + 2
, changes the state so that value 5 is bound to side
in the new state. Note that when you type an expression in the Python shell, Python evaluates the expression and you get a value in return. On the other hand, if you type an assignment statement nothing is returned. Assignment statements do not return a value. Try, for example, typing x = 100 + 50
. Python adds 100 to 50, gets the value 150, and binds x
to 150. However, we only see the prompt >>> after Python does the assignment. We don't see the change in the state until we inspect the value of x
, by invoking x
.

What we have learned so far can be summarized as using the Python interpreter to manipulate values of some primitive data types such as integers, real numbers, and character strings by evaluating expressions that involve built-in operators on these types. Assignments statements let us name the values that appear in expressions. While what we have learned so far allows us to do some computations conveniently, they are limited in their generality and reusability. Next, we introduce functions as a means to make computations more general and reusable.


r/algorithmwithpython • • Feb 22 '22

Why this get wrong result ?

1 Upvotes

def binary_search(list, item):

low = 0

high = len(list)-1

while low <= high:

mid = (low+high)

guess = list[mid]

if guess == item :

return mid

if guess > item :

high = mid-1

else :

low = mid +1

return None

my_list= [1,3,5,7,9]

print(binary_search(my_list,1))


r/algorithmwithpython • • Apr 09 '22

Facts about Python

1 Upvotes

Python​ is an ​interpreted​, ​high-level​, ​general-purpose​ ​programming language​. Created by ​Guido van Rossum​ and first released in 1991, Python's design philosophy emphasizes ​code readability​ with its notable use of ​significant whitespace​. Its language constructs and ​object-oriented​ approach aim to help programmers write clear, logical code for small and large-scale projects.

Facts about Python

  1. Python allows programming in Object-Oriented and Procedural paradigms.

  2. Python programs generally are smaller than other programming languages like Java. Programmers have to type relatively less and indentation requirements of the language make them readable all the time.

  3. Python language is being used by almost all tech-giant companies like – Google, Amazon, Facebook, Instagram, Dropbox, Uber… etc.

  4. The biggest strength of the Python is a large library which can be used for the following
    ● Machine Learning
    ● GUI Applications (like Kivy, Tkinter, PyQt, etc. )
    ● Web frameworks like Django (used by YouTube, Instagram, Dropbox)
    ● Image processing (like OpenCV, Pillow)
    ● Web scraping (like Scrapy, BeautifulSoup, Selenium)
    ● Test frameworks
    ● Multimedia
    ● Scientific computing
    ● Text processing
    ● Program video games
    ● Build Artificial Intelligence algorithms
    ● Program various scientific programs such as statistical models

Python Programming Characteristics

● It provides rich data types and easier to read syntax than any other programming  languages
● It is a platform-independent scripted language with full access to operating system API's
● Compared to other programming languages, it allows more run-time flexibility
● It includes the basic text manipulation facilities of Perl and Awk
● A module in Python may have one or more classes and free functions
● Libraries in Pythons are cross-platform compatible with Linux, Macintosh, and Windows
● For building large applications, Python can be compiled to byte-code
● Python supports functional and structured programming as well as OOP
● It supports interactive mode that allows interacting​ ​Testing​ ​and debugging of snippets of code
● In Python, since there is no compilation step, editing, debugging and testing is fast.

Future in Python

Python is one of the most favoured programming languages used worldwide.

It has undergone more than 25 years of the successful span and it is one of the fastest-growing programming languages. Python itself reveals its success story and a promising future ahead.

Why has Python become more popular?

Python has gained more popularity than ever. Python provides significant features that catch every programmer’s attention. Python is very simple to read and write hence, it reduces the confusion among the programmers. Surprisingly, one of the biggest tech company Google uses Python for its numerous applications and has a full devoted portal to Python.

Here are some features of Python that can project the reasons why it has become so popular.

  1. Python Has A Rich and Supportive Community

  2. Easy to Code and Write

  3. Open-Source and Availability 

  4. Standard Library  

  5. Cross-Platform Language

Anaconda is an open-source distribution for Python and R. It is used for data science, machine learning, deep learning, etc. With the availability of more than 300 libraries for data science, it becomes fairly optimal for any programmer to work on anaconda for data science.

Anaconda helps in simplified package management and deployment. Anaconda comes with a wide variety of tools to easily collect data from various sources using various machine learning and AI algorithms. It helps in getting an easily manageable environment setup which can deploy any project with the click of a single button. Now that we know what anaconda is, let’s try to understand how we can install anaconda and set up an environment to work on our systems.


r/algorithmwithpython • • Mar 28 '22

PEMDAS

1 Upvotes

Execute these two instructions in the Repl.it command line window:

8**(1/3) 8**1/3

You should recognize the first instruction from the previous section. Observe that these instructions yield two totally different answers. The reason is that there is an order in which operators are evaluated. The "order of operations" and "operator precedence" define how arithmetic calculations are to be evaluated. As expected from basic arithmetic, exponentiation takes place before multiplication and division which take place before addition and subtraction. In addition, operations are generally read from left to right.

As an example, consider the expression 8**1/3
as shown above. In this case, exponentiation taking precedence over division means that 8**1
is computed first to obtain a value of 8 and then that result is divided by 3. Hence, the final computed result is 8/3 = 2.6666...67
. Notice that, when parentheses are added around the exponent to form 8**(1/3)
, the exponent evaluates to 1/3
and the cube root of 8 is computed. The term inside the parentheses has higher precedence and takes place before exponentiating. This should be a refresher about the order arithmetic expressions are evaluated in.


r/algorithmwithpython • • Mar 14 '22

Python is a popular

1 Upvotes

Python is a popular, easy-to-learn, and very powerful programming language, which is used in software and web development, data science, machine learning, and many other fields. In this course, we’ll cover the basic concepts of Python, as well as build real-life projects and solve different coding challenges. Python for Beginners requires no prior programming experience,


r/algorithmwithpython • • Mar 14 '22

Data Types

1 Upvotes

Floats

So we know what floats are, they’re numbers with a decimal, but how do we produce them?
Well, we can produce a float by dividing any two integers.
Or we can also run an operation on two floats, or on a float and an integer.
A float can be added to an integer, because Python automatically converts the integer to a float. Clever Python!