https://artofproblemsolving.com/wiki/api.php?action=feedcontributions&user=Anstar&feedformat=atomAoPS Wiki - User contributions [en]2020-10-28T12:19:00ZUser contributionsMediaWiki 1.31.1https://artofproblemsolving.com/wiki/index.php?title=Basic_Programming_With_Python&diff=134878Basic Programming With Python2020-10-10T19:37:22Z<p>Anstar: /* __init__ */</p>
<hr />
<div>'''Important: It is extremely recommended that you read [[Getting Started With Python Programming]] before reading this unless you already know some programming knowledge.'''<br />
<br />
(Note: This is a really long article. To learn the most from this article, you need to read everything in order and skip nothing, unless you are '''absolutely absolutely sure that that content is way too easy for you.''')<br />
<br />
This article will talk about some basic Python programming. If you don't even know how to install Python, look [[Getting Started With Python Programming|here]].<br />
<br />
Note that this article has lots of program examples. It is recommended (but not required) to try these on your own before looking at the solutions.<br />
<br />
==Loops==<br />
<br />
There are two different kinds of loops in Python: the for loop and the while loop.<br />
<br />
===The For Loop===<br />
<br />
The for loop iterates over a list, or an array, of objects. You have probably seen this code before:<br />
<br />
[[File:Capture.PNG|200px]]<br />
<br />
This for loop iterates over the list of integers from 1 to 51, excluding the 51 and including the 1. That means it is a list from 1 to 50, inclusive. On every iteration, Python will print the number that the loop is iterating through. <br />
<br />
For example, in the first iteration, i = 1, so Python prints 1.<br />
<br />
In the second iteration, i = 2, so Python prints 2.<br />
<br />
This continues so on until the number, 50, is reached. Therefore, the last number Python will print out is 50.<br />
<br />
====Program Example====<br />
<br />
'''Find <math>\sum_{n=1}^{50} 2^{n}.</math>'''<br />
<br />
To do this task, we must create a for loop and loop over the integers from 1 to 50 inclusive:<br />
<br />
for i in range(1,51):<br />
<br />
Now what? We must keep a running total and increase it by <math>2^i</math> every time:<br />
<br />
total = 0<br />
for i in range(1,51):<br />
total += 2**i<br />
<br />
We must not forget to print the total at the end!<br />
<br />
total = 0<br />
for i in range(1,51):<br />
total += 2**i<br />
print(total)<br />
<br />
You must exit out of the for loop one you reach the print(total) line by pressing backspace.<br />
<br />
Once you run your program, you should get an answer of <math>\boxed{2,251,799,813,685,246.}</math><br />
<br />
===The While Loop===<br />
<br />
While loops don't loop over a list. They loop over and over and over...'''until'''...a condition becomes false.<br />
<br />
i = 3<br />
total = 0<br />
while i < 1000:<br />
total += i<br />
i += 3<br />
print(total)<br />
<br />
In this code, the while loop loops 333 times, until <math>i</math> becomes greater than or equal to 1000.<br />
<br />
====Program Example====<br />
<br />
'''Find <math>\sum_{n=1}^{50} 2^n</math> using a while loop.'''<br />
<br />
We must create a while loop that will iterate until n is greater than <math>50.</math><br />
<br />
n = 1<br />
total = 0<br />
while n <= 50:<br />
total += 2**n<br />
n += 1<br />
print(total)<br />
<br />
We must not forget to include the n += 1 line at the end of the while loop! <br />
<br />
If we run this, we will get the same answer as last time, <math>2,251,799,813,685,246.</math><br />
<br />
==Functions==<br />
<br />
In this section, we will define new operations and do arithmetic with them in Python.<br />
<br />
===The New Operation===<br />
Let's say that you defined a new binary operation, the <math>\uparrow \downarrow.</math> You want it to be so <math>a \uparrow \downarrow b = a^{b}b^{a}.</math> Therefore, <math>1\uparrow \downarrow 2 = 1^{2}2^{1}=1\cdot 2= 2,</math> and <math>2\uparrow \downarrow 3 = 2^33^2 = 8\cdot 9 = 72.</math> Let's call this operation an '''up down arrow.'''<br />
<br />
===Program Example 1===<br />
<br />
'''Find <math>[2 \uparrow \downarrow (1 \uparrow \downarrow 2)] \uparrow \downarrow 2.</math>'''<br />
<br />
We know this will be a big number, so we should write a program to do it! We certainly don't want to do the exponentiation and multiplication every time we use the operation in our program, and that's where functions come in! Functions can take in parameters (<math>a</math> and <math>b</math>) and return a result depending on the parameters.<br />
<br />
def up_down_arrow(a,b): <br />
return ((a**b) * (b**a))<br />
<br />
Above is the code to define our function. We need to print the final result at the end, so we must put a print statement at the end.<br />
<br />
def up_down_arrow(a,b): <br />
return ((a**b) * (b**a))<br />
print(up_down_arrow(up_down_arrow(2,up_down_arrow(1,2)),2)<br />
<br />
All those nested up_down_arrow's might be confusing at first, but it really isn't that confusing.<br />
If you run your program, you should get your answer: <math>16,777,216.</math> <br />
<br />
You might be surprised that the answer is so big. If you actually start calculating the real answer without a program, you will really quickly find that the final result is <math>16 \uparrow \downarrow 2,</math> which does turn out to be 16,777,216 if you use a calculator.<br />
<br />
Let's make another operation!<br />
<br />
We will define the operation <math>\uparrow \downarrow \leftarrow \rightarrow</math> to be called '''all around.''' <math>a \uparrow \downarrow \leftarrow \rightarrow b = (ab(a \uparrow \downarrow b))^2.</math> That's an operation that will make really big numbers!<br />
<br />
===Program Example 2===<br />
<br />
'''Find 87 all around 132.'''<br />
<br />
The answer is bound to be a huge number, so we must make a program to solve it.<br />
<br />
We will keep our up_down_arrow function because in the definition of our all_around function we will use it. Then, we will define the all_around function.<br />
<br />
def up_down_arrow(a,b):<br />
return ((a**b) * (b**a))<br />
def all_around(a,b):<br />
return ((a * b * up_down_arrow(a,b)) ** 2)<br />
<br />
We must print all_around(87,132) at the end. Once we do that, and we run our program, we get a super huge number that has over 800 digits!<br />
<br />
===Understanding Functions===<br />
<br />
Every single function has a '''return value'''. If a function does not return anything, the return value is '''null'''. Null is a term used in programming as a placeholder that stands for nothing.<br />
<br />
====Simple Program Example 1====<br />
<br />
'''Define a function that adds 1 to an input.'''<br />
<br />
How will the function know what number to add 1 to? We will input a '''parameter''' for the function to add 1 to.<br />
<br />
def add_one(x):<br />
return x + 1<br />
<br />
In this function, <math>x</math> is the parameter.<br />
<br />
def add_one(x):<br />
return x + 1<br />
print(add_one(2))<br />
<br />
In the print statement, we set <math>x</math> as 2, and the function returns <math>2 + 1 = 3,</math> so the program prints <math>3</math>.<br />
<br />
====Simple Program Example 2====<br />
<br />
'''Define a function that prints out an input.'''<br />
<br />
We will use a parameter again.<br />
<br />
def print_function(x):<br />
print(x)<br />
<br />
Uh oh! We have nothing to return! Therefore, we will return nothing (or null), by just writing return.<br />
<br />
def print_function(x):<br />
print(x)<br />
return<br />
print_function("print_function")<br />
<br />
This code prints out print_function. print_function() is said to be '''called''' in the final line of the code. Again, we set <math>x</math>, our parameter, as "print_function."<br />
== Classes ==<br />
Classes are <br />
<br />
===Defining a class===<br />
We can define a class by doing the following:<br />
<br />
<br />
class Example:<br />
pass<br />
<br />
Usually, classes use CamelCase convention.<br />
We can call a class by doing the following<br />
<br />
===methods===<br />
methods are functions that apply to a class.<br />
<br />
===__init__===<br />
__init__ is where one should define class wide variables. For example:<br />
Class Person:<br />
def __init__(self,first_name,last_name,age):<br />
self.name=first_name+" "+last_name<br />
self.age=age<br />
Now I could use this class like this:<br />
Person("Richard", "Rusczyk", 49)<br />
<br />
===__str__===<br />
===overloading===<br />
overloading means changing a builtin function to do what you want it to do.<br />
<br />
==Flow==<br />
<br />
Flow consists of if statements, elif (else if) statements, and else statements.<br />
<br />
*An if statement checks if a comparison is true.<br />
<br />
*An else statement checks if a comparison is not true. It is used after an if statement (and all elif statements after the if statement) and it shares the same comparison as the if statement.<br />
<br />
*An elif statement checks for two things: if a comparison is true, and if a comparison is not true. It is used right after the if statement.<br />
<br />
===Program Example===<br />
<br />
'''Does the number 10 have the property that when you multiply 10 by 5, you get a two digit number?'''<br />
<br />
This problem is super easy to solve without a program, but let's write a program to solve this anyway. We will use an if statement to check if <math>10\cdot 5</math> is less than 100 and greater than 9.<br />
<br />
if 10*5 > 9:<br />
if 10*5 < 100:<br />
print("Yes")<br />
else:<br />
print("No")<br />
else:<br />
print("No")<br />
<br />
This code means, if 10*5 > 9, then we will check if it is less than 100. If it is not greater than 9, however, we will print No. If it is greater than 9, we check if it is less than 100. If it is, we print Yes. If it isn't we print No.<br />
<br />
These nested if statements can be very confusing. Luckily, there is a faster an easier way to do this.<br />
<br />
if 10*5 > 9 and 10*5 < 100:<br />
print("Yes") <br />
else:<br />
print("No")<br />
<br />
This code checks for the two conditions at the same time. If we run it, we get our answer of Yes.<br />
<br />
==Booleans==<br />
<br />
===Program Example===<br />
<br />
'''Print all two-digit positive integers <math>x</math> such that <math>5x</math> is a two-digit positive integer.'''<br />
<br />
We can create a function with our previous code.<br />
<br />
We will have to slightly modify our function so we can use it in a for loop at the end:<br />
<br />
def check(a):<br />
if a*5 > 9 and a*5 < 100:<br />
return True <br />
else:<br />
return False<br />
<br />
True and False are what are called '''booleans'''. When an if or elif statement receives True, the code inside of the statement happens. When an if or elif statement receives False, the code inside of the statement does not happen. <br />
<br />
We must create a for loop that will iterate through all two digit positive integers. <br />
<br />
def check(a):<br />
if a*5 > 9 and a*5 < 100:<br />
return True <br />
else:<br />
return False<br />
for i in range(10,100):<br />
if check(i):<br />
print(i)<br />
<br />
The final for loop checks if <math>5i</math> is a two digit integer. If it is, the function returns True and the code inside the if statement gets run. If it isn't, the function returns False and the code inside the if statement gets ignored.<br />
<br />
If we run this, we will get the answer.<br />
<br />
All two digit integers from 10 to 19 inclusive work!<br />
<br />
=="Soft Coding" Programs==<br />
<br />
In the next few examples, you will see why hard coding programs is bad. Hard coding programs refers to coding a program that is hard to modify. For example:<br />
<br />
===Program Example 1===<br />
<br />
'''Print all two digit positive integers <math>x</math> such that <math>5x</math> is a three digit positive integer.'''<br />
<br />
We can keep our code and modify some parts of it.<br />
<br />
def check(a, min, max):<br />
if a*5 > min - 1 and a*5 < max + 1:<br />
return True <br />
else:<br />
return False<br />
<br />
def print_check(range_min, range_max, check_min, check_max):<br />
for i in range(range_min, range_max + 1):<br />
if check(i, check_min, check_max):<br />
print(i)<br />
return<br />
<br />
print_check(10, 99, 100, 999)<br />
<br />
Why did we add so many functions?<br />
<br />
Well, if the numbers in a problem change (and the words stay the same), and you need to change a lot of numbers in your program, your program is considered '''hard-coded'''. We want our programs to be as '''soft-coded''' as possible. In our new program, we only need to change 4 numbers (in the print_check() statement) if the numbers in the problem change. Therefore, our program is relatively soft-coded. There are still ways to soft-code this program even more, though.<br />
<br />
If we run our program, we get our answer.<br />
<br />
All numbers from 20 to 99 work!<br />
<br />
===Program Example 2===<br />
<br />
'''Print all three digit positive integers <math>x</math> such that <math>5x</math> is a three digit positive integer.'''<br />
<br />
We can just change the print_check line at the end to<br />
<br />
print_check(100, 999, 100, 999)<br />
<br />
and our program will be ready to be run.<br />
<br />
All numbers from 100 to 199 work.<br />
<br />
===Program Example 3===<br />
<br />
'''Print all two digit positive integers <math>x</math> such that <math>3x</math> is a three digit positive integer.'''<br />
<br />
Uh oh. Only changing the print_check line won't work. We will need to change our functions!<br />
<br />
def check(a, min, max, factor):<br />
if a*factor > min - 1 and a*factor < max + 1:<br />
return True <br />
else:<br />
return False<br />
<br />
def print_check(range_min, range_max, check_min, check_max, check_factor):<br />
for i in range(range_min, range_max + 1):<br />
if check(i, check_min, check_max, check_factor):<br />
print(i)<br />
return<br />
<br />
print_check(10, 99, 100, 999, 3)<br />
<br />
In this step, we added a parameter in both functions. We also soft-coded our program even more! Hooray!<br />
<br />
All integers from 34 to 99 work.<br />
<br />
===Program Example 4===<br />
<br />
'''Print all two digit positive integers <math>x</math> such that <math>12x</math> is a positive integer from 500 to 900.'''<br />
<br />
This problem may look a bit different from the other ones, but it really is the same thing, except that the factor is 12 and check_min and check_max are 500 and 900, respectively.<br />
<br />
Once we change the final print_check() line to satisfy our needs, we can run our program.<br />
<br />
All numbers from 42 to 75 work!<br />
<br />
Congrats! You have written your first programs above 10 lines of code!<br />
<br />
==Random==<br />
<br />
There is a package in Python that allows the use of random numbers.<br />
<br />
===Program Example 1===<br />
<br />
'''Generate a random number from 1 to 6.'''<br />
<br />
Easy peasy. We will just generate a random number from 1 to 6 with the package like this:<br />
<br />
import random<br />
print(random.randint(1,6))<br />
<br />
As you can see, when you run this program, you get a random integer from 1 to 6.<br />
<br />
===Program Example 2===<br />
<br />
'''Simulate the rolling of 1000 dice. Now, count the number of times you roll 6. Print that number out.'''<br />
<br />
We can create a function that returns a random number from 1 to 6. Then, we can make a for loop that rolls the dice 1000 times and check if it is a 6.<br />
<br />
import random<br />
count = 0<br />
<br />
def roll():<br />
return random.randint(1,6)<br />
<br />
for i in range(1, 1001):<br />
if roll() == 6:<br />
count += 1<br />
<br />
print(count)<br />
<br />
If we run this, we will get a number around 170.<br />
<br />
===Program Example 3===<br />
<br />
'''Simulate the rolling of 10,000 dice. Now, count the amount of times you roll 3. Print that amount out.'''<br />
<br />
We can keep our roll function and our code inside the for loop, but we need to change our for loop statement.<br />
<br />
We can actually soft-code our program more. Let's turn the whole for loop into a function!<br />
<br />
import random<br />
<br />
def roll():<br />
return random.randint(1,6)<br />
<br />
def count(amount):<br />
count_ = 0<br />
<br />
for i in range(1, amount+1):<br />
if roll() == 3:<br />
count_ += 1<br />
return count_<br />
<br />
print(count(10000))<br />
<br />
If we run this code, it works.<br />
<br />
===Program Example 4===<br />
<br />
'''One of my friends loves rolling dice. He is going to roll 1 die tomorrow, 2 dice two days from now, 3 dice three days from now, and so on so that he rolls <math>a</math> dice <math>a</math> days from now. He gets tired rolling dice after rolling dice for 365 days (so the last day he rolls 365 dice). In Python, simulate this. How many times does he roll 3 after 365 days of rolling dice?'''<br />
<br />
We can use a for loop that calls a function multiple times.<br />
<br />
import random<br />
<br />
def roll():<br />
return random.randint(1,6)<br />
<br />
def count(amount):<br />
count_ = 0<br />
for i in range(1, amount+1):<br />
if roll() == 3:<br />
count_ += 1<br />
return count_<br />
<br />
total = 0<br />
<br />
for i in range(1, 366):<br />
total += count(i)<br />
<br />
print(total)<br />
<br />
This is a really long program, but the whole program should make sense if you look at it for a while. We defined our count function in the previous example, and now we are using it with a for loop and a running total. <br />
<br />
You should get a number around 11,000 when you run it. Wow, lots of 3's!<br />
<br />
===Program Example 5===<br />
<br />
'''20 of my friends love rolling dice. They are all going to roll 1 die each tomorrow, 2 dice each two days from now, 3 dice each three days from now, and so on so that they roll <math>a</math> dice each <math>a</math> days from now. But, one of my friends gets tired very quickly and he only rolls dice for 1 day and stops. Another friend only will roll dice for 2 days, and another will roll dice for three days only, and so on up to the fact that my last friend will roll dice for 20 days. In Python, simulate this. How many times does someone roll 3 after everything?'''<br />
<br />
We will have to make our for loop into a function again.<br />
<br />
import random<br />
<br />
def roll():<br />
return random.randint(1,6)<br />
<br />
def count(amount):<br />
count_ = 0<br />
for i in range(1, amount+1):<br />
if roll() == 3:<br />
count_ += 1<br />
return count_<br />
<br />
def count2(amount)<br />
total = 0<br />
for i in range(1, amount + 1):<br />
total += count(i)<br />
return total<br />
<br />
def count3(amount)<br />
total = 0<br />
for i in range(1, amount + 1):<br />
total += count2(i)<br />
return total<br />
<br />
print(count3(20))<br />
<br />
(Our program is so long!)<br />
<br />
I also made a new function just in case we needed to turn that into a function later.<br />
<br />
'''Make sure''' you read the code carefully and you fully understand it. If you don't understand every single line of code, then you will get confused later on in this article.<br />
<br />
When you run this program, you might be surprised that the answer isn't so big.<br />
<br />
===Program Example 6===<br />
<br />
'''365 of my friends love rolling dice. They are all going to roll 1 die each tomorrow, 2 dice each two days from now, 3 dice each three days from now, and so on so that they roll <math>a</math> dice each <math>a</math> days from now. But, one of my friends gets tired very quickly and he only rolls dice for 1 day and stops. Another friend only will roll dice for 2 days, and another will roll dice for three days only, and so on up to the fact that my last friend will roll dice for 365 days. In Python, simulate this. How many times does someone roll 3 after everything?'''<br />
<br />
Because we soft-coded our program so much, all we have to do is change the last line so the parameter of count3() is 365.<br />
<br />
If we run it...we get a big answer, as expected. It also takes quite a while!<br />
<br />
You may not have realized that we soft-coded our program at all, but the whole point of functions is to soft-code programs!<br />
<br />
Congrats on writing a program that is around 25 lines long!<br />
<br />
==Very Basic Datatypes==<br />
<br />
An integer is a basic datatype in Python. Basically, all variables with the datatype of '''int''' is an integer.<br />
<br />
A string is another basic datatype, and it is a string of characters enclosed by quotes.<br />
<br />
===Why Are Datatypes So Important?===<br />
<br />
Let's say we wanted to make a program that would add 2 and 3. Some bogus code would be:<br />
<br />
x="2"<br />
y="3"<br />
print(x+y)<br />
<br />
If you ran this code, you would get 23. Why is that?<br />
<br />
Well, here, x and y are strings. When you perform the addition operator to strings in Python, it concatenates the strings, giving 23.<br />
<br />
The real code is:<br />
<br />
x=2<br />
y=3<br />
print(x+y)<br />
<br />
If you run this, you will get <math>5</math>, which is correct.<br />
<br />
Here's another reason datatypes are important. Now, we will introduce the datatype called the '''floating point number''', or '''float'''. A floating-point number is a number with a decimal point.<br />
<br />
Let's go back to the IDLE. Type "0.1*10". The result is 1.0. Notice the decimal point.<br />
<br />
Let's type something different. Type <math>0.1+0.1+0.1+0.1+0.1+0.1+0.1+0.1+0.1+0.1.</math><br />
<br />
'''WHAT!?'''<br />
<br />
You would have expected the answer to be 1, but it isn't 1. What happened?<br />
<br />
'''Float approximation''' happened. Most (almost all) programming languages have a bad float approximation. That means that 1.0 can turn into 0.99999999999999 and 0.5 can turn into 0.49999999999999999993. That only happens with floats, so we should try to use floats as sparingly as possible.<br />
<br />
==Lists==<br />
<br />
A for loop iterates over a '''list'''. A list is a bunch of objects stored in one variable. (Hey! A list is a datatype!) For loops are highly related to lists.<br />
<br />
Let's say we wanted to make a program to print all the items in a list.<br />
<br />
We will first create the list, using the code:<br />
<br />
myList = [1,4,6,8]<br />
<br />
This is a list with four items: 1, 4, 6, and 8.<br />
<br />
We must now print all elements of it with a for loop:<br />
<br />
myList = [1,4,6,8]<br />
for i in myList:<br />
print(i)<br />
<br />
When we run this program, we get the numbers 1, 4, 6, and 8, as expected.<br />
<br />
===Accessing Values===<br />
<br />
Let's say we wanted to print out the second item in a list. We will use '''indexes'''.<br />
<br />
The index of the first item in a list is always 0. The index of the second is 1. The index of the <math>n</math>th is <math>n-1.</math><br />
<br />
To print out the second item, we will use an index of 1, like this:<br />
<br />
myList = [1,4,6,8]<br />
print(myList[1])<br />
<br />
Notice that the index is inside of the square brackets.<br />
<br />
===Adding Values===<br />
<br />
We can use the list.append() function to add an object to the end of a list.<br />
<br />
myList.append(10)<br />
<br />
will add 10 to the list, which makes myList = [1,4,6,8,10].<br />
<br />
===Removing Items From Lists===<br />
<br />
We can use the list.remove() function to remove a specific item in a list.<br />
<br />
For example, consider this code.<br />
<br />
myList = [1,2,3]<br />
myList.remove(3)<br />
<br />
This code will make myList turn into [1,2]. The element, 3, gets removed.<br />
<br />
===len(list)===<br />
<br />
The len(list) function returns the length of a list.<br />
<br />
This code will print 3.<br />
<br />
myList = [1,2,3]<br />
print(len(myList))<br />
<br />
The length of myList is 3, so Python prints 3.<br />
<br />
===All Kinds Of Lists===<br />
<br />
Lists don't have to be only integers!<br />
<br />
myList = [1,"Hi","Hello world", 3.5, 3.14159265358979323]<br />
<br />
If fact, there can be lists inside of lists!<br />
<br />
myList = [[1,2,3], [3,4,5], [5,6,"Hello world"], "BOB", 3.1415926]<br />
<br />
Even this!<br />
<br />
myList = [[1, [1, [1,2,3],3],3], [[[3,["Hello world", 4],5],4,5],4,5], [5,6,7,[1,[1,2,3],3],"Hello world"], "BOB", 3.1415926, True]<br />
<br />
If you look at that list carefully, you will find lists inside of lists inside of lists inside of lists! And, a boolean at the end!<br />
<br />
Like variables, you can have as many lists in a program as you want (a list is a variable)!<br />
<br />
myList = [1,2,3,4]<br />
yourList = [5,6,7,8]<br />
hisList = [9,10,11,12]<br />
herList = [13,14,15,16]<br />
theirList = [17,18,19,20]<br />
ourList = [21,22,23,24]<br />
listsOfLists = [[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16],[17,18,19,20],[21,22,23,24]]<br />
<br />
===Splitting Lists===<br />
Split Operator Basics:<br />
genericList[where to start:where to end:what size steps to take]<br />
The value where to start is inclusive, and denotes the index where your split list begins. It has a default value of 0.<br />
The value where to end is exclusive, and denotes the index where your split list ends. It has a default value of len(genericList).<br />
The value what size steps denotes the size of the steps your split takes(more on that later). It has a default value of 1.<br />
Say you want to split a list and only return certain indices, for example if you wanted to split a list called data and put the first two elements into a list called head and the last two into a list called tail, you would split like this:<br />
data = [1, 3, 4, 23.5, 40, 55]<br />
head = data[:2]<br />
tail = data[-2:] # negative list indices represent the end of a list, so -1 is the last element and -2 is the second-to-last<br />
Step Size:<br />
We will practice writing a few functions that select every other element and will reverse in a list using step size.<br />
A step size of two means skip every other list index, so we can write our first function.<br />
def selectEveryOtherElement(list):<br />
return list[::2]<br />
But which step size will get us our desired reversed list. We could start at the end of the list and iterate backwards, but how would we do that...<br />
Negative Step Size:<br />
A step size that is negative means skip a certain amount of elements, but backwards. If we were to start at 0, with a step size of -1, we would be able to iterate backwards over the list!<br />
def reverse(list):<br />
return list[::-1]<br />
Splitting lists with ratios:<br />
What if we wanted to be able to split a list based upon a ratio. For example, the common 80:20 train to test ratio in machine learning? Here is how you would do it<br />
def eighty-twenty(list):<br />
train = list[:int(len(list) * (4 / 5))] # We must include the int() method to convert to an integer if len(list) % 5 != 0<br />
test = list[int(len(list) * 4 / 5)]<br />
return [train, test] # We then return a list with the train and test lists inside<br />
<br />
==Dictionaries==<br />
<br />
A dictionary (a type of datatype) is a bunch of keys and values. There is a major difference between dictionaries and lists. Lists are ordered; dictionaries are not.<br />
<br />
Here is the '''syntax''' of creating a dictionary:<br />
<br />
myDictionary = {1:"one",2:"two"}<br />
<br />
This dictionary has two key/value pairs. Notice it is surrounded in curly braces. The keys are 1 and 2; the values are "one" and "two."<br />
<br />
How is this useful? Let's make a simple program to test it out.<br />
<br />
myDictionary = {1:"one",2:"two"}<br />
print(myDictionary[1])<br />
print(myDictionary[2])<br />
<br />
===Accessing Values===<br />
<br />
To access a value in a dictionary, you put in the key.<br />
<br />
myDictionary[1]<br />
<br />
returns one, because 1 is the key to "one."<br />
<br />
===Adding New Values===<br />
<br />
To overwrite a value, we do this.<br />
<br />
myDictionary[1] = "won"<br />
<br />
The value to the key 1 is now "won."<br />
<br />
To add a value, we do the same thing!<br />
<br />
myDictionary[3] = "three"<br />
<br />
This adds a key 3 with a value of "three."<br />
<br />
==Misc Concepts==<br />
<br />
This section will talk about some concepts that we haven't learned yet.<br />
<br />
====Concatenating Strings====<br />
<br />
Concatenating strings is putting them together. For example, "one" concatenated with "two" gives "onetwo."<br />
<br />
The following string,<br />
<br />
"Hello, " + person2 + "! How are you?"<br />
<br />
depends on what person2 was. If person2 was Bob, the string would be:<br />
<br />
"Hello, Bob! How are you?"<br />
<br />
It fits together perfectly!<br />
<br />
You cannot concatenate strings with integers. For example, doing this:<br />
<br />
"2" + 3<br />
<br />
will not work. Instead, to get an answer of "23", you must do this:<br />
<br />
"2" + str(3)<br />
<br />
That turns 3 into a string so it is "3", and the result will be "23".<br />
<br />
There is a faster way to do this:<br />
<br />
name="aops"<br />
"hello %s" % name<br />
<br />
or even faster<br />
<br />
wiki_name="AOPS WIKI"<br />
"This is the {0}".format(wiki_name)<br />
====Line Breaks====<br />
<br />
We can use multiple line breaks to make our code more organized. There are some places that you cannot line break. For example, this code will produce an error:<br />
<br />
myList =<br />
[1,2,3]<br />
<br />
This code does not work.<br />
<br />
This code '''does work''':<br />
<br />
myList = [<br />
1,2,3]<br />
<br />
It is accepted when you break a line right after the [. It is also accepted right after a comma. (And right before the ending ].)<br />
<br />
myList = [<br />
1,<br />
2,<br />
3<br />
]<br />
<br />
==Challenge Program==<br />
<br />
In this section, we will attempt the hardest program so far in this article.<br />
<br />
'''Make a conversation generator that will generate random conversations between different people.'''<br />
<br />
First, we will generate the people. We can use a list and generate two random numbers.<br />
<br />
import random<br />
<br />
peopleNames = [<br />
"Bob",<br />
"Kyle",<br />
"James",<br />
"Richard",<br />
"Zachary",<br />
"Olivia",<br />
"Jonathan",<br />
"Will",<br />
"Bobby",<br />
"Kevin"<br />
]<br />
person1 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
peopleNames.remove(person1)<br />
person2 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
<br />
(I made it more organized by separating the long lines of code into multiple lines. It only works when you have a line break right after each item in the list.)<br />
<br />
Here, we use the remove() function to remove person1 from the list to make sure we don't use the same name twice. <br />
<br />
We also used the len() function to find the length of the list (soft-coding!)<br />
<br />
Now, we need to create a list of possible values for the first thing that person1 says (person1 will always be the first one to talk). <br />
<br />
Then, we will print it out.<br />
<br />
import random<br />
<br />
peopleNames = [<br />
"Bob",<br />
"Kyle",<br />
"James",<br />
"Richard",<br />
"Zachary",<br />
"Olivia",<br />
"Jonathan",<br />
"Will",<br />
"Bobby",<br />
"Kevin"<br />
]<br />
person1 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
peopleNames.remove(person1)<br />
person2 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
<br />
first = [<br />
"Hi!",<br />
"Hello!",<br />
"Good morning!",<br />
"Hello, " + person2 + "!",<br />
"Hi.",<br />
"Hi, " + person2 + "!"<br />
]<br />
print(person1 + ": " + first[random.randint(0, (len(first) - 1))])<br />
<br />
If we test out this program, we can confirm that this part indeed does work. This program is already getting long! Now, we will use the same method and create the second message.<br />
<br />
import random<br />
<br />
peopleNames = [<br />
"Bob",<br />
"Kyle",<br />
"James",<br />
"Richard",<br />
"Zachary",<br />
"Olivia",<br />
"Jonathan",<br />
"Will",<br />
"Bobby",<br />
"Kevin"<br />
]<br />
person1 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
peopleNames.remove(person1)<br />
person2 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
<br />
first = [<br />
"Hi!",<br />
"Hello!",<br />
"Good morning!",<br />
"Hello, " + person2 + "!",<br />
"Hi.",<br />
"Hi, " + person2 + "!"<br />
]<br />
print(person1 + ": " + first[random.randint(0, (len(first) - 1))])<br />
<br />
second = [<br />
"Hi! How are you today?",<br />
"Hello! How are you?",<br />
"Good morning! How are you today?",<br />
"Hello, " + person1 + "! How are you?",<br />
"Hi. How are you?",<br />
"Hi, " + person1 + "! How are you today?"<br />
]<br />
print(person2 + ": " + second[random.randint(0, (len(second) - 1))])<br />
<br />
We will repeat this for the rest of the conversation:<br />
<br />
import random<br />
<br />
peopleNames = [<br />
"Bob",<br />
"Kyle",<br />
"James",<br />
"Richard",<br />
"Zachary",<br />
"Olivia",<br />
"Jonathan",<br />
"Will", <br />
"Bobby",<br />
"Kevin"<br />
]<br />
person1 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
peopleNames.remove(person1)<br />
person2 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
<br />
first = [<br />
"Hi!",<br />
"Hello!",<br />
"Good morning!",<br />
"Hello, " + person2 + "!",<br />
"Hi.",<br />
"Hi, " + person2 + "!"<br />
]<br />
print(person1 + ": " + first[random.randint(0, (len(first) - 1))])<br />
<br />
second = [<br />
"Hi! How are you today?",<br />
"Hello! How are you?",<br />
"Good morning! How are you today?",<br />
"Hello, " + person1 + "! How are you?",<br />
"Hi. How are you?",<br />
"Hi, " + person1 + "! How are you today?"<br />
]<br />
print(person2 + ": " + second[random.randint(0, (len(second) - 1))])<br />
<br />
third = [<br />
"I'm feeling awesome! And you?",<br />
"I'm feeling alright! How are you?",<br />
"I'm good, thank you. How are you feeling?",<br />
"I'm fine!" ,<br />
"How are you today?"<br />
]<br />
print(person1 + ": " + third[random.randint(0, (len(third) - 1))])<br />
<br />
fourth = [<br />
"I'm feeling great!",<br />
"I'm awesome!",<br />
"Thanks for asking! I am feeling good today!",<br />
"I'm feeling awesome today! Yippee!"<br />
] <br />
print(person2 + ": " + fourth[random.randint(0, (len(fourth) - 1))])<br />
<br />
fifth = [<br />
"It's so nice out today!",<br />
"Today is such a cloudy day.",<br />
"I hate it when it is so cloudy outside!",<br />
"It's partly cloudy today!"<br />
]<br />
print(person1 + ": " + fifth[random.randint(0, (len(fifth) - 1))])<br />
<br />
sixth = [<br />
"I know, right?",<br />
"I know.",<br />
"Yeah!",<br />
"True."<br />
]<br />
print(person2 + ": " + sixth[random.randint(0, (len(sixth) - 1))])<br />
<br />
seventh = [<br />
"Sorry, I need to leave. Bye!",<br />
"I gotta go. Bye!",<br />
"Sorry, I don't have time to stay and chat. I've got to go somewhere. Bye!"<br />
]<br />
print(person1 + ": " + seventh[random.randint(0, (len(seventh) - 1))])<br />
<br />
eighth = [<br />
"Bye!",<br />
"Good-bye!",<br />
"Bye, " + person1 + "."<br />
]<br />
print(person2 + ": " + eighth[random.randint(0, (len(eighth) - 1))])<br />
<br />
Whew! So long!<br />
<br />
Once we run our program. It works! This program really wasn't that hard.<br />
<br />
Congrats! You've made it so far!</div>Anstarhttps://artofproblemsolving.com/wiki/index.php?title=Basic_Programming_With_Python&diff=134877Basic Programming With Python2020-10-10T19:32:42Z<p>Anstar: /* Defining a class */</p>
<hr />
<div>'''Important: It is extremely recommended that you read [[Getting Started With Python Programming]] before reading this unless you already know some programming knowledge.'''<br />
<br />
(Note: This is a really long article. To learn the most from this article, you need to read everything in order and skip nothing, unless you are '''absolutely absolutely sure that that content is way too easy for you.''')<br />
<br />
This article will talk about some basic Python programming. If you don't even know how to install Python, look [[Getting Started With Python Programming|here]].<br />
<br />
Note that this article has lots of program examples. It is recommended (but not required) to try these on your own before looking at the solutions.<br />
<br />
==Loops==<br />
<br />
There are two different kinds of loops in Python: the for loop and the while loop.<br />
<br />
===The For Loop===<br />
<br />
The for loop iterates over a list, or an array, of objects. You have probably seen this code before:<br />
<br />
[[File:Capture.PNG|200px]]<br />
<br />
This for loop iterates over the list of integers from 1 to 51, excluding the 51 and including the 1. That means it is a list from 1 to 50, inclusive. On every iteration, Python will print the number that the loop is iterating through. <br />
<br />
For example, in the first iteration, i = 1, so Python prints 1.<br />
<br />
In the second iteration, i = 2, so Python prints 2.<br />
<br />
This continues so on until the number, 50, is reached. Therefore, the last number Python will print out is 50.<br />
<br />
====Program Example====<br />
<br />
'''Find <math>\sum_{n=1}^{50} 2^{n}.</math>'''<br />
<br />
To do this task, we must create a for loop and loop over the integers from 1 to 50 inclusive:<br />
<br />
for i in range(1,51):<br />
<br />
Now what? We must keep a running total and increase it by <math>2^i</math> every time:<br />
<br />
total = 0<br />
for i in range(1,51):<br />
total += 2**i<br />
<br />
We must not forget to print the total at the end!<br />
<br />
total = 0<br />
for i in range(1,51):<br />
total += 2**i<br />
print(total)<br />
<br />
You must exit out of the for loop one you reach the print(total) line by pressing backspace.<br />
<br />
Once you run your program, you should get an answer of <math>\boxed{2,251,799,813,685,246.}</math><br />
<br />
===The While Loop===<br />
<br />
While loops don't loop over a list. They loop over and over and over...'''until'''...a condition becomes false.<br />
<br />
i = 3<br />
total = 0<br />
while i < 1000:<br />
total += i<br />
i += 3<br />
print(total)<br />
<br />
In this code, the while loop loops 333 times, until <math>i</math> becomes greater than or equal to 1000.<br />
<br />
====Program Example====<br />
<br />
'''Find <math>\sum_{n=1}^{50} 2^n</math> using a while loop.'''<br />
<br />
We must create a while loop that will iterate until n is greater than <math>50.</math><br />
<br />
n = 1<br />
total = 0<br />
while n <= 50:<br />
total += 2**n<br />
n += 1<br />
print(total)<br />
<br />
We must not forget to include the n += 1 line at the end of the while loop! <br />
<br />
If we run this, we will get the same answer as last time, <math>2,251,799,813,685,246.</math><br />
<br />
==Functions==<br />
<br />
In this section, we will define new operations and do arithmetic with them in Python.<br />
<br />
===The New Operation===<br />
Let's say that you defined a new binary operation, the <math>\uparrow \downarrow.</math> You want it to be so <math>a \uparrow \downarrow b = a^{b}b^{a}.</math> Therefore, <math>1\uparrow \downarrow 2 = 1^{2}2^{1}=1\cdot 2= 2,</math> and <math>2\uparrow \downarrow 3 = 2^33^2 = 8\cdot 9 = 72.</math> Let's call this operation an '''up down arrow.'''<br />
<br />
===Program Example 1===<br />
<br />
'''Find <math>[2 \uparrow \downarrow (1 \uparrow \downarrow 2)] \uparrow \downarrow 2.</math>'''<br />
<br />
We know this will be a big number, so we should write a program to do it! We certainly don't want to do the exponentiation and multiplication every time we use the operation in our program, and that's where functions come in! Functions can take in parameters (<math>a</math> and <math>b</math>) and return a result depending on the parameters.<br />
<br />
def up_down_arrow(a,b): <br />
return ((a**b) * (b**a))<br />
<br />
Above is the code to define our function. We need to print the final result at the end, so we must put a print statement at the end.<br />
<br />
def up_down_arrow(a,b): <br />
return ((a**b) * (b**a))<br />
print(up_down_arrow(up_down_arrow(2,up_down_arrow(1,2)),2)<br />
<br />
All those nested up_down_arrow's might be confusing at first, but it really isn't that confusing.<br />
If you run your program, you should get your answer: <math>16,777,216.</math> <br />
<br />
You might be surprised that the answer is so big. If you actually start calculating the real answer without a program, you will really quickly find that the final result is <math>16 \uparrow \downarrow 2,</math> which does turn out to be 16,777,216 if you use a calculator.<br />
<br />
Let's make another operation!<br />
<br />
We will define the operation <math>\uparrow \downarrow \leftarrow \rightarrow</math> to be called '''all around.''' <math>a \uparrow \downarrow \leftarrow \rightarrow b = (ab(a \uparrow \downarrow b))^2.</math> That's an operation that will make really big numbers!<br />
<br />
===Program Example 2===<br />
<br />
'''Find 87 all around 132.'''<br />
<br />
The answer is bound to be a huge number, so we must make a program to solve it.<br />
<br />
We will keep our up_down_arrow function because in the definition of our all_around function we will use it. Then, we will define the all_around function.<br />
<br />
def up_down_arrow(a,b):<br />
return ((a**b) * (b**a))<br />
def all_around(a,b):<br />
return ((a * b * up_down_arrow(a,b)) ** 2)<br />
<br />
We must print all_around(87,132) at the end. Once we do that, and we run our program, we get a super huge number that has over 800 digits!<br />
<br />
===Understanding Functions===<br />
<br />
Every single function has a '''return value'''. If a function does not return anything, the return value is '''null'''. Null is a term used in programming as a placeholder that stands for nothing.<br />
<br />
====Simple Program Example 1====<br />
<br />
'''Define a function that adds 1 to an input.'''<br />
<br />
How will the function know what number to add 1 to? We will input a '''parameter''' for the function to add 1 to.<br />
<br />
def add_one(x):<br />
return x + 1<br />
<br />
In this function, <math>x</math> is the parameter.<br />
<br />
def add_one(x):<br />
return x + 1<br />
print(add_one(2))<br />
<br />
In the print statement, we set <math>x</math> as 2, and the function returns <math>2 + 1 = 3,</math> so the program prints <math>3</math>.<br />
<br />
====Simple Program Example 2====<br />
<br />
'''Define a function that prints out an input.'''<br />
<br />
We will use a parameter again.<br />
<br />
def print_function(x):<br />
print(x)<br />
<br />
Uh oh! We have nothing to return! Therefore, we will return nothing (or null), by just writing return.<br />
<br />
def print_function(x):<br />
print(x)<br />
return<br />
print_function("print_function")<br />
<br />
This code prints out print_function. print_function() is said to be '''called''' in the final line of the code. Again, we set <math>x</math>, our parameter, as "print_function."<br />
== Classes ==<br />
Classes are <br />
<br />
===Defining a class===<br />
We can define a class by doing the following:<br />
<br />
<br />
class Example:<br />
pass<br />
<br />
Usually, classes use CamelCase convention.<br />
We can call a class by doing the following<br />
<br />
===methods===<br />
methods are functions that apply to a class.<br />
<br />
===__init__===<br />
===__str__===<br />
===overloading===<br />
overloading means changing a builtin function to do what you want it to do.<br />
<br />
==Flow==<br />
<br />
Flow consists of if statements, elif (else if) statements, and else statements.<br />
<br />
*An if statement checks if a comparison is true.<br />
<br />
*An else statement checks if a comparison is not true. It is used after an if statement (and all elif statements after the if statement) and it shares the same comparison as the if statement.<br />
<br />
*An elif statement checks for two things: if a comparison is true, and if a comparison is not true. It is used right after the if statement.<br />
<br />
===Program Example===<br />
<br />
'''Does the number 10 have the property that when you multiply 10 by 5, you get a two digit number?'''<br />
<br />
This problem is super easy to solve without a program, but let's write a program to solve this anyway. We will use an if statement to check if <math>10\cdot 5</math> is less than 100 and greater than 9.<br />
<br />
if 10*5 > 9:<br />
if 10*5 < 100:<br />
print("Yes")<br />
else:<br />
print("No")<br />
else:<br />
print("No")<br />
<br />
This code means, if 10*5 > 9, then we will check if it is less than 100. If it is not greater than 9, however, we will print No. If it is greater than 9, we check if it is less than 100. If it is, we print Yes. If it isn't we print No.<br />
<br />
These nested if statements can be very confusing. Luckily, there is a faster an easier way to do this.<br />
<br />
if 10*5 > 9 and 10*5 < 100:<br />
print("Yes") <br />
else:<br />
print("No")<br />
<br />
This code checks for the two conditions at the same time. If we run it, we get our answer of Yes.<br />
<br />
==Booleans==<br />
<br />
===Program Example===<br />
<br />
'''Print all two-digit positive integers <math>x</math> such that <math>5x</math> is a two-digit positive integer.'''<br />
<br />
We can create a function with our previous code.<br />
<br />
We will have to slightly modify our function so we can use it in a for loop at the end:<br />
<br />
def check(a):<br />
if a*5 > 9 and a*5 < 100:<br />
return True <br />
else:<br />
return False<br />
<br />
True and False are what are called '''booleans'''. When an if or elif statement receives True, the code inside of the statement happens. When an if or elif statement receives False, the code inside of the statement does not happen. <br />
<br />
We must create a for loop that will iterate through all two digit positive integers. <br />
<br />
def check(a):<br />
if a*5 > 9 and a*5 < 100:<br />
return True <br />
else:<br />
return False<br />
for i in range(10,100):<br />
if check(i):<br />
print(i)<br />
<br />
The final for loop checks if <math>5i</math> is a two digit integer. If it is, the function returns True and the code inside the if statement gets run. If it isn't, the function returns False and the code inside the if statement gets ignored.<br />
<br />
If we run this, we will get the answer.<br />
<br />
All two digit integers from 10 to 19 inclusive work!<br />
<br />
=="Soft Coding" Programs==<br />
<br />
In the next few examples, you will see why hard coding programs is bad. Hard coding programs refers to coding a program that is hard to modify. For example:<br />
<br />
===Program Example 1===<br />
<br />
'''Print all two digit positive integers <math>x</math> such that <math>5x</math> is a three digit positive integer.'''<br />
<br />
We can keep our code and modify some parts of it.<br />
<br />
def check(a, min, max):<br />
if a*5 > min - 1 and a*5 < max + 1:<br />
return True <br />
else:<br />
return False<br />
<br />
def print_check(range_min, range_max, check_min, check_max):<br />
for i in range(range_min, range_max + 1):<br />
if check(i, check_min, check_max):<br />
print(i)<br />
return<br />
<br />
print_check(10, 99, 100, 999)<br />
<br />
Why did we add so many functions?<br />
<br />
Well, if the numbers in a problem change (and the words stay the same), and you need to change a lot of numbers in your program, your program is considered '''hard-coded'''. We want our programs to be as '''soft-coded''' as possible. In our new program, we only need to change 4 numbers (in the print_check() statement) if the numbers in the problem change. Therefore, our program is relatively soft-coded. There are still ways to soft-code this program even more, though.<br />
<br />
If we run our program, we get our answer.<br />
<br />
All numbers from 20 to 99 work!<br />
<br />
===Program Example 2===<br />
<br />
'''Print all three digit positive integers <math>x</math> such that <math>5x</math> is a three digit positive integer.'''<br />
<br />
We can just change the print_check line at the end to<br />
<br />
print_check(100, 999, 100, 999)<br />
<br />
and our program will be ready to be run.<br />
<br />
All numbers from 100 to 199 work.<br />
<br />
===Program Example 3===<br />
<br />
'''Print all two digit positive integers <math>x</math> such that <math>3x</math> is a three digit positive integer.'''<br />
<br />
Uh oh. Only changing the print_check line won't work. We will need to change our functions!<br />
<br />
def check(a, min, max, factor):<br />
if a*factor > min - 1 and a*factor < max + 1:<br />
return True <br />
else:<br />
return False<br />
<br />
def print_check(range_min, range_max, check_min, check_max, check_factor):<br />
for i in range(range_min, range_max + 1):<br />
if check(i, check_min, check_max, check_factor):<br />
print(i)<br />
return<br />
<br />
print_check(10, 99, 100, 999, 3)<br />
<br />
In this step, we added a parameter in both functions. We also soft-coded our program even more! Hooray!<br />
<br />
All integers from 34 to 99 work.<br />
<br />
===Program Example 4===<br />
<br />
'''Print all two digit positive integers <math>x</math> such that <math>12x</math> is a positive integer from 500 to 900.'''<br />
<br />
This problem may look a bit different from the other ones, but it really is the same thing, except that the factor is 12 and check_min and check_max are 500 and 900, respectively.<br />
<br />
Once we change the final print_check() line to satisfy our needs, we can run our program.<br />
<br />
All numbers from 42 to 75 work!<br />
<br />
Congrats! You have written your first programs above 10 lines of code!<br />
<br />
==Random==<br />
<br />
There is a package in Python that allows the use of random numbers.<br />
<br />
===Program Example 1===<br />
<br />
'''Generate a random number from 1 to 6.'''<br />
<br />
Easy peasy. We will just generate a random number from 1 to 6 with the package like this:<br />
<br />
import random<br />
print(random.randint(1,6))<br />
<br />
As you can see, when you run this program, you get a random integer from 1 to 6.<br />
<br />
===Program Example 2===<br />
<br />
'''Simulate the rolling of 1000 dice. Now, count the number of times you roll 6. Print that number out.'''<br />
<br />
We can create a function that returns a random number from 1 to 6. Then, we can make a for loop that rolls the dice 1000 times and check if it is a 6.<br />
<br />
import random<br />
count = 0<br />
<br />
def roll():<br />
return random.randint(1,6)<br />
<br />
for i in range(1, 1001):<br />
if roll() == 6:<br />
count += 1<br />
<br />
print(count)<br />
<br />
If we run this, we will get a number around 170.<br />
<br />
===Program Example 3===<br />
<br />
'''Simulate the rolling of 10,000 dice. Now, count the amount of times you roll 3. Print that amount out.'''<br />
<br />
We can keep our roll function and our code inside the for loop, but we need to change our for loop statement.<br />
<br />
We can actually soft-code our program more. Let's turn the whole for loop into a function!<br />
<br />
import random<br />
<br />
def roll():<br />
return random.randint(1,6)<br />
<br />
def count(amount):<br />
count_ = 0<br />
<br />
for i in range(1, amount+1):<br />
if roll() == 3:<br />
count_ += 1<br />
return count_<br />
<br />
print(count(10000))<br />
<br />
If we run this code, it works.<br />
<br />
===Program Example 4===<br />
<br />
'''One of my friends loves rolling dice. He is going to roll 1 die tomorrow, 2 dice two days from now, 3 dice three days from now, and so on so that he rolls <math>a</math> dice <math>a</math> days from now. He gets tired rolling dice after rolling dice for 365 days (so the last day he rolls 365 dice). In Python, simulate this. How many times does he roll 3 after 365 days of rolling dice?'''<br />
<br />
We can use a for loop that calls a function multiple times.<br />
<br />
import random<br />
<br />
def roll():<br />
return random.randint(1,6)<br />
<br />
def count(amount):<br />
count_ = 0<br />
for i in range(1, amount+1):<br />
if roll() == 3:<br />
count_ += 1<br />
return count_<br />
<br />
total = 0<br />
<br />
for i in range(1, 366):<br />
total += count(i)<br />
<br />
print(total)<br />
<br />
This is a really long program, but the whole program should make sense if you look at it for a while. We defined our count function in the previous example, and now we are using it with a for loop and a running total. <br />
<br />
You should get a number around 11,000 when you run it. Wow, lots of 3's!<br />
<br />
===Program Example 5===<br />
<br />
'''20 of my friends love rolling dice. They are all going to roll 1 die each tomorrow, 2 dice each two days from now, 3 dice each three days from now, and so on so that they roll <math>a</math> dice each <math>a</math> days from now. But, one of my friends gets tired very quickly and he only rolls dice for 1 day and stops. Another friend only will roll dice for 2 days, and another will roll dice for three days only, and so on up to the fact that my last friend will roll dice for 20 days. In Python, simulate this. How many times does someone roll 3 after everything?'''<br />
<br />
We will have to make our for loop into a function again.<br />
<br />
import random<br />
<br />
def roll():<br />
return random.randint(1,6)<br />
<br />
def count(amount):<br />
count_ = 0<br />
for i in range(1, amount+1):<br />
if roll() == 3:<br />
count_ += 1<br />
return count_<br />
<br />
def count2(amount)<br />
total = 0<br />
for i in range(1, amount + 1):<br />
total += count(i)<br />
return total<br />
<br />
def count3(amount)<br />
total = 0<br />
for i in range(1, amount + 1):<br />
total += count2(i)<br />
return total<br />
<br />
print(count3(20))<br />
<br />
(Our program is so long!)<br />
<br />
I also made a new function just in case we needed to turn that into a function later.<br />
<br />
'''Make sure''' you read the code carefully and you fully understand it. If you don't understand every single line of code, then you will get confused later on in this article.<br />
<br />
When you run this program, you might be surprised that the answer isn't so big.<br />
<br />
===Program Example 6===<br />
<br />
'''365 of my friends love rolling dice. They are all going to roll 1 die each tomorrow, 2 dice each two days from now, 3 dice each three days from now, and so on so that they roll <math>a</math> dice each <math>a</math> days from now. But, one of my friends gets tired very quickly and he only rolls dice for 1 day and stops. Another friend only will roll dice for 2 days, and another will roll dice for three days only, and so on up to the fact that my last friend will roll dice for 365 days. In Python, simulate this. How many times does someone roll 3 after everything?'''<br />
<br />
Because we soft-coded our program so much, all we have to do is change the last line so the parameter of count3() is 365.<br />
<br />
If we run it...we get a big answer, as expected. It also takes quite a while!<br />
<br />
You may not have realized that we soft-coded our program at all, but the whole point of functions is to soft-code programs!<br />
<br />
Congrats on writing a program that is around 25 lines long!<br />
<br />
==Very Basic Datatypes==<br />
<br />
An integer is a basic datatype in Python. Basically, all variables with the datatype of '''int''' is an integer.<br />
<br />
A string is another basic datatype, and it is a string of characters enclosed by quotes.<br />
<br />
===Why Are Datatypes So Important?===<br />
<br />
Let's say we wanted to make a program that would add 2 and 3. Some bogus code would be:<br />
<br />
x="2"<br />
y="3"<br />
print(x+y)<br />
<br />
If you ran this code, you would get 23. Why is that?<br />
<br />
Well, here, x and y are strings. When you perform the addition operator to strings in Python, it concatenates the strings, giving 23.<br />
<br />
The real code is:<br />
<br />
x=2<br />
y=3<br />
print(x+y)<br />
<br />
If you run this, you will get <math>5</math>, which is correct.<br />
<br />
Here's another reason datatypes are important. Now, we will introduce the datatype called the '''floating point number''', or '''float'''. A floating-point number is a number with a decimal point.<br />
<br />
Let's go back to the IDLE. Type "0.1*10". The result is 1.0. Notice the decimal point.<br />
<br />
Let's type something different. Type <math>0.1+0.1+0.1+0.1+0.1+0.1+0.1+0.1+0.1+0.1.</math><br />
<br />
'''WHAT!?'''<br />
<br />
You would have expected the answer to be 1, but it isn't 1. What happened?<br />
<br />
'''Float approximation''' happened. Most (almost all) programming languages have a bad float approximation. That means that 1.0 can turn into 0.99999999999999 and 0.5 can turn into 0.49999999999999999993. That only happens with floats, so we should try to use floats as sparingly as possible.<br />
<br />
==Lists==<br />
<br />
A for loop iterates over a '''list'''. A list is a bunch of objects stored in one variable. (Hey! A list is a datatype!) For loops are highly related to lists.<br />
<br />
Let's say we wanted to make a program to print all the items in a list.<br />
<br />
We will first create the list, using the code:<br />
<br />
myList = [1,4,6,8]<br />
<br />
This is a list with four items: 1, 4, 6, and 8.<br />
<br />
We must now print all elements of it with a for loop:<br />
<br />
myList = [1,4,6,8]<br />
for i in myList:<br />
print(i)<br />
<br />
When we run this program, we get the numbers 1, 4, 6, and 8, as expected.<br />
<br />
===Accessing Values===<br />
<br />
Let's say we wanted to print out the second item in a list. We will use '''indexes'''.<br />
<br />
The index of the first item in a list is always 0. The index of the second is 1. The index of the <math>n</math>th is <math>n-1.</math><br />
<br />
To print out the second item, we will use an index of 1, like this:<br />
<br />
myList = [1,4,6,8]<br />
print(myList[1])<br />
<br />
Notice that the index is inside of the square brackets.<br />
<br />
===Adding Values===<br />
<br />
We can use the list.append() function to add an object to the end of a list.<br />
<br />
myList.append(10)<br />
<br />
will add 10 to the list, which makes myList = [1,4,6,8,10].<br />
<br />
===Removing Items From Lists===<br />
<br />
We can use the list.remove() function to remove a specific item in a list.<br />
<br />
For example, consider this code.<br />
<br />
myList = [1,2,3]<br />
myList.remove(3)<br />
<br />
This code will make myList turn into [1,2]. The element, 3, gets removed.<br />
<br />
===len(list)===<br />
<br />
The len(list) function returns the length of a list.<br />
<br />
This code will print 3.<br />
<br />
myList = [1,2,3]<br />
print(len(myList))<br />
<br />
The length of myList is 3, so Python prints 3.<br />
<br />
===All Kinds Of Lists===<br />
<br />
Lists don't have to be only integers!<br />
<br />
myList = [1,"Hi","Hello world", 3.5, 3.14159265358979323]<br />
<br />
If fact, there can be lists inside of lists!<br />
<br />
myList = [[1,2,3], [3,4,5], [5,6,"Hello world"], "BOB", 3.1415926]<br />
<br />
Even this!<br />
<br />
myList = [[1, [1, [1,2,3],3],3], [[[3,["Hello world", 4],5],4,5],4,5], [5,6,7,[1,[1,2,3],3],"Hello world"], "BOB", 3.1415926, True]<br />
<br />
If you look at that list carefully, you will find lists inside of lists inside of lists inside of lists! And, a boolean at the end!<br />
<br />
Like variables, you can have as many lists in a program as you want (a list is a variable)!<br />
<br />
myList = [1,2,3,4]<br />
yourList = [5,6,7,8]<br />
hisList = [9,10,11,12]<br />
herList = [13,14,15,16]<br />
theirList = [17,18,19,20]<br />
ourList = [21,22,23,24]<br />
listsOfLists = [[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16],[17,18,19,20],[21,22,23,24]]<br />
<br />
===Splitting Lists===<br />
Split Operator Basics:<br />
genericList[where to start:where to end:what size steps to take]<br />
The value where to start is inclusive, and denotes the index where your split list begins. It has a default value of 0.<br />
The value where to end is exclusive, and denotes the index where your split list ends. It has a default value of len(genericList).<br />
The value what size steps denotes the size of the steps your split takes(more on that later). It has a default value of 1.<br />
Say you want to split a list and only return certain indices, for example if you wanted to split a list called data and put the first two elements into a list called head and the last two into a list called tail, you would split like this:<br />
data = [1, 3, 4, 23.5, 40, 55]<br />
head = data[:2]<br />
tail = data[-2:] # negative list indices represent the end of a list, so -1 is the last element and -2 is the second-to-last<br />
Step Size:<br />
We will practice writing a few functions that select every other element and will reverse in a list using step size.<br />
A step size of two means skip every other list index, so we can write our first function.<br />
def selectEveryOtherElement(list):<br />
return list[::2]<br />
But which step size will get us our desired reversed list. We could start at the end of the list and iterate backwards, but how would we do that...<br />
Negative Step Size:<br />
A step size that is negative means skip a certain amount of elements, but backwards. If we were to start at 0, with a step size of -1, we would be able to iterate backwards over the list!<br />
def reverse(list):<br />
return list[::-1]<br />
Splitting lists with ratios:<br />
What if we wanted to be able to split a list based upon a ratio. For example, the common 80:20 train to test ratio in machine learning? Here is how you would do it<br />
def eighty-twenty(list):<br />
train = list[:int(len(list) * (4 / 5))] # We must include the int() method to convert to an integer if len(list) % 5 != 0<br />
test = list[int(len(list) * 4 / 5)]<br />
return [train, test] # We then return a list with the train and test lists inside<br />
<br />
==Dictionaries==<br />
<br />
A dictionary (a type of datatype) is a bunch of keys and values. There is a major difference between dictionaries and lists. Lists are ordered; dictionaries are not.<br />
<br />
Here is the '''syntax''' of creating a dictionary:<br />
<br />
myDictionary = {1:"one",2:"two"}<br />
<br />
This dictionary has two key/value pairs. Notice it is surrounded in curly braces. The keys are 1 and 2; the values are "one" and "two."<br />
<br />
How is this useful? Let's make a simple program to test it out.<br />
<br />
myDictionary = {1:"one",2:"two"}<br />
print(myDictionary[1])<br />
print(myDictionary[2])<br />
<br />
===Accessing Values===<br />
<br />
To access a value in a dictionary, you put in the key.<br />
<br />
myDictionary[1]<br />
<br />
returns one, because 1 is the key to "one."<br />
<br />
===Adding New Values===<br />
<br />
To overwrite a value, we do this.<br />
<br />
myDictionary[1] = "won"<br />
<br />
The value to the key 1 is now "won."<br />
<br />
To add a value, we do the same thing!<br />
<br />
myDictionary[3] = "three"<br />
<br />
This adds a key 3 with a value of "three."<br />
<br />
==Misc Concepts==<br />
<br />
This section will talk about some concepts that we haven't learned yet.<br />
<br />
====Concatenating Strings====<br />
<br />
Concatenating strings is putting them together. For example, "one" concatenated with "two" gives "onetwo."<br />
<br />
The following string,<br />
<br />
"Hello, " + person2 + "! How are you?"<br />
<br />
depends on what person2 was. If person2 was Bob, the string would be:<br />
<br />
"Hello, Bob! How are you?"<br />
<br />
It fits together perfectly!<br />
<br />
You cannot concatenate strings with integers. For example, doing this:<br />
<br />
"2" + 3<br />
<br />
will not work. Instead, to get an answer of "23", you must do this:<br />
<br />
"2" + str(3)<br />
<br />
That turns 3 into a string so it is "3", and the result will be "23".<br />
<br />
There is a faster way to do this:<br />
<br />
name="aops"<br />
"hello %s" % name<br />
<br />
or even faster<br />
<br />
wiki_name="AOPS WIKI"<br />
"This is the {0}".format(wiki_name)<br />
====Line Breaks====<br />
<br />
We can use multiple line breaks to make our code more organized. There are some places that you cannot line break. For example, this code will produce an error:<br />
<br />
myList =<br />
[1,2,3]<br />
<br />
This code does not work.<br />
<br />
This code '''does work''':<br />
<br />
myList = [<br />
1,2,3]<br />
<br />
It is accepted when you break a line right after the [. It is also accepted right after a comma. (And right before the ending ].)<br />
<br />
myList = [<br />
1,<br />
2,<br />
3<br />
]<br />
<br />
==Challenge Program==<br />
<br />
In this section, we will attempt the hardest program so far in this article.<br />
<br />
'''Make a conversation generator that will generate random conversations between different people.'''<br />
<br />
First, we will generate the people. We can use a list and generate two random numbers.<br />
<br />
import random<br />
<br />
peopleNames = [<br />
"Bob",<br />
"Kyle",<br />
"James",<br />
"Richard",<br />
"Zachary",<br />
"Olivia",<br />
"Jonathan",<br />
"Will",<br />
"Bobby",<br />
"Kevin"<br />
]<br />
person1 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
peopleNames.remove(person1)<br />
person2 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
<br />
(I made it more organized by separating the long lines of code into multiple lines. It only works when you have a line break right after each item in the list.)<br />
<br />
Here, we use the remove() function to remove person1 from the list to make sure we don't use the same name twice. <br />
<br />
We also used the len() function to find the length of the list (soft-coding!)<br />
<br />
Now, we need to create a list of possible values for the first thing that person1 says (person1 will always be the first one to talk). <br />
<br />
Then, we will print it out.<br />
<br />
import random<br />
<br />
peopleNames = [<br />
"Bob",<br />
"Kyle",<br />
"James",<br />
"Richard",<br />
"Zachary",<br />
"Olivia",<br />
"Jonathan",<br />
"Will",<br />
"Bobby",<br />
"Kevin"<br />
]<br />
person1 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
peopleNames.remove(person1)<br />
person2 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
<br />
first = [<br />
"Hi!",<br />
"Hello!",<br />
"Good morning!",<br />
"Hello, " + person2 + "!",<br />
"Hi.",<br />
"Hi, " + person2 + "!"<br />
]<br />
print(person1 + ": " + first[random.randint(0, (len(first) - 1))])<br />
<br />
If we test out this program, we can confirm that this part indeed does work. This program is already getting long! Now, we will use the same method and create the second message.<br />
<br />
import random<br />
<br />
peopleNames = [<br />
"Bob",<br />
"Kyle",<br />
"James",<br />
"Richard",<br />
"Zachary",<br />
"Olivia",<br />
"Jonathan",<br />
"Will",<br />
"Bobby",<br />
"Kevin"<br />
]<br />
person1 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
peopleNames.remove(person1)<br />
person2 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
<br />
first = [<br />
"Hi!",<br />
"Hello!",<br />
"Good morning!",<br />
"Hello, " + person2 + "!",<br />
"Hi.",<br />
"Hi, " + person2 + "!"<br />
]<br />
print(person1 + ": " + first[random.randint(0, (len(first) - 1))])<br />
<br />
second = [<br />
"Hi! How are you today?",<br />
"Hello! How are you?",<br />
"Good morning! How are you today?",<br />
"Hello, " + person1 + "! How are you?",<br />
"Hi. How are you?",<br />
"Hi, " + person1 + "! How are you today?"<br />
]<br />
print(person2 + ": " + second[random.randint(0, (len(second) - 1))])<br />
<br />
We will repeat this for the rest of the conversation:<br />
<br />
import random<br />
<br />
peopleNames = [<br />
"Bob",<br />
"Kyle",<br />
"James",<br />
"Richard",<br />
"Zachary",<br />
"Olivia",<br />
"Jonathan",<br />
"Will", <br />
"Bobby",<br />
"Kevin"<br />
]<br />
person1 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
peopleNames.remove(person1)<br />
person2 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
<br />
first = [<br />
"Hi!",<br />
"Hello!",<br />
"Good morning!",<br />
"Hello, " + person2 + "!",<br />
"Hi.",<br />
"Hi, " + person2 + "!"<br />
]<br />
print(person1 + ": " + first[random.randint(0, (len(first) - 1))])<br />
<br />
second = [<br />
"Hi! How are you today?",<br />
"Hello! How are you?",<br />
"Good morning! How are you today?",<br />
"Hello, " + person1 + "! How are you?",<br />
"Hi. How are you?",<br />
"Hi, " + person1 + "! How are you today?"<br />
]<br />
print(person2 + ": " + second[random.randint(0, (len(second) - 1))])<br />
<br />
third = [<br />
"I'm feeling awesome! And you?",<br />
"I'm feeling alright! How are you?",<br />
"I'm good, thank you. How are you feeling?",<br />
"I'm fine!" ,<br />
"How are you today?"<br />
]<br />
print(person1 + ": " + third[random.randint(0, (len(third) - 1))])<br />
<br />
fourth = [<br />
"I'm feeling great!",<br />
"I'm awesome!",<br />
"Thanks for asking! I am feeling good today!",<br />
"I'm feeling awesome today! Yippee!"<br />
] <br />
print(person2 + ": " + fourth[random.randint(0, (len(fourth) - 1))])<br />
<br />
fifth = [<br />
"It's so nice out today!",<br />
"Today is such a cloudy day.",<br />
"I hate it when it is so cloudy outside!",<br />
"It's partly cloudy today!"<br />
]<br />
print(person1 + ": " + fifth[random.randint(0, (len(fifth) - 1))])<br />
<br />
sixth = [<br />
"I know, right?",<br />
"I know.",<br />
"Yeah!",<br />
"True."<br />
]<br />
print(person2 + ": " + sixth[random.randint(0, (len(sixth) - 1))])<br />
<br />
seventh = [<br />
"Sorry, I need to leave. Bye!",<br />
"I gotta go. Bye!",<br />
"Sorry, I don't have time to stay and chat. I've got to go somewhere. Bye!"<br />
]<br />
print(person1 + ": " + seventh[random.randint(0, (len(seventh) - 1))])<br />
<br />
eighth = [<br />
"Bye!",<br />
"Good-bye!",<br />
"Bye, " + person1 + "."<br />
]<br />
print(person2 + ": " + eighth[random.randint(0, (len(eighth) - 1))])<br />
<br />
Whew! So long!<br />
<br />
Once we run our program. It works! This program really wasn't that hard.<br />
<br />
Congrats! You've made it so far!</div>Anstarhttps://artofproblemsolving.com/wiki/index.php?title=Basic_Programming_With_Python&diff=134876Basic Programming With Python2020-10-10T19:31:08Z<p>Anstar: /* Misc Concepts */</p>
<hr />
<div>'''Important: It is extremely recommended that you read [[Getting Started With Python Programming]] before reading this unless you already know some programming knowledge.'''<br />
<br />
(Note: This is a really long article. To learn the most from this article, you need to read everything in order and skip nothing, unless you are '''absolutely absolutely sure that that content is way too easy for you.''')<br />
<br />
This article will talk about some basic Python programming. If you don't even know how to install Python, look [[Getting Started With Python Programming|here]].<br />
<br />
Note that this article has lots of program examples. It is recommended (but not required) to try these on your own before looking at the solutions.<br />
<br />
==Loops==<br />
<br />
There are two different kinds of loops in Python: the for loop and the while loop.<br />
<br />
===The For Loop===<br />
<br />
The for loop iterates over a list, or an array, of objects. You have probably seen this code before:<br />
<br />
[[File:Capture.PNG|200px]]<br />
<br />
This for loop iterates over the list of integers from 1 to 51, excluding the 51 and including the 1. That means it is a list from 1 to 50, inclusive. On every iteration, Python will print the number that the loop is iterating through. <br />
<br />
For example, in the first iteration, i = 1, so Python prints 1.<br />
<br />
In the second iteration, i = 2, so Python prints 2.<br />
<br />
This continues so on until the number, 50, is reached. Therefore, the last number Python will print out is 50.<br />
<br />
====Program Example====<br />
<br />
'''Find <math>\sum_{n=1}^{50} 2^{n}.</math>'''<br />
<br />
To do this task, we must create a for loop and loop over the integers from 1 to 50 inclusive:<br />
<br />
for i in range(1,51):<br />
<br />
Now what? We must keep a running total and increase it by <math>2^i</math> every time:<br />
<br />
total = 0<br />
for i in range(1,51):<br />
total += 2**i<br />
<br />
We must not forget to print the total at the end!<br />
<br />
total = 0<br />
for i in range(1,51):<br />
total += 2**i<br />
print(total)<br />
<br />
You must exit out of the for loop one you reach the print(total) line by pressing backspace.<br />
<br />
Once you run your program, you should get an answer of <math>\boxed{2,251,799,813,685,246.}</math><br />
<br />
===The While Loop===<br />
<br />
While loops don't loop over a list. They loop over and over and over...'''until'''...a condition becomes false.<br />
<br />
i = 3<br />
total = 0<br />
while i < 1000:<br />
total += i<br />
i += 3<br />
print(total)<br />
<br />
In this code, the while loop loops 333 times, until <math>i</math> becomes greater than or equal to 1000.<br />
<br />
====Program Example====<br />
<br />
'''Find <math>\sum_{n=1}^{50} 2^n</math> using a while loop.'''<br />
<br />
We must create a while loop that will iterate until n is greater than <math>50.</math><br />
<br />
n = 1<br />
total = 0<br />
while n <= 50:<br />
total += 2**n<br />
n += 1<br />
print(total)<br />
<br />
We must not forget to include the n += 1 line at the end of the while loop! <br />
<br />
If we run this, we will get the same answer as last time, <math>2,251,799,813,685,246.</math><br />
<br />
==Functions==<br />
<br />
In this section, we will define new operations and do arithmetic with them in Python.<br />
<br />
===The New Operation===<br />
Let's say that you defined a new binary operation, the <math>\uparrow \downarrow.</math> You want it to be so <math>a \uparrow \downarrow b = a^{b}b^{a}.</math> Therefore, <math>1\uparrow \downarrow 2 = 1^{2}2^{1}=1\cdot 2= 2,</math> and <math>2\uparrow \downarrow 3 = 2^33^2 = 8\cdot 9 = 72.</math> Let's call this operation an '''up down arrow.'''<br />
<br />
===Program Example 1===<br />
<br />
'''Find <math>[2 \uparrow \downarrow (1 \uparrow \downarrow 2)] \uparrow \downarrow 2.</math>'''<br />
<br />
We know this will be a big number, so we should write a program to do it! We certainly don't want to do the exponentiation and multiplication every time we use the operation in our program, and that's where functions come in! Functions can take in parameters (<math>a</math> and <math>b</math>) and return a result depending on the parameters.<br />
<br />
def up_down_arrow(a,b): <br />
return ((a**b) * (b**a))<br />
<br />
Above is the code to define our function. We need to print the final result at the end, so we must put a print statement at the end.<br />
<br />
def up_down_arrow(a,b): <br />
return ((a**b) * (b**a))<br />
print(up_down_arrow(up_down_arrow(2,up_down_arrow(1,2)),2)<br />
<br />
All those nested up_down_arrow's might be confusing at first, but it really isn't that confusing.<br />
If you run your program, you should get your answer: <math>16,777,216.</math> <br />
<br />
You might be surprised that the answer is so big. If you actually start calculating the real answer without a program, you will really quickly find that the final result is <math>16 \uparrow \downarrow 2,</math> which does turn out to be 16,777,216 if you use a calculator.<br />
<br />
Let's make another operation!<br />
<br />
We will define the operation <math>\uparrow \downarrow \leftarrow \rightarrow</math> to be called '''all around.''' <math>a \uparrow \downarrow \leftarrow \rightarrow b = (ab(a \uparrow \downarrow b))^2.</math> That's an operation that will make really big numbers!<br />
<br />
===Program Example 2===<br />
<br />
'''Find 87 all around 132.'''<br />
<br />
The answer is bound to be a huge number, so we must make a program to solve it.<br />
<br />
We will keep our up_down_arrow function because in the definition of our all_around function we will use it. Then, we will define the all_around function.<br />
<br />
def up_down_arrow(a,b):<br />
return ((a**b) * (b**a))<br />
def all_around(a,b):<br />
return ((a * b * up_down_arrow(a,b)) ** 2)<br />
<br />
We must print all_around(87,132) at the end. Once we do that, and we run our program, we get a super huge number that has over 800 digits!<br />
<br />
===Understanding Functions===<br />
<br />
Every single function has a '''return value'''. If a function does not return anything, the return value is '''null'''. Null is a term used in programming as a placeholder that stands for nothing.<br />
<br />
====Simple Program Example 1====<br />
<br />
'''Define a function that adds 1 to an input.'''<br />
<br />
How will the function know what number to add 1 to? We will input a '''parameter''' for the function to add 1 to.<br />
<br />
def add_one(x):<br />
return x + 1<br />
<br />
In this function, <math>x</math> is the parameter.<br />
<br />
def add_one(x):<br />
return x + 1<br />
print(add_one(2))<br />
<br />
In the print statement, we set <math>x</math> as 2, and the function returns <math>2 + 1 = 3,</math> so the program prints <math>3</math>.<br />
<br />
====Simple Program Example 2====<br />
<br />
'''Define a function that prints out an input.'''<br />
<br />
We will use a parameter again.<br />
<br />
def print_function(x):<br />
print(x)<br />
<br />
Uh oh! We have nothing to return! Therefore, we will return nothing (or null), by just writing return.<br />
<br />
def print_function(x):<br />
print(x)<br />
return<br />
print_function("print_function")<br />
<br />
This code prints out print_function. print_function() is said to be '''called''' in the final line of the code. Again, we set <math>x</math>, our parameter, as "print_function."<br />
== Classes ==<br />
Classes are <br />
<br />
===Defining a class===<br />
We can define a class by doing the following:<br />
<br />
<br />
class Example:<br />
pass<br />
<br />
Usually, classes use CamelCase convention.<br />
We can call a class by doing the following<br />
<br />
===methods===<br />
methods are functions that apply to a class.<br />
<br />
===__init__===<br />
===__str__===<br />
===overloading===<br />
overloading means changing a builtin function to do what you want it to do.<br />
<br />
==Flow==<br />
<br />
Flow consists of if statements, elif (else if) statements, and else statements.<br />
<br />
*An if statement checks if a comparison is true.<br />
<br />
*An else statement checks if a comparison is not true. It is used after an if statement (and all elif statements after the if statement) and it shares the same comparison as the if statement.<br />
<br />
*An elif statement checks for two things: if a comparison is true, and if a comparison is not true. It is used right after the if statement.<br />
<br />
===Program Example===<br />
<br />
'''Does the number 10 have the property that when you multiply 10 by 5, you get a two digit number?'''<br />
<br />
This problem is super easy to solve without a program, but let's write a program to solve this anyway. We will use an if statement to check if <math>10\cdot 5</math> is less than 100 and greater than 9.<br />
<br />
if 10*5 > 9:<br />
if 10*5 < 100:<br />
print("Yes")<br />
else:<br />
print("No")<br />
else:<br />
print("No")<br />
<br />
This code means, if 10*5 > 9, then we will check if it is less than 100. If it is not greater than 9, however, we will print No. If it is greater than 9, we check if it is less than 100. If it is, we print Yes. If it isn't we print No.<br />
<br />
These nested if statements can be very confusing. Luckily, there is a faster an easier way to do this.<br />
<br />
if 10*5 > 9 and 10*5 < 100:<br />
print("Yes") <br />
else:<br />
print("No")<br />
<br />
This code checks for the two conditions at the same time. If we run it, we get our answer of Yes.<br />
<br />
==Booleans==<br />
<br />
===Program Example===<br />
<br />
'''Print all two-digit positive integers <math>x</math> such that <math>5x</math> is a two-digit positive integer.'''<br />
<br />
We can create a function with our previous code.<br />
<br />
We will have to slightly modify our function so we can use it in a for loop at the end:<br />
<br />
def check(a):<br />
if a*5 > 9 and a*5 < 100:<br />
return True <br />
else:<br />
return False<br />
<br />
True and False are what are called '''booleans'''. When an if or elif statement receives True, the code inside of the statement happens. When an if or elif statement receives False, the code inside of the statement does not happen. <br />
<br />
We must create a for loop that will iterate through all two digit positive integers. <br />
<br />
def check(a):<br />
if a*5 > 9 and a*5 < 100:<br />
return True <br />
else:<br />
return False<br />
for i in range(10,100):<br />
if check(i):<br />
print(i)<br />
<br />
The final for loop checks if <math>5i</math> is a two digit integer. If it is, the function returns True and the code inside the if statement gets run. If it isn't, the function returns False and the code inside the if statement gets ignored.<br />
<br />
If we run this, we will get the answer.<br />
<br />
All two digit integers from 10 to 19 inclusive work!<br />
<br />
=="Soft Coding" Programs==<br />
<br />
In the next few examples, you will see why hard coding programs is bad. Hard coding programs refers to coding a program that is hard to modify. For example:<br />
<br />
===Program Example 1===<br />
<br />
'''Print all two digit positive integers <math>x</math> such that <math>5x</math> is a three digit positive integer.'''<br />
<br />
We can keep our code and modify some parts of it.<br />
<br />
def check(a, min, max):<br />
if a*5 > min - 1 and a*5 < max + 1:<br />
return True <br />
else:<br />
return False<br />
<br />
def print_check(range_min, range_max, check_min, check_max):<br />
for i in range(range_min, range_max + 1):<br />
if check(i, check_min, check_max):<br />
print(i)<br />
return<br />
<br />
print_check(10, 99, 100, 999)<br />
<br />
Why did we add so many functions?<br />
<br />
Well, if the numbers in a problem change (and the words stay the same), and you need to change a lot of numbers in your program, your program is considered '''hard-coded'''. We want our programs to be as '''soft-coded''' as possible. In our new program, we only need to change 4 numbers (in the print_check() statement) if the numbers in the problem change. Therefore, our program is relatively soft-coded. There are still ways to soft-code this program even more, though.<br />
<br />
If we run our program, we get our answer.<br />
<br />
All numbers from 20 to 99 work!<br />
<br />
===Program Example 2===<br />
<br />
'''Print all three digit positive integers <math>x</math> such that <math>5x</math> is a three digit positive integer.'''<br />
<br />
We can just change the print_check line at the end to<br />
<br />
print_check(100, 999, 100, 999)<br />
<br />
and our program will be ready to be run.<br />
<br />
All numbers from 100 to 199 work.<br />
<br />
===Program Example 3===<br />
<br />
'''Print all two digit positive integers <math>x</math> such that <math>3x</math> is a three digit positive integer.'''<br />
<br />
Uh oh. Only changing the print_check line won't work. We will need to change our functions!<br />
<br />
def check(a, min, max, factor):<br />
if a*factor > min - 1 and a*factor < max + 1:<br />
return True <br />
else:<br />
return False<br />
<br />
def print_check(range_min, range_max, check_min, check_max, check_factor):<br />
for i in range(range_min, range_max + 1):<br />
if check(i, check_min, check_max, check_factor):<br />
print(i)<br />
return<br />
<br />
print_check(10, 99, 100, 999, 3)<br />
<br />
In this step, we added a parameter in both functions. We also soft-coded our program even more! Hooray!<br />
<br />
All integers from 34 to 99 work.<br />
<br />
===Program Example 4===<br />
<br />
'''Print all two digit positive integers <math>x</math> such that <math>12x</math> is a positive integer from 500 to 900.'''<br />
<br />
This problem may look a bit different from the other ones, but it really is the same thing, except that the factor is 12 and check_min and check_max are 500 and 900, respectively.<br />
<br />
Once we change the final print_check() line to satisfy our needs, we can run our program.<br />
<br />
All numbers from 42 to 75 work!<br />
<br />
Congrats! You have written your first programs above 10 lines of code!<br />
<br />
==Random==<br />
<br />
There is a package in Python that allows the use of random numbers.<br />
<br />
===Program Example 1===<br />
<br />
'''Generate a random number from 1 to 6.'''<br />
<br />
Easy peasy. We will just generate a random number from 1 to 6 with the package like this:<br />
<br />
import random<br />
print(random.randint(1,6))<br />
<br />
As you can see, when you run this program, you get a random integer from 1 to 6.<br />
<br />
===Program Example 2===<br />
<br />
'''Simulate the rolling of 1000 dice. Now, count the number of times you roll 6. Print that number out.'''<br />
<br />
We can create a function that returns a random number from 1 to 6. Then, we can make a for loop that rolls the dice 1000 times and check if it is a 6.<br />
<br />
import random<br />
count = 0<br />
<br />
def roll():<br />
return random.randint(1,6)<br />
<br />
for i in range(1, 1001):<br />
if roll() == 6:<br />
count += 1<br />
<br />
print(count)<br />
<br />
If we run this, we will get a number around 170.<br />
<br />
===Program Example 3===<br />
<br />
'''Simulate the rolling of 10,000 dice. Now, count the amount of times you roll 3. Print that amount out.'''<br />
<br />
We can keep our roll function and our code inside the for loop, but we need to change our for loop statement.<br />
<br />
We can actually soft-code our program more. Let's turn the whole for loop into a function!<br />
<br />
import random<br />
<br />
def roll():<br />
return random.randint(1,6)<br />
<br />
def count(amount):<br />
count_ = 0<br />
<br />
for i in range(1, amount+1):<br />
if roll() == 3:<br />
count_ += 1<br />
return count_<br />
<br />
print(count(10000))<br />
<br />
If we run this code, it works.<br />
<br />
===Program Example 4===<br />
<br />
'''One of my friends loves rolling dice. He is going to roll 1 die tomorrow, 2 dice two days from now, 3 dice three days from now, and so on so that he rolls <math>a</math> dice <math>a</math> days from now. He gets tired rolling dice after rolling dice for 365 days (so the last day he rolls 365 dice). In Python, simulate this. How many times does he roll 3 after 365 days of rolling dice?'''<br />
<br />
We can use a for loop that calls a function multiple times.<br />
<br />
import random<br />
<br />
def roll():<br />
return random.randint(1,6)<br />
<br />
def count(amount):<br />
count_ = 0<br />
for i in range(1, amount+1):<br />
if roll() == 3:<br />
count_ += 1<br />
return count_<br />
<br />
total = 0<br />
<br />
for i in range(1, 366):<br />
total += count(i)<br />
<br />
print(total)<br />
<br />
This is a really long program, but the whole program should make sense if you look at it for a while. We defined our count function in the previous example, and now we are using it with a for loop and a running total. <br />
<br />
You should get a number around 11,000 when you run it. Wow, lots of 3's!<br />
<br />
===Program Example 5===<br />
<br />
'''20 of my friends love rolling dice. They are all going to roll 1 die each tomorrow, 2 dice each two days from now, 3 dice each three days from now, and so on so that they roll <math>a</math> dice each <math>a</math> days from now. But, one of my friends gets tired very quickly and he only rolls dice for 1 day and stops. Another friend only will roll dice for 2 days, and another will roll dice for three days only, and so on up to the fact that my last friend will roll dice for 20 days. In Python, simulate this. How many times does someone roll 3 after everything?'''<br />
<br />
We will have to make our for loop into a function again.<br />
<br />
import random<br />
<br />
def roll():<br />
return random.randint(1,6)<br />
<br />
def count(amount):<br />
count_ = 0<br />
for i in range(1, amount+1):<br />
if roll() == 3:<br />
count_ += 1<br />
return count_<br />
<br />
def count2(amount)<br />
total = 0<br />
for i in range(1, amount + 1):<br />
total += count(i)<br />
return total<br />
<br />
def count3(amount)<br />
total = 0<br />
for i in range(1, amount + 1):<br />
total += count2(i)<br />
return total<br />
<br />
print(count3(20))<br />
<br />
(Our program is so long!)<br />
<br />
I also made a new function just in case we needed to turn that into a function later.<br />
<br />
'''Make sure''' you read the code carefully and you fully understand it. If you don't understand every single line of code, then you will get confused later on in this article.<br />
<br />
When you run this program, you might be surprised that the answer isn't so big.<br />
<br />
===Program Example 6===<br />
<br />
'''365 of my friends love rolling dice. They are all going to roll 1 die each tomorrow, 2 dice each two days from now, 3 dice each three days from now, and so on so that they roll <math>a</math> dice each <math>a</math> days from now. But, one of my friends gets tired very quickly and he only rolls dice for 1 day and stops. Another friend only will roll dice for 2 days, and another will roll dice for three days only, and so on up to the fact that my last friend will roll dice for 365 days. In Python, simulate this. How many times does someone roll 3 after everything?'''<br />
<br />
Because we soft-coded our program so much, all we have to do is change the last line so the parameter of count3() is 365.<br />
<br />
If we run it...we get a big answer, as expected. It also takes quite a while!<br />
<br />
You may not have realized that we soft-coded our program at all, but the whole point of functions is to soft-code programs!<br />
<br />
Congrats on writing a program that is around 25 lines long!<br />
<br />
==Very Basic Datatypes==<br />
<br />
An integer is a basic datatype in Python. Basically, all variables with the datatype of '''int''' is an integer.<br />
<br />
A string is another basic datatype, and it is a string of characters enclosed by quotes.<br />
<br />
===Why Are Datatypes So Important?===<br />
<br />
Let's say we wanted to make a program that would add 2 and 3. Some bogus code would be:<br />
<br />
x="2"<br />
y="3"<br />
print(x+y)<br />
<br />
If you ran this code, you would get 23. Why is that?<br />
<br />
Well, here, x and y are strings. When you perform the addition operator to strings in Python, it concatenates the strings, giving 23.<br />
<br />
The real code is:<br />
<br />
x=2<br />
y=3<br />
print(x+y)<br />
<br />
If you run this, you will get <math>5</math>, which is correct.<br />
<br />
Here's another reason datatypes are important. Now, we will introduce the datatype called the '''floating point number''', or '''float'''. A floating-point number is a number with a decimal point.<br />
<br />
Let's go back to the IDLE. Type "0.1*10". The result is 1.0. Notice the decimal point.<br />
<br />
Let's type something different. Type <math>0.1+0.1+0.1+0.1+0.1+0.1+0.1+0.1+0.1+0.1.</math><br />
<br />
'''WHAT!?'''<br />
<br />
You would have expected the answer to be 1, but it isn't 1. What happened?<br />
<br />
'''Float approximation''' happened. Most (almost all) programming languages have a bad float approximation. That means that 1.0 can turn into 0.99999999999999 and 0.5 can turn into 0.49999999999999999993. That only happens with floats, so we should try to use floats as sparingly as possible.<br />
<br />
==Lists==<br />
<br />
A for loop iterates over a '''list'''. A list is a bunch of objects stored in one variable. (Hey! A list is a datatype!) For loops are highly related to lists.<br />
<br />
Let's say we wanted to make a program to print all the items in a list.<br />
<br />
We will first create the list, using the code:<br />
<br />
myList = [1,4,6,8]<br />
<br />
This is a list with four items: 1, 4, 6, and 8.<br />
<br />
We must now print all elements of it with a for loop:<br />
<br />
myList = [1,4,6,8]<br />
for i in myList:<br />
print(i)<br />
<br />
When we run this program, we get the numbers 1, 4, 6, and 8, as expected.<br />
<br />
===Accessing Values===<br />
<br />
Let's say we wanted to print out the second item in a list. We will use '''indexes'''.<br />
<br />
The index of the first item in a list is always 0. The index of the second is 1. The index of the <math>n</math>th is <math>n-1.</math><br />
<br />
To print out the second item, we will use an index of 1, like this:<br />
<br />
myList = [1,4,6,8]<br />
print(myList[1])<br />
<br />
Notice that the index is inside of the square brackets.<br />
<br />
===Adding Values===<br />
<br />
We can use the list.append() function to add an object to the end of a list.<br />
<br />
myList.append(10)<br />
<br />
will add 10 to the list, which makes myList = [1,4,6,8,10].<br />
<br />
===Removing Items From Lists===<br />
<br />
We can use the list.remove() function to remove a specific item in a list.<br />
<br />
For example, consider this code.<br />
<br />
myList = [1,2,3]<br />
myList.remove(3)<br />
<br />
This code will make myList turn into [1,2]. The element, 3, gets removed.<br />
<br />
===len(list)===<br />
<br />
The len(list) function returns the length of a list.<br />
<br />
This code will print 3.<br />
<br />
myList = [1,2,3]<br />
print(len(myList))<br />
<br />
The length of myList is 3, so Python prints 3.<br />
<br />
===All Kinds Of Lists===<br />
<br />
Lists don't have to be only integers!<br />
<br />
myList = [1,"Hi","Hello world", 3.5, 3.14159265358979323]<br />
<br />
If fact, there can be lists inside of lists!<br />
<br />
myList = [[1,2,3], [3,4,5], [5,6,"Hello world"], "BOB", 3.1415926]<br />
<br />
Even this!<br />
<br />
myList = [[1, [1, [1,2,3],3],3], [[[3,["Hello world", 4],5],4,5],4,5], [5,6,7,[1,[1,2,3],3],"Hello world"], "BOB", 3.1415926, True]<br />
<br />
If you look at that list carefully, you will find lists inside of lists inside of lists inside of lists! And, a boolean at the end!<br />
<br />
Like variables, you can have as many lists in a program as you want (a list is a variable)!<br />
<br />
myList = [1,2,3,4]<br />
yourList = [5,6,7,8]<br />
hisList = [9,10,11,12]<br />
herList = [13,14,15,16]<br />
theirList = [17,18,19,20]<br />
ourList = [21,22,23,24]<br />
listsOfLists = [[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16],[17,18,19,20],[21,22,23,24]]<br />
<br />
===Splitting Lists===<br />
Split Operator Basics:<br />
genericList[where to start:where to end:what size steps to take]<br />
The value where to start is inclusive, and denotes the index where your split list begins. It has a default value of 0.<br />
The value where to end is exclusive, and denotes the index where your split list ends. It has a default value of len(genericList).<br />
The value what size steps denotes the size of the steps your split takes(more on that later). It has a default value of 1.<br />
Say you want to split a list and only return certain indices, for example if you wanted to split a list called data and put the first two elements into a list called head and the last two into a list called tail, you would split like this:<br />
data = [1, 3, 4, 23.5, 40, 55]<br />
head = data[:2]<br />
tail = data[-2:] # negative list indices represent the end of a list, so -1 is the last element and -2 is the second-to-last<br />
Step Size:<br />
We will practice writing a few functions that select every other element and will reverse in a list using step size.<br />
A step size of two means skip every other list index, so we can write our first function.<br />
def selectEveryOtherElement(list):<br />
return list[::2]<br />
But which step size will get us our desired reversed list. We could start at the end of the list and iterate backwards, but how would we do that...<br />
Negative Step Size:<br />
A step size that is negative means skip a certain amount of elements, but backwards. If we were to start at 0, with a step size of -1, we would be able to iterate backwards over the list!<br />
def reverse(list):<br />
return list[::-1]<br />
Splitting lists with ratios:<br />
What if we wanted to be able to split a list based upon a ratio. For example, the common 80:20 train to test ratio in machine learning? Here is how you would do it<br />
def eighty-twenty(list):<br />
train = list[:int(len(list) * (4 / 5))] # We must include the int() method to convert to an integer if len(list) % 5 != 0<br />
test = list[int(len(list) * 4 / 5)]<br />
return [train, test] # We then return a list with the train and test lists inside<br />
<br />
==Dictionaries==<br />
<br />
A dictionary (a type of datatype) is a bunch of keys and values. There is a major difference between dictionaries and lists. Lists are ordered; dictionaries are not.<br />
<br />
Here is the '''syntax''' of creating a dictionary:<br />
<br />
myDictionary = {1:"one",2:"two"}<br />
<br />
This dictionary has two key/value pairs. Notice it is surrounded in curly braces. The keys are 1 and 2; the values are "one" and "two."<br />
<br />
How is this useful? Let's make a simple program to test it out.<br />
<br />
myDictionary = {1:"one",2:"two"}<br />
print(myDictionary[1])<br />
print(myDictionary[2])<br />
<br />
===Accessing Values===<br />
<br />
To access a value in a dictionary, you put in the key.<br />
<br />
myDictionary[1]<br />
<br />
returns one, because 1 is the key to "one."<br />
<br />
===Adding New Values===<br />
<br />
To overwrite a value, we do this.<br />
<br />
myDictionary[1] = "won"<br />
<br />
The value to the key 1 is now "won."<br />
<br />
To add a value, we do the same thing!<br />
<br />
myDictionary[3] = "three"<br />
<br />
This adds a key 3 with a value of "three."<br />
<br />
==Misc Concepts==<br />
<br />
This section will talk about some concepts that we haven't learned yet.<br />
<br />
====Concatenating Strings====<br />
<br />
Concatenating strings is putting them together. For example, "one" concatenated with "two" gives "onetwo."<br />
<br />
The following string,<br />
<br />
"Hello, " + person2 + "! How are you?"<br />
<br />
depends on what person2 was. If person2 was Bob, the string would be:<br />
<br />
"Hello, Bob! How are you?"<br />
<br />
It fits together perfectly!<br />
<br />
You cannot concatenate strings with integers. For example, doing this:<br />
<br />
"2" + 3<br />
<br />
will not work. Instead, to get an answer of "23", you must do this:<br />
<br />
"2" + str(3)<br />
<br />
That turns 3 into a string so it is "3", and the result will be "23".<br />
<br />
There is a faster way to do this:<br />
<br />
name="aops"<br />
"hello %s" % name<br />
<br />
or even faster<br />
<br />
wiki_name="AOPS WIKI"<br />
"This is the {0}".format(wiki_name)<br />
====Line Breaks====<br />
<br />
We can use multiple line breaks to make our code more organized. There are some places that you cannot line break. For example, this code will produce an error:<br />
<br />
myList =<br />
[1,2,3]<br />
<br />
This code does not work.<br />
<br />
This code '''does work''':<br />
<br />
myList = [<br />
1,2,3]<br />
<br />
It is accepted when you break a line right after the [. It is also accepted right after a comma. (And right before the ending ].)<br />
<br />
myList = [<br />
1,<br />
2,<br />
3<br />
]<br />
<br />
==Challenge Program==<br />
<br />
In this section, we will attempt the hardest program so far in this article.<br />
<br />
'''Make a conversation generator that will generate random conversations between different people.'''<br />
<br />
First, we will generate the people. We can use a list and generate two random numbers.<br />
<br />
import random<br />
<br />
peopleNames = [<br />
"Bob",<br />
"Kyle",<br />
"James",<br />
"Richard",<br />
"Zachary",<br />
"Olivia",<br />
"Jonathan",<br />
"Will",<br />
"Bobby",<br />
"Kevin"<br />
]<br />
person1 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
peopleNames.remove(person1)<br />
person2 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
<br />
(I made it more organized by separating the long lines of code into multiple lines. It only works when you have a line break right after each item in the list.)<br />
<br />
Here, we use the remove() function to remove person1 from the list to make sure we don't use the same name twice. <br />
<br />
We also used the len() function to find the length of the list (soft-coding!)<br />
<br />
Now, we need to create a list of possible values for the first thing that person1 says (person1 will always be the first one to talk). <br />
<br />
Then, we will print it out.<br />
<br />
import random<br />
<br />
peopleNames = [<br />
"Bob",<br />
"Kyle",<br />
"James",<br />
"Richard",<br />
"Zachary",<br />
"Olivia",<br />
"Jonathan",<br />
"Will",<br />
"Bobby",<br />
"Kevin"<br />
]<br />
person1 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
peopleNames.remove(person1)<br />
person2 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
<br />
first = [<br />
"Hi!",<br />
"Hello!",<br />
"Good morning!",<br />
"Hello, " + person2 + "!",<br />
"Hi.",<br />
"Hi, " + person2 + "!"<br />
]<br />
print(person1 + ": " + first[random.randint(0, (len(first) - 1))])<br />
<br />
If we test out this program, we can confirm that this part indeed does work. This program is already getting long! Now, we will use the same method and create the second message.<br />
<br />
import random<br />
<br />
peopleNames = [<br />
"Bob",<br />
"Kyle",<br />
"James",<br />
"Richard",<br />
"Zachary",<br />
"Olivia",<br />
"Jonathan",<br />
"Will",<br />
"Bobby",<br />
"Kevin"<br />
]<br />
person1 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
peopleNames.remove(person1)<br />
person2 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
<br />
first = [<br />
"Hi!",<br />
"Hello!",<br />
"Good morning!",<br />
"Hello, " + person2 + "!",<br />
"Hi.",<br />
"Hi, " + person2 + "!"<br />
]<br />
print(person1 + ": " + first[random.randint(0, (len(first) - 1))])<br />
<br />
second = [<br />
"Hi! How are you today?",<br />
"Hello! How are you?",<br />
"Good morning! How are you today?",<br />
"Hello, " + person1 + "! How are you?",<br />
"Hi. How are you?",<br />
"Hi, " + person1 + "! How are you today?"<br />
]<br />
print(person2 + ": " + second[random.randint(0, (len(second) - 1))])<br />
<br />
We will repeat this for the rest of the conversation:<br />
<br />
import random<br />
<br />
peopleNames = [<br />
"Bob",<br />
"Kyle",<br />
"James",<br />
"Richard",<br />
"Zachary",<br />
"Olivia",<br />
"Jonathan",<br />
"Will", <br />
"Bobby",<br />
"Kevin"<br />
]<br />
person1 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
peopleNames.remove(person1)<br />
person2 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
<br />
first = [<br />
"Hi!",<br />
"Hello!",<br />
"Good morning!",<br />
"Hello, " + person2 + "!",<br />
"Hi.",<br />
"Hi, " + person2 + "!"<br />
]<br />
print(person1 + ": " + first[random.randint(0, (len(first) - 1))])<br />
<br />
second = [<br />
"Hi! How are you today?",<br />
"Hello! How are you?",<br />
"Good morning! How are you today?",<br />
"Hello, " + person1 + "! How are you?",<br />
"Hi. How are you?",<br />
"Hi, " + person1 + "! How are you today?"<br />
]<br />
print(person2 + ": " + second[random.randint(0, (len(second) - 1))])<br />
<br />
third = [<br />
"I'm feeling awesome! And you?",<br />
"I'm feeling alright! How are you?",<br />
"I'm good, thank you. How are you feeling?",<br />
"I'm fine!" ,<br />
"How are you today?"<br />
]<br />
print(person1 + ": " + third[random.randint(0, (len(third) - 1))])<br />
<br />
fourth = [<br />
"I'm feeling great!",<br />
"I'm awesome!",<br />
"Thanks for asking! I am feeling good today!",<br />
"I'm feeling awesome today! Yippee!"<br />
] <br />
print(person2 + ": " + fourth[random.randint(0, (len(fourth) - 1))])<br />
<br />
fifth = [<br />
"It's so nice out today!",<br />
"Today is such a cloudy day.",<br />
"I hate it when it is so cloudy outside!",<br />
"It's partly cloudy today!"<br />
]<br />
print(person1 + ": " + fifth[random.randint(0, (len(fifth) - 1))])<br />
<br />
sixth = [<br />
"I know, right?",<br />
"I know.",<br />
"Yeah!",<br />
"True."<br />
]<br />
print(person2 + ": " + sixth[random.randint(0, (len(sixth) - 1))])<br />
<br />
seventh = [<br />
"Sorry, I need to leave. Bye!",<br />
"I gotta go. Bye!",<br />
"Sorry, I don't have time to stay and chat. I've got to go somewhere. Bye!"<br />
]<br />
print(person1 + ": " + seventh[random.randint(0, (len(seventh) - 1))])<br />
<br />
eighth = [<br />
"Bye!",<br />
"Good-bye!",<br />
"Bye, " + person1 + "."<br />
]<br />
print(person2 + ": " + eighth[random.randint(0, (len(eighth) - 1))])<br />
<br />
Whew! So long!<br />
<br />
Once we run our program. It works! This program really wasn't that hard.<br />
<br />
Congrats! You've made it so far!</div>Anstarhttps://artofproblemsolving.com/wiki/index.php?title=CSS:_Animations_and_Transitions&diff=133567CSS: Animations and Transitions2020-09-13T02:42:45Z<p>Anstar: </p>
<hr />
<div>CSS can create Animations and transitions.<br />
<br />
{{ stub }}</div>Anstarhttps://artofproblemsolving.com/wiki/index.php?title=CSS:_Animations_and_Transitions&diff=133566CSS: Animations and Transitions2020-09-13T02:41:47Z<p>Anstar: </p>
<hr />
<div>CSS can create Animations and transitions.<br />
{{ stub }}</div>Anstarhttps://artofproblemsolving.com/wiki/index.php?title=CSS:_Animations_and_Transitions&diff=133565CSS: Animations and Transitions2020-09-13T02:41:27Z<p>Anstar: Created page with "CSS can create Animations and transitions."</p>
<hr />
<div>CSS can create Animations and transitions.</div>Anstarhttps://artofproblemsolving.com/wiki/index.php?title=User:OlympusHero&diff=132441User:OlympusHero2020-08-24T03:12:32Z<p>Anstar: /* User Count */</p>
<hr />
<div>OlympusHero's Page:<br />
<br><br />
__NOTOC__<div style="border:2px solid black; -webkit-border-radius: 10px; background:#dddddd"><br />
==<font color="black" style="font-family: ITC Avant Garde Gothic Std, Verdana"><div style="margin-left:10px">User Count</div></font>==<br />
<div style="margin-left: 10px; margin-bottom:10px"><font color="black">If this is your first time visiting this page, edit it by incrementing the user count below by one.</font></div><br />
<center><font size="107px"> 103<br />
</font></center><br />
</div><br />
<div style="border:2px solid black; background:#cccccc;-webkit-border-radius: 10px; align:center"><br />
<br />
==<font color="black" style="font-family: ITC Avant Garde Gothic Std, Verdana"><div style="margin-left:10px">About Me</div></font>==<br />
<div style="margin-left: 10px; margin-bottom:10px"><font color="black">OlympusHero is currently borderline AIME.<br><br />
<br />
OlympusHero is 10 years old.<br><br />
<br />
OlympusHero scored 47/46 (got an extra point for finishing the test under 10 minutes) when mocking the 2019 MATHCOUNTS State test, and got silver on the 2020 online MATHCOUNTS State.<br><br />
<br />
OlympusHero is a pro at maths and chess<br />
<br />
OlympusHero for black mop 2021<br />
<br />
OlympusHero was #1 at the 2017 Chess World Cadets U8 (He was 7 years old)<br />
<br />
OlympusHero is pro believe it<br />
<br />
OlympusHero is much better than Rusczyk at maths yes<br />
</font></div><br />
</div><br />
<div style="border:2px solid black; background:#bbbbbb;-webkit-border-radius: 10px; align:center"><br />
<br />
==<font color="black" style="font-family: ITC Avant Garde Gothic Std, Verdana"><div style="margin-left:10px">Goals</div></font>==<br />
<div style="margin-left: 10px; margin-right: 10px; margin-bottom:10px">A User Count of 300<br />
<br />
Make AIME 2021 (Currently borderline)<br />
<br />
Get 5 or more on AIME I 2021 (Mocked a 3 on the 2020 AIME I a few months ago)<br />
<br />
Get to 40 or more on the MATHCOUNTS Trainer Nationals Level (25/40)<br />
<br />
Get a perfect score and First Place in IMO 2021.<br />
</div><br />
</div></div>Anstarhttps://artofproblemsolving.com/wiki/index.php?title=Asymptote:_Getting_Started/Windows/Downloads_and_Installation&diff=132246Asymptote: Getting Started/Windows/Downloads and Installation2020-08-20T19:22:36Z<p>Anstar: /* GSview */</p>
<hr />
<div>{{Asymptote}}<br />
<br />
:'''''NOTE''': The following instructions assume that you are using a Windows machine. Instructions for MAC and Unix users can be found under Documentation <math>\rightarrow</math> Installation [http://asymptote.sourceforge.net/ here].''<br />
<br />
To begin using Asymptote, you must first download and install it. To view the eps-format images you produce, you will also need to download an eps viewer such as GSview. (GSview is convenient because it can display both eps and pdf files, and with GhostScript installed, Asymptote can easily output the images in pdf format as well.)<br />
<br />
== Asymptote ==<br />
To download and install Asymptote on your Windows machine:<br />
<br />
#Click [http://sourceforge.net/projects/asymptote/files/latest/download?source=files here] and wait for the download to begin. This will bring you to SourceForge, which will help you download asymptote-X.YZ-setup.exe, where X.YZ is the version.<br />
#When the download is complete, browse to <tt>D:\downloads\Asymptote</tt>, or wherever you saved the file, and double-click on the <tt>.exe</tt> file (<tt>asymptote-X.YZ-setup.exe</tt>). This will open an installer window, where you can choose the folder that Asymptote will be installed to (or simply use the default <tt>C:\Program Files\Asymptote</tt>), and choose whether you wish to have shortcuts added to the desktop and start menu. When you have finished, click Install.<br />
<br />
Asymptote is ready to start producing images, but you still need a way to view these images. (NOTE: if you already have a previewer capable of viewing .eps and .pdf files, you do not need to download the file below.)<br />
<br />
== GSview ==<br />
GSview is a standard viewer for .eps files, which is the standard output format for Asymptote images. To download and install GSview,<br />
# Go to [http://pages.cs.wisc.edu/~ghost/gsview/ this download site], and click on the "Obtaining GSView" link. Then click on the first link down, <tt>gsvXYw32.exe</tt>, where X.Y is the version. A download window will pop up in your browser. Choose to save the file, and take note of where on your hard drive you saved it to. Let's say you saved it to the folder <tt>C:\downloads\Ghostscript</tt>. (If you are unable to get the file <tt>gsvXYw32.exe</tt> from this site, try [ftp://ftp.mirror.ac.uk/sites/mirror.cs.wisc.edu/pub/mirrors/ghost/ghostgum/ this site] instead.)<br />
# When the download is complete, browse to <tt>D:\downloads\Ghostscript</tt> in your files and double-click on the .exe file <tt>gsvXYw32.exe</tt>. This will bring you to an installation window. Click Setup.<br />
# After it extracts the necessary files, there will be a new installation window. Click Next twice, and there will be two checkboxes, which can set GSview to be the default eps or pdf previewer. If you wish to use the more common Acrobat Reader, or some other pdf reader, to view pdf files, only leave the first box checked. However, you can check both if desired.<br />
# Click Next, and choose the directory in which you want GSview installed (or leave the default setting, <tt>C:\Program Files\Ghostgum</tt>). <br />
# Click Next twice, and choose the Start Menu folder to which a shortcut will be added. (The default is Ghostgum.)<br />
# Click Finish, and GSview will be installed.<br />
<br />
== Ghostscript ==<br />
Ghostscript may also need to be installed on your system. You may download it [http://pages.cs.wisc.edu/~ghost here] by clicking on the second link down, GPL Ghostscript. Then, click on the first link down, and copy the file to your computer. After that, run it to install Ghostscript. You may then need to set the version of Ghostscript in GSview. Do this by choosing the <tt>Easy Configure</tt> option in the <tt>Options</tt> menu in GSview.<br />
<br />
You now have installed everything you need to use Asymptote on the most basic level, as described in the next section.<br />
<br />
:[[Asymptote: Getting Started/Windows/Interactive Mode| Next: Interactive Mode]]</div>Anstarhttps://artofproblemsolving.com/wiki/index.php?title=Basic_Programming_With_Python&diff=132196Basic Programming With Python2020-08-20T01:17:17Z<p>Anstar: /* methods */</p>
<hr />
<div>'''Important: It is extremely recommended that you read [[Getting Started With Python Programming]] before reading this unless you already know some programming knowledge.'''<br />
<br />
(Note: This is a really long article. To learn the most from this article, you need to read everything in order and skip nothing, unless you are '''absolutely absolutely sure that that content is way too easy for you.''')<br />
<br />
This article will talk about some basic Python programming. If you don't even know how to install Python, look [[Getting Started With Python Programming|here]].<br />
<br />
Note that this article has lots of program examples. It is recommended (but not required) to try these on your own before looking at the solutions.<br />
<br />
==Loops==<br />
<br />
There are two different kinds of loops in Python: the for loop and the while loop.<br />
<br />
===The For Loop===<br />
<br />
The for loop iterates over a list, or an array, of objects. You have probably seen this code before:<br />
<br />
[[File:Capture.PNG|200px]]<br />
<br />
This for loop iterates over the list of integers from 1 to 51, excluding the 51 and including the 1. That means it is a list from 1 to 50, inclusive. On every iteration, Python will print the number that the loop is iterating through. <br />
<br />
For example, in the first iteration, i = 1, so Python prints 1.<br />
<br />
In the second iteration, i = 2, so Python prints 2.<br />
<br />
This continues so on until the number, 50, is reached. Therefore, the last number Python will print out is 50.<br />
<br />
====Program Example====<br />
<br />
'''Find <math>\sum_{n=1}^{50} 2^{n}.</math>'''<br />
<br />
To do this task, we must create a for loop and loop over the integers from 1 to 50 inclusive:<br />
<br />
for i in range(1,51):<br />
<br />
Now what? We must keep a running total and increase it by <math>2^i</math> every time:<br />
<br />
total = 0<br />
for i in range(1,51):<br />
total += 2**i<br />
<br />
We must not forget to print the total at the end!<br />
<br />
total = 0<br />
for i in range(1,51):<br />
total += 2**i<br />
print(total)<br />
<br />
You must exit out of the for loop one you reach the print(total) line by pressing backspace.<br />
<br />
Once you run your program, you should get an answer of <math>\boxed{2,251,799,813,685,246.}</math><br />
<br />
===The While Loop===<br />
<br />
While loops don't loop over a list. They loop over and over and over...'''until'''...a condition becomes false.<br />
<br />
i = 3<br />
total = 0<br />
while i < 1000:<br />
total += i<br />
i += 3<br />
print(total)<br />
<br />
In this code, the while loop loops 333 times, until <math>i</math> becomes greater than or equal to 1000.<br />
<br />
====Program Example====<br />
<br />
'''Find <math>\sum_{n=1}^{50} 2^n</math> using a while loop.'''<br />
<br />
We must create a while loop that will iterate until n is greater than <math>50.</math><br />
<br />
n = 1<br />
total = 0<br />
while n <= 50:<br />
total += 2**n<br />
n += 1<br />
print(total)<br />
<br />
We must not forget to include the n += 1 line at the end of the while loop! <br />
<br />
If we run this, we will get the same answer as last time, <math>2,251,799,813,685,246.</math><br />
<br />
==Functions==<br />
<br />
In this section, we will define new operations and do arithmetic with them in Python.<br />
<br />
===The New Operation===<br />
Let's say that you defined a new binary operation, the <math>\uparrow \downarrow.</math> You want it to be so <math>a \uparrow \downarrow b = a^{b}b^{a}.</math> Therefore, <math>1\uparrow \downarrow 2 = 1^{2}2^{1}=1\cdot 2= 2,</math> and <math>2\uparrow \downarrow 3 = 2^33^2 = 8\cdot 9 = 72.</math> Let's call this operation an '''up down arrow.'''<br />
<br />
===Program Example 1===<br />
<br />
'''Find <math>[2 \uparrow \downarrow (1 \uparrow \downarrow 2)] \uparrow \downarrow 2.</math>'''<br />
<br />
We know this will be a big number, so we should write a program to do it! We certainly don't want to do the exponentiation and multiplication every time we use the operation in our program, and that's where functions come in! Functions can take in parameters (<math>a</math> and <math>b</math>) and return a result depending on the parameters.<br />
<br />
def up_down_arrow(a,b): <br />
return ((a**b) * (b**a))<br />
<br />
Above is the code to define our function. We need to print the final result at the end, so we must put a print statement at the end.<br />
<br />
def up_down_arrow(a,b): <br />
return ((a**b) * (b**a))<br />
print(up_down_arrow(up_down_arrow(2,up_down_arrow(1,2)),2)<br />
<br />
All those nested up_down_arrow's might be confusing at first, but it really isn't that confusing.<br />
If you run your program, you should get your answer: <math>16,777,216.</math> <br />
<br />
You might be surprised that the answer is so big. If you actually start calculating the real answer without a program, you will really quickly find that the final result is <math>16 \uparrow \downarrow 2,</math> which does turn out to be 16,777,216 if you use a calculator.<br />
<br />
Let's make another operation!<br />
<br />
We will define the operation <math>\uparrow \downarrow \leftarrow \rightarrow</math> to be called '''all around.''' <math>a \uparrow \downarrow \leftarrow \rightarrow b = (ab(a \uparrow \downarrow b))^2.</math> That's an operation that will make really big numbers!<br />
<br />
===Program Example 2===<br />
<br />
'''Find 87 all around 132.'''<br />
<br />
The answer is bound to be a huge number, so we must make a program to solve it.<br />
<br />
We will keep our up_down_arrow function because in the definition of our all_around function we will use it. Then, we will define the all_around function.<br />
<br />
def up_down_arrow(a,b):<br />
return ((a**b) * (b**a))<br />
def all_around(a,b):<br />
return ((a * b * up_down_arrow(a,b)) ** 2)<br />
<br />
We must print all_around(87,132) at the end. Once we do that, and we run our program, we get a super huge number that has over 800 digits!<br />
<br />
===Understanding Functions===<br />
<br />
Every single function has a '''return value'''. If a function does not return anything, the return value is '''null'''. Null is a term used in programming as a placeholder that stands for nothing.<br />
<br />
====Simple Program Example 1====<br />
<br />
'''Define a function that adds 1 to an input.'''<br />
<br />
How will the function know what number to add 1 to? We will input a '''parameter''' for the function to add 1 to.<br />
<br />
def add_one(x):<br />
return x + 1<br />
<br />
In this function, <math>x</math> is the parameter.<br />
<br />
def add_one(x):<br />
return x + 1<br />
print(add_one(2))<br />
<br />
In the print statement, we set <math>x</math> as 2, and the function returns <math>2 + 1 = 3,</math> so the program prints <math>3</math>.<br />
<br />
====Simple Program Example 2====<br />
<br />
'''Define a function that prints out an input.'''<br />
<br />
We will use a parameter again.<br />
<br />
def print_function(x):<br />
print(x)<br />
<br />
Uh oh! We have nothing to return! Therefore, we will return nothing (or null), by just writing return.<br />
<br />
def print_function(x):<br />
print(x)<br />
return<br />
print_function("print_function")<br />
<br />
This code prints out print_function. print_function() is said to be '''called''' in the final line of the code. Again, we set <math>x</math>, our parameter, as "print_function."<br />
== Classes ==<br />
Classes are <br />
<br />
===Defining a class===<br />
We can define a class by doing the following:<br />
<br />
<br />
class Example:<br />
pass<br />
<br />
Usually, classes use CamelCase convention.<br />
We can call a class by doing the following<br />
<br />
===methods===<br />
methods are functions that apply to a class.<br />
<br />
===__init__===<br />
===__str__===<br />
===overloading===<br />
overloading means changing a builtin function to do what you want it to do.<br />
<br />
==Flow==<br />
<br />
Flow consists of if statements, elif (else if) statements, and else statements.<br />
<br />
*An if statement checks if a comparison is true.<br />
<br />
*An else statement checks if a comparison is not true. It is used after an if statement (and all elif statements after the if statement) and it shares the same comparison as the if statement.<br />
<br />
*An elif statement checks for two things: if a comparison is true, and if a comparison is not true. It is used right after the if statement.<br />
<br />
===Program Example===<br />
<br />
'''Does the number 10 have the property that when you multiply 10 by 5, you get a two digit number?'''<br />
<br />
This problem is super easy to solve without a program, but let's write a program to solve this anyway. We will use an if statement to check if <math>10\cdot 5</math> is less than 100 and greater than 9.<br />
<br />
if 10*5 > 9:<br />
if 10*5 < 100:<br />
print("Yes")<br />
else:<br />
print("No")<br />
else:<br />
print("No")<br />
<br />
This code means, if 10*5 > 9, then we will check if it is less than 100. If it is not greater than 9, however, we will print No. If it is greater than 9, we check if it is less than 100. If it is, we print Yes. If it isn't we print No.<br />
<br />
These nested if statements can be very confusing. Luckily, there is a faster an easier way to do this.<br />
<br />
if 10*5 > 9 and 10*5 < 100:<br />
print("Yes") <br />
else:<br />
print("No")<br />
<br />
This code checks for the two conditions at the same time. If we run it, we get our answer of Yes.<br />
<br />
==Booleans==<br />
<br />
===Program Example===<br />
<br />
'''Print all two-digit positive integers <math>x</math> such that <math>5x</math> is a two-digit positive integer.'''<br />
<br />
We can create a function with our previous code.<br />
<br />
We will have to slightly modify our function so we can use it in a for loop at the end:<br />
<br />
def check(a):<br />
if a*5 > 9 and a*5 < 100:<br />
return True <br />
else:<br />
return False<br />
<br />
True and False are what are called '''booleans'''. When an if or elif statement receives True, the code inside of the statement happens. When an if or elif statement receives False, the code inside of the statement does not happen. <br />
<br />
We must create a for loop that will iterate through all two digit positive integers. <br />
<br />
def check(a):<br />
if a*5 > 9 and a*5 < 100:<br />
return True <br />
else:<br />
return False<br />
for i in range(10,100):<br />
if check(i):<br />
print(i)<br />
<br />
The final for loop checks if <math>5i</math> is a two digit integer. If it is, the function returns True and the code inside the if statement gets run. If it isn't, the function returns False and the code inside the if statement gets ignored.<br />
<br />
If we run this, we will get the answer.<br />
<br />
All two digit integers from 10 to 19 inclusive work!<br />
<br />
=="Soft Coding" Programs==<br />
<br />
In the next few examples, you will see why hard coding programs is bad. Hard coding programs refers to coding a program that is hard to modify. For example:<br />
<br />
===Program Example 1===<br />
<br />
'''Print all two digit positive integers <math>x</math> such that <math>5x</math> is a three digit positive integer.'''<br />
<br />
We can keep our code and modify some parts of it.<br />
<br />
def check(a, min, max):<br />
if a*5 > min - 1 and a*5 < max + 1:<br />
return True <br />
else:<br />
return False<br />
<br />
def print_check(range_min, range_max, check_min, check_max):<br />
for i in range(range_min, range_max + 1):<br />
if check(i, check_min, check_max):<br />
print(i)<br />
return<br />
<br />
print_check(10, 99, 100, 999)<br />
<br />
Why did we add so many functions?<br />
<br />
Well, if the numbers in a problem change (and the words stay the same), and you need to change a lot of numbers in your program, your program is considered '''hard-coded'''. We want our programs to be as '''soft-coded''' as possible. In our new program, we only need to change 4 numbers (in the print_check() statement) if the numbers in the problem change. Therefore, our program is relatively soft-coded. There are still ways to soft-code this program even more, though.<br />
<br />
If we run our program, we get our answer.<br />
<br />
All numbers from 20 to 99 work!<br />
<br />
===Program Example 2===<br />
<br />
'''Print all three digit positive integers <math>x</math> such that <math>5x</math> is a three digit positive integer.'''<br />
<br />
We can just change the print_check line at the end to<br />
<br />
print_check(100, 999, 100, 999)<br />
<br />
and our program will be ready to be run.<br />
<br />
All numbers from 100 to 199 work.<br />
<br />
===Program Example 3===<br />
<br />
'''Print all two digit positive integers <math>x</math> such that <math>3x</math> is a three digit positive integer.'''<br />
<br />
Uh oh. Only changing the print_check line won't work. We will need to change our functions!<br />
<br />
def check(a, min, max, factor):<br />
if a*factor > min - 1 and a*factor < max + 1:<br />
return True <br />
else:<br />
return False<br />
<br />
def print_check(range_min, range_max, check_min, check_max, check_factor):<br />
for i in range(range_min, range_max + 1):<br />
if check(i, check_min, check_max, check_factor):<br />
print(i)<br />
return<br />
<br />
print_check(10, 99, 100, 999, 3)<br />
<br />
In this step, we added a parameter in both functions. We also soft-coded our program even more! Hooray!<br />
<br />
All integers from 34 to 99 work.<br />
<br />
===Program Example 4===<br />
<br />
'''Print all two digit positive integers <math>x</math> such that <math>12x</math> is a positive integer from 500 to 900.'''<br />
<br />
This problem may look a bit different from the other ones, but it really is the same thing, except that the factor is 12 and check_min and check_max are 500 and 900, respectively.<br />
<br />
Once we change the final print_check() line to satisfy our needs, we can run our program.<br />
<br />
All numbers from 42 to 75 work!<br />
<br />
Congrats! You have written your first programs above 10 lines of code!<br />
<br />
==Random==<br />
<br />
There is a package in Python that allows the use of random numbers.<br />
<br />
===Program Example 1===<br />
<br />
'''Generate a random number from 1 to 6.'''<br />
<br />
Easy peasy. We will just generate a random number from 1 to 6 with the package like this:<br />
<br />
import random<br />
print(random.randint(1,6))<br />
<br />
As you can see, when you run this program, you get a random integer from 1 to 6.<br />
<br />
===Program Example 2===<br />
<br />
'''Simulate the rolling of 1000 dice. Now, count the number of times you roll 6. Print that number out.'''<br />
<br />
We can create a function that returns a random number from 1 to 6. Then, we can make a for loop that rolls the dice 1000 times and check if it is a 6.<br />
<br />
import random<br />
count = 0<br />
<br />
def roll():<br />
return random.randint(1,6)<br />
<br />
for i in range(1, 1001):<br />
if roll() == 6:<br />
count += 1<br />
<br />
print(count)<br />
<br />
If we run this, we will get a number around 170.<br />
<br />
===Program Example 3===<br />
<br />
'''Simulate the rolling of 10,000 dice. Now, count the amount of times you roll 3. Print that amount out.'''<br />
<br />
We can keep our roll function and our code inside the for loop, but we need to change our for loop statement.<br />
<br />
We can actually soft-code our program more. Let's turn the whole for loop into a function!<br />
<br />
import random<br />
<br />
def roll():<br />
return random.randint(1,6)<br />
<br />
def count(amount):<br />
count_ = 0<br />
<br />
for i in range(1, amount+1):<br />
if roll() == 3:<br />
count_ += 1<br />
return count_<br />
<br />
print(count(10000))<br />
<br />
If we run this code, it works.<br />
<br />
===Program Example 4===<br />
<br />
'''One of my friends loves rolling dice. He is going to roll 1 die tomorrow, 2 dice two days from now, 3 dice three days from now, and so on so that he rolls <math>a</math> dice <math>a</math> days from now. He gets tired rolling dice after rolling dice for 365 days (so the last day he rolls 365 dice). In Python, simulate this. How many times does he roll 3 after 365 days of rolling dice?'''<br />
<br />
We can use a for loop that calls a function multiple times.<br />
<br />
import random<br />
<br />
def roll():<br />
return random.randint(1,6)<br />
<br />
def count(amount):<br />
count_ = 0<br />
for i in range(1, amount+1):<br />
if roll() == 3:<br />
count_ += 1<br />
return count_<br />
<br />
total = 0<br />
<br />
for i in range(1, 366):<br />
total += count(i)<br />
<br />
print(total)<br />
<br />
This is a really long program, but the whole program should make sense if you look at it for a while. We defined our count function in the previous example, and now we are using it with a for loop and a running total. <br />
<br />
You should get a number around 11,000 when you run it. Wow, lots of 3's!<br />
<br />
===Program Example 5===<br />
<br />
'''20 of my friends love rolling dice. They are all going to roll 1 die each tomorrow, 2 dice each two days from now, 3 dice each three days from now, and so on so that they roll <math>a</math> dice each <math>a</math> days from now. But, one of my friends gets tired very quickly and he only rolls dice for 1 day and stops. Another friend only will roll dice for 2 days, and another will roll dice for three days only, and so on up to the fact that my last friend will roll dice for 20 days. In Python, simulate this. How many times does someone roll 3 after everything?'''<br />
<br />
We will have to make our for loop into a function again.<br />
<br />
import random<br />
<br />
def roll():<br />
return random.randint(1,6)<br />
<br />
def count(amount):<br />
count_ = 0<br />
for i in range(1, amount+1):<br />
if roll() == 3:<br />
count_ += 1<br />
return count_<br />
<br />
def count2(amount)<br />
total = 0<br />
for i in range(1, amount + 1):<br />
total += count(i)<br />
return total<br />
<br />
def count3(amount)<br />
total = 0<br />
for i in range(1, amount + 1):<br />
total += count2(i)<br />
return total<br />
<br />
print(count3(20))<br />
<br />
(Our program is so long!)<br />
<br />
I also made a new function just in case we needed to turn that into a function later.<br />
<br />
'''Make sure''' you read the code carefully and you fully understand it. If you don't understand every single line of code, then you will get confused later on in this article.<br />
<br />
When you run this program, you might be surprised that the answer isn't so big.<br />
<br />
===Program Example 6===<br />
<br />
'''365 of my friends love rolling dice. They are all going to roll 1 die each tomorrow, 2 dice each two days from now, 3 dice each three days from now, and so on so that they roll <math>a</math> dice each <math>a</math> days from now. But, one of my friends gets tired very quickly and he only rolls dice for 1 day and stops. Another friend only will roll dice for 2 days, and another will roll dice for three days only, and so on up to the fact that my last friend will roll dice for 365 days. In Python, simulate this. How many times does someone roll 3 after everything?'''<br />
<br />
Because we soft-coded our program so much, all we have to do is change the last line so the parameter of count3() is 365.<br />
<br />
If we run it...we get a big answer, as expected. It also takes quite a while!<br />
<br />
You may not have realized that we soft-coded our program at all, but the whole point of functions is to soft-code programs!<br />
<br />
Congrats on writing a program that is around 25 lines long!<br />
<br />
==Very Basic Datatypes==<br />
<br />
An integer is a basic datatype in Python. Basically, all variables with the datatype of '''int''' is an integer.<br />
<br />
A string is another basic datatype, and it is a string of characters enclosed by quotes.<br />
<br />
===Why Are Datatypes So Important?===<br />
<br />
Let's say we wanted to make a program that would add 2 and 3. Some bogus code would be:<br />
<br />
x="2"<br />
y="3"<br />
print(x+y)<br />
<br />
If you ran this code, you would get 23. Why is that?<br />
<br />
Well, here, x and y are strings. When you perform the addition operator to strings in Python, it concatenates the strings, giving 23.<br />
<br />
The real code is:<br />
<br />
x=2<br />
y=3<br />
print(x+y)<br />
<br />
If you run this, you will get <math>5</math>, which is correct.<br />
<br />
Here's another reason datatypes are important. Now, we will introduce the datatype called the '''floating point number''', or '''float'''. A floating-point number is a number with a decimal point.<br />
<br />
Let's go back to the IDLE. Type "0.1*10". The result is 1.0. Notice the decimal point.<br />
<br />
Let's type something different. Type <math>0.1+0.1+0.1+0.1+0.1+0.1+0.1+0.1+0.1+0.1.</math><br />
<br />
'''WHAT!?'''<br />
<br />
You would have expected the answer to be 1, but it isn't 1. What happened?<br />
<br />
'''Float approximation''' happened. Most (almost all) programming languages have a bad float approximation. That means that 1.0 can turn into 0.99999999999999 and 0.5 can turn into 0.49999999999999999993. That only happens with floats, so we should try to use floats as sparingly as possible.<br />
<br />
==Lists==<br />
<br />
A for loop iterates over a '''list'''. A list is a bunch of objects stored in one variable. (Hey! A list is a datatype!) For loops are highly related to lists.<br />
<br />
Let's say we wanted to make a program to print all the items in a list.<br />
<br />
We will first create the list, using the code:<br />
<br />
myList = [1,4,6,8]<br />
<br />
This is a list with four items: 1, 4, 6, and 8.<br />
<br />
We must now print all elements of it with a for loop:<br />
<br />
myList = [1,4,6,8]<br />
for i in myList:<br />
print(i)<br />
<br />
When we run this program, we get the numbers 1, 4, 6, and 8, as expected.<br />
<br />
===Accessing Values===<br />
<br />
Let's say we wanted to print out the second item in a list. We will use '''indexes'''.<br />
<br />
The index of the first item in a list is always 0. The index of the second is 1. The index of the <math>n</math>th is <math>n-1.</math><br />
<br />
To print out the second item, we will use an index of 1, like this:<br />
<br />
myList = [1,4,6,8]<br />
print(myList[1])<br />
<br />
Notice that the index is inside of the square brackets.<br />
<br />
===Adding Values===<br />
<br />
We can use the list.append() function to add an object to the end of a list.<br />
<br />
myList.append(10)<br />
<br />
will add 10 to the list, which makes myList = [1,4,6,8,10].<br />
<br />
===Removing Items From Lists===<br />
<br />
We can use the list.remove() function to remove a specific item in a list.<br />
<br />
For example, consider this code.<br />
<br />
myList = [1,2,3]<br />
myList.remove(3)<br />
<br />
This code will make myList turn into [1,2]. The element, 3, gets removed.<br />
<br />
===len(list)===<br />
<br />
The len(list) function returns the length of a list.<br />
<br />
This code will print 3.<br />
<br />
myList = [1,2,3]<br />
print(len(myList))<br />
<br />
The length of myList is 3, so Python prints 3.<br />
<br />
===All Kinds Of Lists===<br />
<br />
Lists don't have to be only integers!<br />
<br />
myList = [1,"Hi","Hello world", 3.5, 3.14159265358979323]<br />
<br />
If fact, there can be lists inside of lists!<br />
<br />
myList = [[1,2,3], [3,4,5], [5,6,"Hello world"], "BOB", 3.1415926]<br />
<br />
Even this!<br />
<br />
myList = [[1, [1, [1,2,3],3],3], [[[3,["Hello world", 4],5],4,5],4,5], [5,6,7,[1,[1,2,3],3],"Hello world"], "BOB", 3.1415926, True]<br />
<br />
If you look at that list carefully, you will find lists inside of lists inside of lists inside of lists! And, a boolean at the end!<br />
<br />
Like variables, you can have as many lists in a program as you want (a list is a variable)!<br />
<br />
myList = [1,2,3,4]<br />
yourList = [5,6,7,8]<br />
hisList = [9,10,11,12]<br />
herList = [13,14,15,16]<br />
theirList = [17,18,19,20]<br />
ourList = [21,22,23,24]<br />
listsOfLists = [[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16],[17,18,19,20],[21,22,23,24]]<br />
<br />
===Splitting Lists===<br />
Split Operator Basics:<br />
genericList[where to start:where to end:what size steps to take]<br />
The value where to start is inclusive, and denotes the index where your split list begins. It has a default value of 0.<br />
The value where to end is exclusive, and denotes the index where your split list ends. It has a default value of len(genericList).<br />
The value what size steps denotes the size of the steps your split takes(more on that later). It has a default value of 1.<br />
Say you want to split a list and only return certain indices, for example if you wanted to split a list called data and put the first two elements into a list called head and the last two into a list called tail, you would split like this:<br />
data = [1, 3, 4, 23.5, 40, 55]<br />
head = data[:2]<br />
tail = data[-2:] # negative list indices represent the end of a list, so -1 is the last element and -2 is the second-to-last<br />
Step Size:<br />
We will practice writing a few functions that select every other element and will reverse in a list using step size.<br />
A step size of two means skip every other list index, so we can write our first function.<br />
def selectEveryOtherElement(list):<br />
return list[::2]<br />
But which step size will get us our desired reversed list. We could start at the end of the list and iterate backwards, but how would we do that...<br />
Negative Step Size:<br />
A step size that is negative means skip a certain amount of elements, but backwards. If we were to start at 0, with a step size of -1, we would be able to iterate backwards over the list!<br />
def reverse(list):<br />
return list[::-1]<br />
Splitting lists with ratios:<br />
What if we wanted to be able to split a list based upon a ratio. For example, the common 80:20 train to test ratio in machine learning? Here is how you would do it<br />
def eighty-twenty(list):<br />
train = list[:int(len(list) * (4 / 5))] # We must include the int() method to convert to an integer if len(list) % 5 != 0<br />
test = list[int(len(list) * 4 / 5)]<br />
return [train, test] # We then return a list with the train and test lists inside<br />
<br />
==Dictionaries==<br />
<br />
A dictionary (a type of datatype) is a bunch of keys and values. There is a major difference between dictionaries and lists. Lists are ordered; dictionaries are not.<br />
<br />
Here is the '''syntax''' of creating a dictionary:<br />
<br />
myDictionary = {1:"one",2:"two"}<br />
<br />
This dictionary has two key/value pairs. Notice it is surrounded in curly braces. The keys are 1 and 2; the values are "one" and "two."<br />
<br />
How is this useful? Let's make a simple program to test it out.<br />
<br />
myDictionary = {1:"one",2:"two"}<br />
print(myDictionary[1])<br />
print(myDictionary[2])<br />
<br />
===Accessing Values===<br />
<br />
To access a value in a dictionary, you put in the key.<br />
<br />
myDictionary[1]<br />
<br />
returns one, because 1 is the key to "one."<br />
<br />
===Adding New Values===<br />
<br />
To overwrite a value, we do this.<br />
<br />
myDictionary[1] = "won"<br />
<br />
The value to the key 1 is now "won."<br />
<br />
To add a value, we do the same thing!<br />
<br />
myDictionary[3] = "three"<br />
<br />
This adds a key 3 with a value of "three."<br />
<br />
==Misc Concepts==<br />
<br />
This section will talk about some concepts that we haven't learned yet.<br />
<br />
====Concatenating Strings====<br />
<br />
Concatenating strings is putting them together. For example, "one" concatenated with "two" gives "onetwo."<br />
<br />
The following string,<br />
<br />
"Hello, " + person2 + "! How are you?"<br />
<br />
depends on what person2 was. If person2 was Bob, the string would be:<br />
<br />
"Hello, Bob! How are you?"<br />
<br />
It fits together perfectly!<br />
<br />
You cannot concatenate strings with integers. For example, doing this:<br />
<br />
"2" + 3<br />
<br />
will not work. Instead, to get an answer of "23", you must do this:<br />
<br />
"2" + str(3)<br />
<br />
That turns 3 into a string so it is "3", and the result will be "23".<br />
<br />
====Line Breaks====<br />
<br />
We can use multiple line breaks to make our code more organized. There are some places that you cannot line break. For example, this code will produce an error:<br />
<br />
myList =<br />
[1,2,3]<br />
<br />
This code does not work.<br />
<br />
This code '''does work''':<br />
<br />
myList = [<br />
1,2,3]<br />
<br />
It is accepted when you break a line right after the [. It is also accepted right after a comma. (And right before the ending ].)<br />
<br />
myList = [<br />
1,<br />
2,<br />
3<br />
]<br />
<br />
==Challenge Program==<br />
<br />
In this section, we will attempt the hardest program so far in this article.<br />
<br />
'''Make a conversation generator that will generate random conversations between different people.'''<br />
<br />
First, we will generate the people. We can use a list and generate two random numbers.<br />
<br />
import random<br />
<br />
peopleNames = [<br />
"Bob",<br />
"Kyle",<br />
"James",<br />
"Richard",<br />
"Zachary",<br />
"Olivia",<br />
"Jonathan",<br />
"Will",<br />
"Bobby",<br />
"Kevin"<br />
]<br />
person1 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
peopleNames.remove(person1)<br />
person2 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
<br />
(I made it more organized by separating the long lines of code into multiple lines. It only works when you have a line break right after each item in the list.)<br />
<br />
Here, we use the remove() function to remove person1 from the list to make sure we don't use the same name twice. <br />
<br />
We also used the len() function to find the length of the list (soft-coding!)<br />
<br />
Now, we need to create a list of possible values for the first thing that person1 says (person1 will always be the first one to talk). <br />
<br />
Then, we will print it out.<br />
<br />
import random<br />
<br />
peopleNames = [<br />
"Bob",<br />
"Kyle",<br />
"James",<br />
"Richard",<br />
"Zachary",<br />
"Olivia",<br />
"Jonathan",<br />
"Will",<br />
"Bobby",<br />
"Kevin"<br />
]<br />
person1 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
peopleNames.remove(person1)<br />
person2 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
<br />
first = [<br />
"Hi!",<br />
"Hello!",<br />
"Good morning!",<br />
"Hello, " + person2 + "!",<br />
"Hi.",<br />
"Hi, " + person2 + "!"<br />
]<br />
print(person1 + ": " + first[random.randint(0, (len(first) - 1))])<br />
<br />
If we test out this program, we can confirm that this part indeed does work. This program is already getting long! Now, we will use the same method and create the second message.<br />
<br />
import random<br />
<br />
peopleNames = [<br />
"Bob",<br />
"Kyle",<br />
"James",<br />
"Richard",<br />
"Zachary",<br />
"Olivia",<br />
"Jonathan",<br />
"Will",<br />
"Bobby",<br />
"Kevin"<br />
]<br />
person1 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
peopleNames.remove(person1)<br />
person2 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
<br />
first = [<br />
"Hi!",<br />
"Hello!",<br />
"Good morning!",<br />
"Hello, " + person2 + "!",<br />
"Hi.",<br />
"Hi, " + person2 + "!"<br />
]<br />
print(person1 + ": " + first[random.randint(0, (len(first) - 1))])<br />
<br />
second = [<br />
"Hi! How are you today?",<br />
"Hello! How are you?",<br />
"Good morning! How are you today?",<br />
"Hello, " + person1 + "! How are you?",<br />
"Hi. How are you?",<br />
"Hi, " + person1 + "! How are you today?"<br />
]<br />
print(person2 + ": " + second[random.randint(0, (len(second) - 1))])<br />
<br />
We will repeat this for the rest of the conversation:<br />
<br />
import random<br />
<br />
peopleNames = [<br />
"Bob",<br />
"Kyle",<br />
"James",<br />
"Richard",<br />
"Zachary",<br />
"Olivia",<br />
"Jonathan",<br />
"Will", <br />
"Bobby",<br />
"Kevin"<br />
]<br />
person1 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
peopleNames.remove(person1)<br />
person2 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
<br />
first = [<br />
"Hi!",<br />
"Hello!",<br />
"Good morning!",<br />
"Hello, " + person2 + "!",<br />
"Hi.",<br />
"Hi, " + person2 + "!"<br />
]<br />
print(person1 + ": " + first[random.randint(0, (len(first) - 1))])<br />
<br />
second = [<br />
"Hi! How are you today?",<br />
"Hello! How are you?",<br />
"Good morning! How are you today?",<br />
"Hello, " + person1 + "! How are you?",<br />
"Hi. How are you?",<br />
"Hi, " + person1 + "! How are you today?"<br />
]<br />
print(person2 + ": " + second[random.randint(0, (len(second) - 1))])<br />
<br />
third = [<br />
"I'm feeling awesome! And you?",<br />
"I'm feeling alright! How are you?",<br />
"I'm good, thank you. How are you feeling?",<br />
"I'm fine!" ,<br />
"How are you today?"<br />
]<br />
print(person1 + ": " + third[random.randint(0, (len(third) - 1))])<br />
<br />
fourth = [<br />
"I'm feeling great!",<br />
"I'm awesome!",<br />
"Thanks for asking! I am feeling good today!",<br />
"I'm feeling awesome today! Yippee!"<br />
] <br />
print(person2 + ": " + fourth[random.randint(0, (len(fourth) - 1))])<br />
<br />
fifth = [<br />
"It's so nice out today!",<br />
"Today is such a cloudy day.",<br />
"I hate it when it is so cloudy outside!",<br />
"It's partly cloudy today!"<br />
]<br />
print(person1 + ": " + fifth[random.randint(0, (len(fifth) - 1))])<br />
<br />
sixth = [<br />
"I know, right?",<br />
"I know.",<br />
"Yeah!",<br />
"True."<br />
]<br />
print(person2 + ": " + sixth[random.randint(0, (len(sixth) - 1))])<br />
<br />
seventh = [<br />
"Sorry, I need to leave. Bye!",<br />
"I gotta go. Bye!",<br />
"Sorry, I don't have time to stay and chat. I've got to go somewhere. Bye!"<br />
]<br />
print(person1 + ": " + seventh[random.randint(0, (len(seventh) - 1))])<br />
<br />
eighth = [<br />
"Bye!",<br />
"Good-bye!",<br />
"Bye, " + person1 + "."<br />
]<br />
print(person2 + ": " + eighth[random.randint(0, (len(eighth) - 1))])<br />
<br />
Whew! So long!<br />
<br />
Once we run our program. It works! This program really wasn't that hard.<br />
<br />
Congrats! You've made it so far!</div>Anstarhttps://artofproblemsolving.com/wiki/index.php?title=Basic_Programming_With_Python&diff=132195Basic Programming With Python2020-08-20T01:16:58Z<p>Anstar: /* Defining a class */</p>
<hr />
<div>'''Important: It is extremely recommended that you read [[Getting Started With Python Programming]] before reading this unless you already know some programming knowledge.'''<br />
<br />
(Note: This is a really long article. To learn the most from this article, you need to read everything in order and skip nothing, unless you are '''absolutely absolutely sure that that content is way too easy for you.''')<br />
<br />
This article will talk about some basic Python programming. If you don't even know how to install Python, look [[Getting Started With Python Programming|here]].<br />
<br />
Note that this article has lots of program examples. It is recommended (but not required) to try these on your own before looking at the solutions.<br />
<br />
==Loops==<br />
<br />
There are two different kinds of loops in Python: the for loop and the while loop.<br />
<br />
===The For Loop===<br />
<br />
The for loop iterates over a list, or an array, of objects. You have probably seen this code before:<br />
<br />
[[File:Capture.PNG|200px]]<br />
<br />
This for loop iterates over the list of integers from 1 to 51, excluding the 51 and including the 1. That means it is a list from 1 to 50, inclusive. On every iteration, Python will print the number that the loop is iterating through. <br />
<br />
For example, in the first iteration, i = 1, so Python prints 1.<br />
<br />
In the second iteration, i = 2, so Python prints 2.<br />
<br />
This continues so on until the number, 50, is reached. Therefore, the last number Python will print out is 50.<br />
<br />
====Program Example====<br />
<br />
'''Find <math>\sum_{n=1}^{50} 2^{n}.</math>'''<br />
<br />
To do this task, we must create a for loop and loop over the integers from 1 to 50 inclusive:<br />
<br />
for i in range(1,51):<br />
<br />
Now what? We must keep a running total and increase it by <math>2^i</math> every time:<br />
<br />
total = 0<br />
for i in range(1,51):<br />
total += 2**i<br />
<br />
We must not forget to print the total at the end!<br />
<br />
total = 0<br />
for i in range(1,51):<br />
total += 2**i<br />
print(total)<br />
<br />
You must exit out of the for loop one you reach the print(total) line by pressing backspace.<br />
<br />
Once you run your program, you should get an answer of <math>\boxed{2,251,799,813,685,246.}</math><br />
<br />
===The While Loop===<br />
<br />
While loops don't loop over a list. They loop over and over and over...'''until'''...a condition becomes false.<br />
<br />
i = 3<br />
total = 0<br />
while i < 1000:<br />
total += i<br />
i += 3<br />
print(total)<br />
<br />
In this code, the while loop loops 333 times, until <math>i</math> becomes greater than or equal to 1000.<br />
<br />
====Program Example====<br />
<br />
'''Find <math>\sum_{n=1}^{50} 2^n</math> using a while loop.'''<br />
<br />
We must create a while loop that will iterate until n is greater than <math>50.</math><br />
<br />
n = 1<br />
total = 0<br />
while n <= 50:<br />
total += 2**n<br />
n += 1<br />
print(total)<br />
<br />
We must not forget to include the n += 1 line at the end of the while loop! <br />
<br />
If we run this, we will get the same answer as last time, <math>2,251,799,813,685,246.</math><br />
<br />
==Functions==<br />
<br />
In this section, we will define new operations and do arithmetic with them in Python.<br />
<br />
===The New Operation===<br />
Let's say that you defined a new binary operation, the <math>\uparrow \downarrow.</math> You want it to be so <math>a \uparrow \downarrow b = a^{b}b^{a}.</math> Therefore, <math>1\uparrow \downarrow 2 = 1^{2}2^{1}=1\cdot 2= 2,</math> and <math>2\uparrow \downarrow 3 = 2^33^2 = 8\cdot 9 = 72.</math> Let's call this operation an '''up down arrow.'''<br />
<br />
===Program Example 1===<br />
<br />
'''Find <math>[2 \uparrow \downarrow (1 \uparrow \downarrow 2)] \uparrow \downarrow 2.</math>'''<br />
<br />
We know this will be a big number, so we should write a program to do it! We certainly don't want to do the exponentiation and multiplication every time we use the operation in our program, and that's where functions come in! Functions can take in parameters (<math>a</math> and <math>b</math>) and return a result depending on the parameters.<br />
<br />
def up_down_arrow(a,b): <br />
return ((a**b) * (b**a))<br />
<br />
Above is the code to define our function. We need to print the final result at the end, so we must put a print statement at the end.<br />
<br />
def up_down_arrow(a,b): <br />
return ((a**b) * (b**a))<br />
print(up_down_arrow(up_down_arrow(2,up_down_arrow(1,2)),2)<br />
<br />
All those nested up_down_arrow's might be confusing at first, but it really isn't that confusing.<br />
If you run your program, you should get your answer: <math>16,777,216.</math> <br />
<br />
You might be surprised that the answer is so big. If you actually start calculating the real answer without a program, you will really quickly find that the final result is <math>16 \uparrow \downarrow 2,</math> which does turn out to be 16,777,216 if you use a calculator.<br />
<br />
Let's make another operation!<br />
<br />
We will define the operation <math>\uparrow \downarrow \leftarrow \rightarrow</math> to be called '''all around.''' <math>a \uparrow \downarrow \leftarrow \rightarrow b = (ab(a \uparrow \downarrow b))^2.</math> That's an operation that will make really big numbers!<br />
<br />
===Program Example 2===<br />
<br />
'''Find 87 all around 132.'''<br />
<br />
The answer is bound to be a huge number, so we must make a program to solve it.<br />
<br />
We will keep our up_down_arrow function because in the definition of our all_around function we will use it. Then, we will define the all_around function.<br />
<br />
def up_down_arrow(a,b):<br />
return ((a**b) * (b**a))<br />
def all_around(a,b):<br />
return ((a * b * up_down_arrow(a,b)) ** 2)<br />
<br />
We must print all_around(87,132) at the end. Once we do that, and we run our program, we get a super huge number that has over 800 digits!<br />
<br />
===Understanding Functions===<br />
<br />
Every single function has a '''return value'''. If a function does not return anything, the return value is '''null'''. Null is a term used in programming as a placeholder that stands for nothing.<br />
<br />
====Simple Program Example 1====<br />
<br />
'''Define a function that adds 1 to an input.'''<br />
<br />
How will the function know what number to add 1 to? We will input a '''parameter''' for the function to add 1 to.<br />
<br />
def add_one(x):<br />
return x + 1<br />
<br />
In this function, <math>x</math> is the parameter.<br />
<br />
def add_one(x):<br />
return x + 1<br />
print(add_one(2))<br />
<br />
In the print statement, we set <math>x</math> as 2, and the function returns <math>2 + 1 = 3,</math> so the program prints <math>3</math>.<br />
<br />
====Simple Program Example 2====<br />
<br />
'''Define a function that prints out an input.'''<br />
<br />
We will use a parameter again.<br />
<br />
def print_function(x):<br />
print(x)<br />
<br />
Uh oh! We have nothing to return! Therefore, we will return nothing (or null), by just writing return.<br />
<br />
def print_function(x):<br />
print(x)<br />
return<br />
print_function("print_function")<br />
<br />
This code prints out print_function. print_function() is said to be '''called''' in the final line of the code. Again, we set <math>x</math>, our parameter, as "print_function."<br />
== Classes ==<br />
Classes are <br />
<br />
===Defining a class===<br />
We can define a class by doing the following:<br />
<br />
<br />
class Example:<br />
pass<br />
<br />
Usually, classes use CamelCase convention.<br />
We can call a class by doing the following<br />
<br />
===methods===<br />
methods are definition that apply to a class.<br />
===__init__===<br />
===__str__===<br />
===overloading===<br />
overloading means changing a builtin function to do what you want it to do.<br />
<br />
==Flow==<br />
<br />
Flow consists of if statements, elif (else if) statements, and else statements.<br />
<br />
*An if statement checks if a comparison is true.<br />
<br />
*An else statement checks if a comparison is not true. It is used after an if statement (and all elif statements after the if statement) and it shares the same comparison as the if statement.<br />
<br />
*An elif statement checks for two things: if a comparison is true, and if a comparison is not true. It is used right after the if statement.<br />
<br />
===Program Example===<br />
<br />
'''Does the number 10 have the property that when you multiply 10 by 5, you get a two digit number?'''<br />
<br />
This problem is super easy to solve without a program, but let's write a program to solve this anyway. We will use an if statement to check if <math>10\cdot 5</math> is less than 100 and greater than 9.<br />
<br />
if 10*5 > 9:<br />
if 10*5 < 100:<br />
print("Yes")<br />
else:<br />
print("No")<br />
else:<br />
print("No")<br />
<br />
This code means, if 10*5 > 9, then we will check if it is less than 100. If it is not greater than 9, however, we will print No. If it is greater than 9, we check if it is less than 100. If it is, we print Yes. If it isn't we print No.<br />
<br />
These nested if statements can be very confusing. Luckily, there is a faster an easier way to do this.<br />
<br />
if 10*5 > 9 and 10*5 < 100:<br />
print("Yes") <br />
else:<br />
print("No")<br />
<br />
This code checks for the two conditions at the same time. If we run it, we get our answer of Yes.<br />
<br />
==Booleans==<br />
<br />
===Program Example===<br />
<br />
'''Print all two-digit positive integers <math>x</math> such that <math>5x</math> is a two-digit positive integer.'''<br />
<br />
We can create a function with our previous code.<br />
<br />
We will have to slightly modify our function so we can use it in a for loop at the end:<br />
<br />
def check(a):<br />
if a*5 > 9 and a*5 < 100:<br />
return True <br />
else:<br />
return False<br />
<br />
True and False are what are called '''booleans'''. When an if or elif statement receives True, the code inside of the statement happens. When an if or elif statement receives False, the code inside of the statement does not happen. <br />
<br />
We must create a for loop that will iterate through all two digit positive integers. <br />
<br />
def check(a):<br />
if a*5 > 9 and a*5 < 100:<br />
return True <br />
else:<br />
return False<br />
for i in range(10,100):<br />
if check(i):<br />
print(i)<br />
<br />
The final for loop checks if <math>5i</math> is a two digit integer. If it is, the function returns True and the code inside the if statement gets run. If it isn't, the function returns False and the code inside the if statement gets ignored.<br />
<br />
If we run this, we will get the answer.<br />
<br />
All two digit integers from 10 to 19 inclusive work!<br />
<br />
=="Soft Coding" Programs==<br />
<br />
In the next few examples, you will see why hard coding programs is bad. Hard coding programs refers to coding a program that is hard to modify. For example:<br />
<br />
===Program Example 1===<br />
<br />
'''Print all two digit positive integers <math>x</math> such that <math>5x</math> is a three digit positive integer.'''<br />
<br />
We can keep our code and modify some parts of it.<br />
<br />
def check(a, min, max):<br />
if a*5 > min - 1 and a*5 < max + 1:<br />
return True <br />
else:<br />
return False<br />
<br />
def print_check(range_min, range_max, check_min, check_max):<br />
for i in range(range_min, range_max + 1):<br />
if check(i, check_min, check_max):<br />
print(i)<br />
return<br />
<br />
print_check(10, 99, 100, 999)<br />
<br />
Why did we add so many functions?<br />
<br />
Well, if the numbers in a problem change (and the words stay the same), and you need to change a lot of numbers in your program, your program is considered '''hard-coded'''. We want our programs to be as '''soft-coded''' as possible. In our new program, we only need to change 4 numbers (in the print_check() statement) if the numbers in the problem change. Therefore, our program is relatively soft-coded. There are still ways to soft-code this program even more, though.<br />
<br />
If we run our program, we get our answer.<br />
<br />
All numbers from 20 to 99 work!<br />
<br />
===Program Example 2===<br />
<br />
'''Print all three digit positive integers <math>x</math> such that <math>5x</math> is a three digit positive integer.'''<br />
<br />
We can just change the print_check line at the end to<br />
<br />
print_check(100, 999, 100, 999)<br />
<br />
and our program will be ready to be run.<br />
<br />
All numbers from 100 to 199 work.<br />
<br />
===Program Example 3===<br />
<br />
'''Print all two digit positive integers <math>x</math> such that <math>3x</math> is a three digit positive integer.'''<br />
<br />
Uh oh. Only changing the print_check line won't work. We will need to change our functions!<br />
<br />
def check(a, min, max, factor):<br />
if a*factor > min - 1 and a*factor < max + 1:<br />
return True <br />
else:<br />
return False<br />
<br />
def print_check(range_min, range_max, check_min, check_max, check_factor):<br />
for i in range(range_min, range_max + 1):<br />
if check(i, check_min, check_max, check_factor):<br />
print(i)<br />
return<br />
<br />
print_check(10, 99, 100, 999, 3)<br />
<br />
In this step, we added a parameter in both functions. We also soft-coded our program even more! Hooray!<br />
<br />
All integers from 34 to 99 work.<br />
<br />
===Program Example 4===<br />
<br />
'''Print all two digit positive integers <math>x</math> such that <math>12x</math> is a positive integer from 500 to 900.'''<br />
<br />
This problem may look a bit different from the other ones, but it really is the same thing, except that the factor is 12 and check_min and check_max are 500 and 900, respectively.<br />
<br />
Once we change the final print_check() line to satisfy our needs, we can run our program.<br />
<br />
All numbers from 42 to 75 work!<br />
<br />
Congrats! You have written your first programs above 10 lines of code!<br />
<br />
==Random==<br />
<br />
There is a package in Python that allows the use of random numbers.<br />
<br />
===Program Example 1===<br />
<br />
'''Generate a random number from 1 to 6.'''<br />
<br />
Easy peasy. We will just generate a random number from 1 to 6 with the package like this:<br />
<br />
import random<br />
print(random.randint(1,6))<br />
<br />
As you can see, when you run this program, you get a random integer from 1 to 6.<br />
<br />
===Program Example 2===<br />
<br />
'''Simulate the rolling of 1000 dice. Now, count the number of times you roll 6. Print that number out.'''<br />
<br />
We can create a function that returns a random number from 1 to 6. Then, we can make a for loop that rolls the dice 1000 times and check if it is a 6.<br />
<br />
import random<br />
count = 0<br />
<br />
def roll():<br />
return random.randint(1,6)<br />
<br />
for i in range(1, 1001):<br />
if roll() == 6:<br />
count += 1<br />
<br />
print(count)<br />
<br />
If we run this, we will get a number around 170.<br />
<br />
===Program Example 3===<br />
<br />
'''Simulate the rolling of 10,000 dice. Now, count the amount of times you roll 3. Print that amount out.'''<br />
<br />
We can keep our roll function and our code inside the for loop, but we need to change our for loop statement.<br />
<br />
We can actually soft-code our program more. Let's turn the whole for loop into a function!<br />
<br />
import random<br />
<br />
def roll():<br />
return random.randint(1,6)<br />
<br />
def count(amount):<br />
count_ = 0<br />
<br />
for i in range(1, amount+1):<br />
if roll() == 3:<br />
count_ += 1<br />
return count_<br />
<br />
print(count(10000))<br />
<br />
If we run this code, it works.<br />
<br />
===Program Example 4===<br />
<br />
'''One of my friends loves rolling dice. He is going to roll 1 die tomorrow, 2 dice two days from now, 3 dice three days from now, and so on so that he rolls <math>a</math> dice <math>a</math> days from now. He gets tired rolling dice after rolling dice for 365 days (so the last day he rolls 365 dice). In Python, simulate this. How many times does he roll 3 after 365 days of rolling dice?'''<br />
<br />
We can use a for loop that calls a function multiple times.<br />
<br />
import random<br />
<br />
def roll():<br />
return random.randint(1,6)<br />
<br />
def count(amount):<br />
count_ = 0<br />
for i in range(1, amount+1):<br />
if roll() == 3:<br />
count_ += 1<br />
return count_<br />
<br />
total = 0<br />
<br />
for i in range(1, 366):<br />
total += count(i)<br />
<br />
print(total)<br />
<br />
This is a really long program, but the whole program should make sense if you look at it for a while. We defined our count function in the previous example, and now we are using it with a for loop and a running total. <br />
<br />
You should get a number around 11,000 when you run it. Wow, lots of 3's!<br />
<br />
===Program Example 5===<br />
<br />
'''20 of my friends love rolling dice. They are all going to roll 1 die each tomorrow, 2 dice each two days from now, 3 dice each three days from now, and so on so that they roll <math>a</math> dice each <math>a</math> days from now. But, one of my friends gets tired very quickly and he only rolls dice for 1 day and stops. Another friend only will roll dice for 2 days, and another will roll dice for three days only, and so on up to the fact that my last friend will roll dice for 20 days. In Python, simulate this. How many times does someone roll 3 after everything?'''<br />
<br />
We will have to make our for loop into a function again.<br />
<br />
import random<br />
<br />
def roll():<br />
return random.randint(1,6)<br />
<br />
def count(amount):<br />
count_ = 0<br />
for i in range(1, amount+1):<br />
if roll() == 3:<br />
count_ += 1<br />
return count_<br />
<br />
def count2(amount)<br />
total = 0<br />
for i in range(1, amount + 1):<br />
total += count(i)<br />
return total<br />
<br />
def count3(amount)<br />
total = 0<br />
for i in range(1, amount + 1):<br />
total += count2(i)<br />
return total<br />
<br />
print(count3(20))<br />
<br />
(Our program is so long!)<br />
<br />
I also made a new function just in case we needed to turn that into a function later.<br />
<br />
'''Make sure''' you read the code carefully and you fully understand it. If you don't understand every single line of code, then you will get confused later on in this article.<br />
<br />
When you run this program, you might be surprised that the answer isn't so big.<br />
<br />
===Program Example 6===<br />
<br />
'''365 of my friends love rolling dice. They are all going to roll 1 die each tomorrow, 2 dice each two days from now, 3 dice each three days from now, and so on so that they roll <math>a</math> dice each <math>a</math> days from now. But, one of my friends gets tired very quickly and he only rolls dice for 1 day and stops. Another friend only will roll dice for 2 days, and another will roll dice for three days only, and so on up to the fact that my last friend will roll dice for 365 days. In Python, simulate this. How many times does someone roll 3 after everything?'''<br />
<br />
Because we soft-coded our program so much, all we have to do is change the last line so the parameter of count3() is 365.<br />
<br />
If we run it...we get a big answer, as expected. It also takes quite a while!<br />
<br />
You may not have realized that we soft-coded our program at all, but the whole point of functions is to soft-code programs!<br />
<br />
Congrats on writing a program that is around 25 lines long!<br />
<br />
==Very Basic Datatypes==<br />
<br />
An integer is a basic datatype in Python. Basically, all variables with the datatype of '''int''' is an integer.<br />
<br />
A string is another basic datatype, and it is a string of characters enclosed by quotes.<br />
<br />
===Why Are Datatypes So Important?===<br />
<br />
Let's say we wanted to make a program that would add 2 and 3. Some bogus code would be:<br />
<br />
x="2"<br />
y="3"<br />
print(x+y)<br />
<br />
If you ran this code, you would get 23. Why is that?<br />
<br />
Well, here, x and y are strings. When you perform the addition operator to strings in Python, it concatenates the strings, giving 23.<br />
<br />
The real code is:<br />
<br />
x=2<br />
y=3<br />
print(x+y)<br />
<br />
If you run this, you will get <math>5</math>, which is correct.<br />
<br />
Here's another reason datatypes are important. Now, we will introduce the datatype called the '''floating point number''', or '''float'''. A floating-point number is a number with a decimal point.<br />
<br />
Let's go back to the IDLE. Type "0.1*10". The result is 1.0. Notice the decimal point.<br />
<br />
Let's type something different. Type <math>0.1+0.1+0.1+0.1+0.1+0.1+0.1+0.1+0.1+0.1.</math><br />
<br />
'''WHAT!?'''<br />
<br />
You would have expected the answer to be 1, but it isn't 1. What happened?<br />
<br />
'''Float approximation''' happened. Most (almost all) programming languages have a bad float approximation. That means that 1.0 can turn into 0.99999999999999 and 0.5 can turn into 0.49999999999999999993. That only happens with floats, so we should try to use floats as sparingly as possible.<br />
<br />
==Lists==<br />
<br />
A for loop iterates over a '''list'''. A list is a bunch of objects stored in one variable. (Hey! A list is a datatype!) For loops are highly related to lists.<br />
<br />
Let's say we wanted to make a program to print all the items in a list.<br />
<br />
We will first create the list, using the code:<br />
<br />
myList = [1,4,6,8]<br />
<br />
This is a list with four items: 1, 4, 6, and 8.<br />
<br />
We must now print all elements of it with a for loop:<br />
<br />
myList = [1,4,6,8]<br />
for i in myList:<br />
print(i)<br />
<br />
When we run this program, we get the numbers 1, 4, 6, and 8, as expected.<br />
<br />
===Accessing Values===<br />
<br />
Let's say we wanted to print out the second item in a list. We will use '''indexes'''.<br />
<br />
The index of the first item in a list is always 0. The index of the second is 1. The index of the <math>n</math>th is <math>n-1.</math><br />
<br />
To print out the second item, we will use an index of 1, like this:<br />
<br />
myList = [1,4,6,8]<br />
print(myList[1])<br />
<br />
Notice that the index is inside of the square brackets.<br />
<br />
===Adding Values===<br />
<br />
We can use the list.append() function to add an object to the end of a list.<br />
<br />
myList.append(10)<br />
<br />
will add 10 to the list, which makes myList = [1,4,6,8,10].<br />
<br />
===Removing Items From Lists===<br />
<br />
We can use the list.remove() function to remove a specific item in a list.<br />
<br />
For example, consider this code.<br />
<br />
myList = [1,2,3]<br />
myList.remove(3)<br />
<br />
This code will make myList turn into [1,2]. The element, 3, gets removed.<br />
<br />
===len(list)===<br />
<br />
The len(list) function returns the length of a list.<br />
<br />
This code will print 3.<br />
<br />
myList = [1,2,3]<br />
print(len(myList))<br />
<br />
The length of myList is 3, so Python prints 3.<br />
<br />
===All Kinds Of Lists===<br />
<br />
Lists don't have to be only integers!<br />
<br />
myList = [1,"Hi","Hello world", 3.5, 3.14159265358979323]<br />
<br />
If fact, there can be lists inside of lists!<br />
<br />
myList = [[1,2,3], [3,4,5], [5,6,"Hello world"], "BOB", 3.1415926]<br />
<br />
Even this!<br />
<br />
myList = [[1, [1, [1,2,3],3],3], [[[3,["Hello world", 4],5],4,5],4,5], [5,6,7,[1,[1,2,3],3],"Hello world"], "BOB", 3.1415926, True]<br />
<br />
If you look at that list carefully, you will find lists inside of lists inside of lists inside of lists! And, a boolean at the end!<br />
<br />
Like variables, you can have as many lists in a program as you want (a list is a variable)!<br />
<br />
myList = [1,2,3,4]<br />
yourList = [5,6,7,8]<br />
hisList = [9,10,11,12]<br />
herList = [13,14,15,16]<br />
theirList = [17,18,19,20]<br />
ourList = [21,22,23,24]<br />
listsOfLists = [[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16],[17,18,19,20],[21,22,23,24]]<br />
<br />
===Splitting Lists===<br />
Split Operator Basics:<br />
genericList[where to start:where to end:what size steps to take]<br />
The value where to start is inclusive, and denotes the index where your split list begins. It has a default value of 0.<br />
The value where to end is exclusive, and denotes the index where your split list ends. It has a default value of len(genericList).<br />
The value what size steps denotes the size of the steps your split takes(more on that later). It has a default value of 1.<br />
Say you want to split a list and only return certain indices, for example if you wanted to split a list called data and put the first two elements into a list called head and the last two into a list called tail, you would split like this:<br />
data = [1, 3, 4, 23.5, 40, 55]<br />
head = data[:2]<br />
tail = data[-2:] # negative list indices represent the end of a list, so -1 is the last element and -2 is the second-to-last<br />
Step Size:<br />
We will practice writing a few functions that select every other element and will reverse in a list using step size.<br />
A step size of two means skip every other list index, so we can write our first function.<br />
def selectEveryOtherElement(list):<br />
return list[::2]<br />
But which step size will get us our desired reversed list. We could start at the end of the list and iterate backwards, but how would we do that...<br />
Negative Step Size:<br />
A step size that is negative means skip a certain amount of elements, but backwards. If we were to start at 0, with a step size of -1, we would be able to iterate backwards over the list!<br />
def reverse(list):<br />
return list[::-1]<br />
Splitting lists with ratios:<br />
What if we wanted to be able to split a list based upon a ratio. For example, the common 80:20 train to test ratio in machine learning? Here is how you would do it<br />
def eighty-twenty(list):<br />
train = list[:int(len(list) * (4 / 5))] # We must include the int() method to convert to an integer if len(list) % 5 != 0<br />
test = list[int(len(list) * 4 / 5)]<br />
return [train, test] # We then return a list with the train and test lists inside<br />
<br />
==Dictionaries==<br />
<br />
A dictionary (a type of datatype) is a bunch of keys and values. There is a major difference between dictionaries and lists. Lists are ordered; dictionaries are not.<br />
<br />
Here is the '''syntax''' of creating a dictionary:<br />
<br />
myDictionary = {1:"one",2:"two"}<br />
<br />
This dictionary has two key/value pairs. Notice it is surrounded in curly braces. The keys are 1 and 2; the values are "one" and "two."<br />
<br />
How is this useful? Let's make a simple program to test it out.<br />
<br />
myDictionary = {1:"one",2:"two"}<br />
print(myDictionary[1])<br />
print(myDictionary[2])<br />
<br />
===Accessing Values===<br />
<br />
To access a value in a dictionary, you put in the key.<br />
<br />
myDictionary[1]<br />
<br />
returns one, because 1 is the key to "one."<br />
<br />
===Adding New Values===<br />
<br />
To overwrite a value, we do this.<br />
<br />
myDictionary[1] = "won"<br />
<br />
The value to the key 1 is now "won."<br />
<br />
To add a value, we do the same thing!<br />
<br />
myDictionary[3] = "three"<br />
<br />
This adds a key 3 with a value of "three."<br />
<br />
==Misc Concepts==<br />
<br />
This section will talk about some concepts that we haven't learned yet.<br />
<br />
====Concatenating Strings====<br />
<br />
Concatenating strings is putting them together. For example, "one" concatenated with "two" gives "onetwo."<br />
<br />
The following string,<br />
<br />
"Hello, " + person2 + "! How are you?"<br />
<br />
depends on what person2 was. If person2 was Bob, the string would be:<br />
<br />
"Hello, Bob! How are you?"<br />
<br />
It fits together perfectly!<br />
<br />
You cannot concatenate strings with integers. For example, doing this:<br />
<br />
"2" + 3<br />
<br />
will not work. Instead, to get an answer of "23", you must do this:<br />
<br />
"2" + str(3)<br />
<br />
That turns 3 into a string so it is "3", and the result will be "23".<br />
<br />
====Line Breaks====<br />
<br />
We can use multiple line breaks to make our code more organized. There are some places that you cannot line break. For example, this code will produce an error:<br />
<br />
myList =<br />
[1,2,3]<br />
<br />
This code does not work.<br />
<br />
This code '''does work''':<br />
<br />
myList = [<br />
1,2,3]<br />
<br />
It is accepted when you break a line right after the [. It is also accepted right after a comma. (And right before the ending ].)<br />
<br />
myList = [<br />
1,<br />
2,<br />
3<br />
]<br />
<br />
==Challenge Program==<br />
<br />
In this section, we will attempt the hardest program so far in this article.<br />
<br />
'''Make a conversation generator that will generate random conversations between different people.'''<br />
<br />
First, we will generate the people. We can use a list and generate two random numbers.<br />
<br />
import random<br />
<br />
peopleNames = [<br />
"Bob",<br />
"Kyle",<br />
"James",<br />
"Richard",<br />
"Zachary",<br />
"Olivia",<br />
"Jonathan",<br />
"Will",<br />
"Bobby",<br />
"Kevin"<br />
]<br />
person1 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
peopleNames.remove(person1)<br />
person2 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
<br />
(I made it more organized by separating the long lines of code into multiple lines. It only works when you have a line break right after each item in the list.)<br />
<br />
Here, we use the remove() function to remove person1 from the list to make sure we don't use the same name twice. <br />
<br />
We also used the len() function to find the length of the list (soft-coding!)<br />
<br />
Now, we need to create a list of possible values for the first thing that person1 says (person1 will always be the first one to talk). <br />
<br />
Then, we will print it out.<br />
<br />
import random<br />
<br />
peopleNames = [<br />
"Bob",<br />
"Kyle",<br />
"James",<br />
"Richard",<br />
"Zachary",<br />
"Olivia",<br />
"Jonathan",<br />
"Will",<br />
"Bobby",<br />
"Kevin"<br />
]<br />
person1 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
peopleNames.remove(person1)<br />
person2 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
<br />
first = [<br />
"Hi!",<br />
"Hello!",<br />
"Good morning!",<br />
"Hello, " + person2 + "!",<br />
"Hi.",<br />
"Hi, " + person2 + "!"<br />
]<br />
print(person1 + ": " + first[random.randint(0, (len(first) - 1))])<br />
<br />
If we test out this program, we can confirm that this part indeed does work. This program is already getting long! Now, we will use the same method and create the second message.<br />
<br />
import random<br />
<br />
peopleNames = [<br />
"Bob",<br />
"Kyle",<br />
"James",<br />
"Richard",<br />
"Zachary",<br />
"Olivia",<br />
"Jonathan",<br />
"Will",<br />
"Bobby",<br />
"Kevin"<br />
]<br />
person1 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
peopleNames.remove(person1)<br />
person2 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
<br />
first = [<br />
"Hi!",<br />
"Hello!",<br />
"Good morning!",<br />
"Hello, " + person2 + "!",<br />
"Hi.",<br />
"Hi, " + person2 + "!"<br />
]<br />
print(person1 + ": " + first[random.randint(0, (len(first) - 1))])<br />
<br />
second = [<br />
"Hi! How are you today?",<br />
"Hello! How are you?",<br />
"Good morning! How are you today?",<br />
"Hello, " + person1 + "! How are you?",<br />
"Hi. How are you?",<br />
"Hi, " + person1 + "! How are you today?"<br />
]<br />
print(person2 + ": " + second[random.randint(0, (len(second) - 1))])<br />
<br />
We will repeat this for the rest of the conversation:<br />
<br />
import random<br />
<br />
peopleNames = [<br />
"Bob",<br />
"Kyle",<br />
"James",<br />
"Richard",<br />
"Zachary",<br />
"Olivia",<br />
"Jonathan",<br />
"Will", <br />
"Bobby",<br />
"Kevin"<br />
]<br />
person1 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
peopleNames.remove(person1)<br />
person2 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
<br />
first = [<br />
"Hi!",<br />
"Hello!",<br />
"Good morning!",<br />
"Hello, " + person2 + "!",<br />
"Hi.",<br />
"Hi, " + person2 + "!"<br />
]<br />
print(person1 + ": " + first[random.randint(0, (len(first) - 1))])<br />
<br />
second = [<br />
"Hi! How are you today?",<br />
"Hello! How are you?",<br />
"Good morning! How are you today?",<br />
"Hello, " + person1 + "! How are you?",<br />
"Hi. How are you?",<br />
"Hi, " + person1 + "! How are you today?"<br />
]<br />
print(person2 + ": " + second[random.randint(0, (len(second) - 1))])<br />
<br />
third = [<br />
"I'm feeling awesome! And you?",<br />
"I'm feeling alright! How are you?",<br />
"I'm good, thank you. How are you feeling?",<br />
"I'm fine!" ,<br />
"How are you today?"<br />
]<br />
print(person1 + ": " + third[random.randint(0, (len(third) - 1))])<br />
<br />
fourth = [<br />
"I'm feeling great!",<br />
"I'm awesome!",<br />
"Thanks for asking! I am feeling good today!",<br />
"I'm feeling awesome today! Yippee!"<br />
] <br />
print(person2 + ": " + fourth[random.randint(0, (len(fourth) - 1))])<br />
<br />
fifth = [<br />
"It's so nice out today!",<br />
"Today is such a cloudy day.",<br />
"I hate it when it is so cloudy outside!",<br />
"It's partly cloudy today!"<br />
]<br />
print(person1 + ": " + fifth[random.randint(0, (len(fifth) - 1))])<br />
<br />
sixth = [<br />
"I know, right?",<br />
"I know.",<br />
"Yeah!",<br />
"True."<br />
]<br />
print(person2 + ": " + sixth[random.randint(0, (len(sixth) - 1))])<br />
<br />
seventh = [<br />
"Sorry, I need to leave. Bye!",<br />
"I gotta go. Bye!",<br />
"Sorry, I don't have time to stay and chat. I've got to go somewhere. Bye!"<br />
]<br />
print(person1 + ": " + seventh[random.randint(0, (len(seventh) - 1))])<br />
<br />
eighth = [<br />
"Bye!",<br />
"Good-bye!",<br />
"Bye, " + person1 + "."<br />
]<br />
print(person2 + ": " + eighth[random.randint(0, (len(eighth) - 1))])<br />
<br />
Whew! So long!<br />
<br />
Once we run our program. It works! This program really wasn't that hard.<br />
<br />
Congrats! You've made it so far!</div>Anstarhttps://artofproblemsolving.com/wiki/index.php?title=Basic_Programming_With_Python&diff=132194Basic Programming With Python2020-08-20T01:16:13Z<p>Anstar: /* Defining a class */</p>
<hr />
<div>'''Important: It is extremely recommended that you read [[Getting Started With Python Programming]] before reading this unless you already know some programming knowledge.'''<br />
<br />
(Note: This is a really long article. To learn the most from this article, you need to read everything in order and skip nothing, unless you are '''absolutely absolutely sure that that content is way too easy for you.''')<br />
<br />
This article will talk about some basic Python programming. If you don't even know how to install Python, look [[Getting Started With Python Programming|here]].<br />
<br />
Note that this article has lots of program examples. It is recommended (but not required) to try these on your own before looking at the solutions.<br />
<br />
==Loops==<br />
<br />
There are two different kinds of loops in Python: the for loop and the while loop.<br />
<br />
===The For Loop===<br />
<br />
The for loop iterates over a list, or an array, of objects. You have probably seen this code before:<br />
<br />
[[File:Capture.PNG|200px]]<br />
<br />
This for loop iterates over the list of integers from 1 to 51, excluding the 51 and including the 1. That means it is a list from 1 to 50, inclusive. On every iteration, Python will print the number that the loop is iterating through. <br />
<br />
For example, in the first iteration, i = 1, so Python prints 1.<br />
<br />
In the second iteration, i = 2, so Python prints 2.<br />
<br />
This continues so on until the number, 50, is reached. Therefore, the last number Python will print out is 50.<br />
<br />
====Program Example====<br />
<br />
'''Find <math>\sum_{n=1}^{50} 2^{n}.</math>'''<br />
<br />
To do this task, we must create a for loop and loop over the integers from 1 to 50 inclusive:<br />
<br />
for i in range(1,51):<br />
<br />
Now what? We must keep a running total and increase it by <math>2^i</math> every time:<br />
<br />
total = 0<br />
for i in range(1,51):<br />
total += 2**i<br />
<br />
We must not forget to print the total at the end!<br />
<br />
total = 0<br />
for i in range(1,51):<br />
total += 2**i<br />
print(total)<br />
<br />
You must exit out of the for loop one you reach the print(total) line by pressing backspace.<br />
<br />
Once you run your program, you should get an answer of <math>\boxed{2,251,799,813,685,246.}</math><br />
<br />
===The While Loop===<br />
<br />
While loops don't loop over a list. They loop over and over and over...'''until'''...a condition becomes false.<br />
<br />
i = 3<br />
total = 0<br />
while i < 1000:<br />
total += i<br />
i += 3<br />
print(total)<br />
<br />
In this code, the while loop loops 333 times, until <math>i</math> becomes greater than or equal to 1000.<br />
<br />
====Program Example====<br />
<br />
'''Find <math>\sum_{n=1}^{50} 2^n</math> using a while loop.'''<br />
<br />
We must create a while loop that will iterate until n is greater than <math>50.</math><br />
<br />
n = 1<br />
total = 0<br />
while n <= 50:<br />
total += 2**n<br />
n += 1<br />
print(total)<br />
<br />
We must not forget to include the n += 1 line at the end of the while loop! <br />
<br />
If we run this, we will get the same answer as last time, <math>2,251,799,813,685,246.</math><br />
<br />
==Functions==<br />
<br />
In this section, we will define new operations and do arithmetic with them in Python.<br />
<br />
===The New Operation===<br />
Let's say that you defined a new binary operation, the <math>\uparrow \downarrow.</math> You want it to be so <math>a \uparrow \downarrow b = a^{b}b^{a}.</math> Therefore, <math>1\uparrow \downarrow 2 = 1^{2}2^{1}=1\cdot 2= 2,</math> and <math>2\uparrow \downarrow 3 = 2^33^2 = 8\cdot 9 = 72.</math> Let's call this operation an '''up down arrow.'''<br />
<br />
===Program Example 1===<br />
<br />
'''Find <math>[2 \uparrow \downarrow (1 \uparrow \downarrow 2)] \uparrow \downarrow 2.</math>'''<br />
<br />
We know this will be a big number, so we should write a program to do it! We certainly don't want to do the exponentiation and multiplication every time we use the operation in our program, and that's where functions come in! Functions can take in parameters (<math>a</math> and <math>b</math>) and return a result depending on the parameters.<br />
<br />
def up_down_arrow(a,b): <br />
return ((a**b) * (b**a))<br />
<br />
Above is the code to define our function. We need to print the final result at the end, so we must put a print statement at the end.<br />
<br />
def up_down_arrow(a,b): <br />
return ((a**b) * (b**a))<br />
print(up_down_arrow(up_down_arrow(2,up_down_arrow(1,2)),2)<br />
<br />
All those nested up_down_arrow's might be confusing at first, but it really isn't that confusing.<br />
If you run your program, you should get your answer: <math>16,777,216.</math> <br />
<br />
You might be surprised that the answer is so big. If you actually start calculating the real answer without a program, you will really quickly find that the final result is <math>16 \uparrow \downarrow 2,</math> which does turn out to be 16,777,216 if you use a calculator.<br />
<br />
Let's make another operation!<br />
<br />
We will define the operation <math>\uparrow \downarrow \leftarrow \rightarrow</math> to be called '''all around.''' <math>a \uparrow \downarrow \leftarrow \rightarrow b = (ab(a \uparrow \downarrow b))^2.</math> That's an operation that will make really big numbers!<br />
<br />
===Program Example 2===<br />
<br />
'''Find 87 all around 132.'''<br />
<br />
The answer is bound to be a huge number, so we must make a program to solve it.<br />
<br />
We will keep our up_down_arrow function because in the definition of our all_around function we will use it. Then, we will define the all_around function.<br />
<br />
def up_down_arrow(a,b):<br />
return ((a**b) * (b**a))<br />
def all_around(a,b):<br />
return ((a * b * up_down_arrow(a,b)) ** 2)<br />
<br />
We must print all_around(87,132) at the end. Once we do that, and we run our program, we get a super huge number that has over 800 digits!<br />
<br />
===Understanding Functions===<br />
<br />
Every single function has a '''return value'''. If a function does not return anything, the return value is '''null'''. Null is a term used in programming as a placeholder that stands for nothing.<br />
<br />
====Simple Program Example 1====<br />
<br />
'''Define a function that adds 1 to an input.'''<br />
<br />
How will the function know what number to add 1 to? We will input a '''parameter''' for the function to add 1 to.<br />
<br />
def add_one(x):<br />
return x + 1<br />
<br />
In this function, <math>x</math> is the parameter.<br />
<br />
def add_one(x):<br />
return x + 1<br />
print(add_one(2))<br />
<br />
In the print statement, we set <math>x</math> as 2, and the function returns <math>2 + 1 = 3,</math> so the program prints <math>3</math>.<br />
<br />
====Simple Program Example 2====<br />
<br />
'''Define a function that prints out an input.'''<br />
<br />
We will use a parameter again.<br />
<br />
def print_function(x):<br />
print(x)<br />
<br />
Uh oh! We have nothing to return! Therefore, we will return nothing (or null), by just writing return.<br />
<br />
def print_function(x):<br />
print(x)<br />
return<br />
print_function("print_function")<br />
<br />
This code prints out print_function. print_function() is said to be '''called''' in the final line of the code. Again, we set <math>x</math>, our parameter, as "print_function."<br />
== Classes ==<br />
Classes are <br />
<br />
===Defining a class===<br />
We can define a class by doing the following:<br />
<br />
<br />
class Example:<br />
pass<br />
<br />
<br />
We can call a class by doing the following<br />
<br />
===methods===<br />
methods are definition that apply to a class.<br />
===__init__===<br />
===__str__===<br />
===overloading===<br />
overloading means changing a builtin function to do what you want it to do.<br />
<br />
==Flow==<br />
<br />
Flow consists of if statements, elif (else if) statements, and else statements.<br />
<br />
*An if statement checks if a comparison is true.<br />
<br />
*An else statement checks if a comparison is not true. It is used after an if statement (and all elif statements after the if statement) and it shares the same comparison as the if statement.<br />
<br />
*An elif statement checks for two things: if a comparison is true, and if a comparison is not true. It is used right after the if statement.<br />
<br />
===Program Example===<br />
<br />
'''Does the number 10 have the property that when you multiply 10 by 5, you get a two digit number?'''<br />
<br />
This problem is super easy to solve without a program, but let's write a program to solve this anyway. We will use an if statement to check if <math>10\cdot 5</math> is less than 100 and greater than 9.<br />
<br />
if 10*5 > 9:<br />
if 10*5 < 100:<br />
print("Yes")<br />
else:<br />
print("No")<br />
else:<br />
print("No")<br />
<br />
This code means, if 10*5 > 9, then we will check if it is less than 100. If it is not greater than 9, however, we will print No. If it is greater than 9, we check if it is less than 100. If it is, we print Yes. If it isn't we print No.<br />
<br />
These nested if statements can be very confusing. Luckily, there is a faster an easier way to do this.<br />
<br />
if 10*5 > 9 and 10*5 < 100:<br />
print("Yes") <br />
else:<br />
print("No")<br />
<br />
This code checks for the two conditions at the same time. If we run it, we get our answer of Yes.<br />
<br />
==Booleans==<br />
<br />
===Program Example===<br />
<br />
'''Print all two-digit positive integers <math>x</math> such that <math>5x</math> is a two-digit positive integer.'''<br />
<br />
We can create a function with our previous code.<br />
<br />
We will have to slightly modify our function so we can use it in a for loop at the end:<br />
<br />
def check(a):<br />
if a*5 > 9 and a*5 < 100:<br />
return True <br />
else:<br />
return False<br />
<br />
True and False are what are called '''booleans'''. When an if or elif statement receives True, the code inside of the statement happens. When an if or elif statement receives False, the code inside of the statement does not happen. <br />
<br />
We must create a for loop that will iterate through all two digit positive integers. <br />
<br />
def check(a):<br />
if a*5 > 9 and a*5 < 100:<br />
return True <br />
else:<br />
return False<br />
for i in range(10,100):<br />
if check(i):<br />
print(i)<br />
<br />
The final for loop checks if <math>5i</math> is a two digit integer. If it is, the function returns True and the code inside the if statement gets run. If it isn't, the function returns False and the code inside the if statement gets ignored.<br />
<br />
If we run this, we will get the answer.<br />
<br />
All two digit integers from 10 to 19 inclusive work!<br />
<br />
=="Soft Coding" Programs==<br />
<br />
In the next few examples, you will see why hard coding programs is bad. Hard coding programs refers to coding a program that is hard to modify. For example:<br />
<br />
===Program Example 1===<br />
<br />
'''Print all two digit positive integers <math>x</math> such that <math>5x</math> is a three digit positive integer.'''<br />
<br />
We can keep our code and modify some parts of it.<br />
<br />
def check(a, min, max):<br />
if a*5 > min - 1 and a*5 < max + 1:<br />
return True <br />
else:<br />
return False<br />
<br />
def print_check(range_min, range_max, check_min, check_max):<br />
for i in range(range_min, range_max + 1):<br />
if check(i, check_min, check_max):<br />
print(i)<br />
return<br />
<br />
print_check(10, 99, 100, 999)<br />
<br />
Why did we add so many functions?<br />
<br />
Well, if the numbers in a problem change (and the words stay the same), and you need to change a lot of numbers in your program, your program is considered '''hard-coded'''. We want our programs to be as '''soft-coded''' as possible. In our new program, we only need to change 4 numbers (in the print_check() statement) if the numbers in the problem change. Therefore, our program is relatively soft-coded. There are still ways to soft-code this program even more, though.<br />
<br />
If we run our program, we get our answer.<br />
<br />
All numbers from 20 to 99 work!<br />
<br />
===Program Example 2===<br />
<br />
'''Print all three digit positive integers <math>x</math> such that <math>5x</math> is a three digit positive integer.'''<br />
<br />
We can just change the print_check line at the end to<br />
<br />
print_check(100, 999, 100, 999)<br />
<br />
and our program will be ready to be run.<br />
<br />
All numbers from 100 to 199 work.<br />
<br />
===Program Example 3===<br />
<br />
'''Print all two digit positive integers <math>x</math> such that <math>3x</math> is a three digit positive integer.'''<br />
<br />
Uh oh. Only changing the print_check line won't work. We will need to change our functions!<br />
<br />
def check(a, min, max, factor):<br />
if a*factor > min - 1 and a*factor < max + 1:<br />
return True <br />
else:<br />
return False<br />
<br />
def print_check(range_min, range_max, check_min, check_max, check_factor):<br />
for i in range(range_min, range_max + 1):<br />
if check(i, check_min, check_max, check_factor):<br />
print(i)<br />
return<br />
<br />
print_check(10, 99, 100, 999, 3)<br />
<br />
In this step, we added a parameter in both functions. We also soft-coded our program even more! Hooray!<br />
<br />
All integers from 34 to 99 work.<br />
<br />
===Program Example 4===<br />
<br />
'''Print all two digit positive integers <math>x</math> such that <math>12x</math> is a positive integer from 500 to 900.'''<br />
<br />
This problem may look a bit different from the other ones, but it really is the same thing, except that the factor is 12 and check_min and check_max are 500 and 900, respectively.<br />
<br />
Once we change the final print_check() line to satisfy our needs, we can run our program.<br />
<br />
All numbers from 42 to 75 work!<br />
<br />
Congrats! You have written your first programs above 10 lines of code!<br />
<br />
==Random==<br />
<br />
There is a package in Python that allows the use of random numbers.<br />
<br />
===Program Example 1===<br />
<br />
'''Generate a random number from 1 to 6.'''<br />
<br />
Easy peasy. We will just generate a random number from 1 to 6 with the package like this:<br />
<br />
import random<br />
print(random.randint(1,6))<br />
<br />
As you can see, when you run this program, you get a random integer from 1 to 6.<br />
<br />
===Program Example 2===<br />
<br />
'''Simulate the rolling of 1000 dice. Now, count the number of times you roll 6. Print that number out.'''<br />
<br />
We can create a function that returns a random number from 1 to 6. Then, we can make a for loop that rolls the dice 1000 times and check if it is a 6.<br />
<br />
import random<br />
count = 0<br />
<br />
def roll():<br />
return random.randint(1,6)<br />
<br />
for i in range(1, 1001):<br />
if roll() == 6:<br />
count += 1<br />
<br />
print(count)<br />
<br />
If we run this, we will get a number around 170.<br />
<br />
===Program Example 3===<br />
<br />
'''Simulate the rolling of 10,000 dice. Now, count the amount of times you roll 3. Print that amount out.'''<br />
<br />
We can keep our roll function and our code inside the for loop, but we need to change our for loop statement.<br />
<br />
We can actually soft-code our program more. Let's turn the whole for loop into a function!<br />
<br />
import random<br />
<br />
def roll():<br />
return random.randint(1,6)<br />
<br />
def count(amount):<br />
count_ = 0<br />
<br />
for i in range(1, amount+1):<br />
if roll() == 3:<br />
count_ += 1<br />
return count_<br />
<br />
print(count(10000))<br />
<br />
If we run this code, it works.<br />
<br />
===Program Example 4===<br />
<br />
'''One of my friends loves rolling dice. He is going to roll 1 die tomorrow, 2 dice two days from now, 3 dice three days from now, and so on so that he rolls <math>a</math> dice <math>a</math> days from now. He gets tired rolling dice after rolling dice for 365 days (so the last day he rolls 365 dice). In Python, simulate this. How many times does he roll 3 after 365 days of rolling dice?'''<br />
<br />
We can use a for loop that calls a function multiple times.<br />
<br />
import random<br />
<br />
def roll():<br />
return random.randint(1,6)<br />
<br />
def count(amount):<br />
count_ = 0<br />
for i in range(1, amount+1):<br />
if roll() == 3:<br />
count_ += 1<br />
return count_<br />
<br />
total = 0<br />
<br />
for i in range(1, 366):<br />
total += count(i)<br />
<br />
print(total)<br />
<br />
This is a really long program, but the whole program should make sense if you look at it for a while. We defined our count function in the previous example, and now we are using it with a for loop and a running total. <br />
<br />
You should get a number around 11,000 when you run it. Wow, lots of 3's!<br />
<br />
===Program Example 5===<br />
<br />
'''20 of my friends love rolling dice. They are all going to roll 1 die each tomorrow, 2 dice each two days from now, 3 dice each three days from now, and so on so that they roll <math>a</math> dice each <math>a</math> days from now. But, one of my friends gets tired very quickly and he only rolls dice for 1 day and stops. Another friend only will roll dice for 2 days, and another will roll dice for three days only, and so on up to the fact that my last friend will roll dice for 20 days. In Python, simulate this. How many times does someone roll 3 after everything?'''<br />
<br />
We will have to make our for loop into a function again.<br />
<br />
import random<br />
<br />
def roll():<br />
return random.randint(1,6)<br />
<br />
def count(amount):<br />
count_ = 0<br />
for i in range(1, amount+1):<br />
if roll() == 3:<br />
count_ += 1<br />
return count_<br />
<br />
def count2(amount)<br />
total = 0<br />
for i in range(1, amount + 1):<br />
total += count(i)<br />
return total<br />
<br />
def count3(amount)<br />
total = 0<br />
for i in range(1, amount + 1):<br />
total += count2(i)<br />
return total<br />
<br />
print(count3(20))<br />
<br />
(Our program is so long!)<br />
<br />
I also made a new function just in case we needed to turn that into a function later.<br />
<br />
'''Make sure''' you read the code carefully and you fully understand it. If you don't understand every single line of code, then you will get confused later on in this article.<br />
<br />
When you run this program, you might be surprised that the answer isn't so big.<br />
<br />
===Program Example 6===<br />
<br />
'''365 of my friends love rolling dice. They are all going to roll 1 die each tomorrow, 2 dice each two days from now, 3 dice each three days from now, and so on so that they roll <math>a</math> dice each <math>a</math> days from now. But, one of my friends gets tired very quickly and he only rolls dice for 1 day and stops. Another friend only will roll dice for 2 days, and another will roll dice for three days only, and so on up to the fact that my last friend will roll dice for 365 days. In Python, simulate this. How many times does someone roll 3 after everything?'''<br />
<br />
Because we soft-coded our program so much, all we have to do is change the last line so the parameter of count3() is 365.<br />
<br />
If we run it...we get a big answer, as expected. It also takes quite a while!<br />
<br />
You may not have realized that we soft-coded our program at all, but the whole point of functions is to soft-code programs!<br />
<br />
Congrats on writing a program that is around 25 lines long!<br />
<br />
==Very Basic Datatypes==<br />
<br />
An integer is a basic datatype in Python. Basically, all variables with the datatype of '''int''' is an integer.<br />
<br />
A string is another basic datatype, and it is a string of characters enclosed by quotes.<br />
<br />
===Why Are Datatypes So Important?===<br />
<br />
Let's say we wanted to make a program that would add 2 and 3. Some bogus code would be:<br />
<br />
x="2"<br />
y="3"<br />
print(x+y)<br />
<br />
If you ran this code, you would get 23. Why is that?<br />
<br />
Well, here, x and y are strings. When you perform the addition operator to strings in Python, it concatenates the strings, giving 23.<br />
<br />
The real code is:<br />
<br />
x=2<br />
y=3<br />
print(x+y)<br />
<br />
If you run this, you will get <math>5</math>, which is correct.<br />
<br />
Here's another reason datatypes are important. Now, we will introduce the datatype called the '''floating point number''', or '''float'''. A floating-point number is a number with a decimal point.<br />
<br />
Let's go back to the IDLE. Type "0.1*10". The result is 1.0. Notice the decimal point.<br />
<br />
Let's type something different. Type <math>0.1+0.1+0.1+0.1+0.1+0.1+0.1+0.1+0.1+0.1.</math><br />
<br />
'''WHAT!?'''<br />
<br />
You would have expected the answer to be 1, but it isn't 1. What happened?<br />
<br />
'''Float approximation''' happened. Most (almost all) programming languages have a bad float approximation. That means that 1.0 can turn into 0.99999999999999 and 0.5 can turn into 0.49999999999999999993. That only happens with floats, so we should try to use floats as sparingly as possible.<br />
<br />
==Lists==<br />
<br />
A for loop iterates over a '''list'''. A list is a bunch of objects stored in one variable. (Hey! A list is a datatype!) For loops are highly related to lists.<br />
<br />
Let's say we wanted to make a program to print all the items in a list.<br />
<br />
We will first create the list, using the code:<br />
<br />
myList = [1,4,6,8]<br />
<br />
This is a list with four items: 1, 4, 6, and 8.<br />
<br />
We must now print all elements of it with a for loop:<br />
<br />
myList = [1,4,6,8]<br />
for i in myList:<br />
print(i)<br />
<br />
When we run this program, we get the numbers 1, 4, 6, and 8, as expected.<br />
<br />
===Accessing Values===<br />
<br />
Let's say we wanted to print out the second item in a list. We will use '''indexes'''.<br />
<br />
The index of the first item in a list is always 0. The index of the second is 1. The index of the <math>n</math>th is <math>n-1.</math><br />
<br />
To print out the second item, we will use an index of 1, like this:<br />
<br />
myList = [1,4,6,8]<br />
print(myList[1])<br />
<br />
Notice that the index is inside of the square brackets.<br />
<br />
===Adding Values===<br />
<br />
We can use the list.append() function to add an object to the end of a list.<br />
<br />
myList.append(10)<br />
<br />
will add 10 to the list, which makes myList = [1,4,6,8,10].<br />
<br />
===Removing Items From Lists===<br />
<br />
We can use the list.remove() function to remove a specific item in a list.<br />
<br />
For example, consider this code.<br />
<br />
myList = [1,2,3]<br />
myList.remove(3)<br />
<br />
This code will make myList turn into [1,2]. The element, 3, gets removed.<br />
<br />
===len(list)===<br />
<br />
The len(list) function returns the length of a list.<br />
<br />
This code will print 3.<br />
<br />
myList = [1,2,3]<br />
print(len(myList))<br />
<br />
The length of myList is 3, so Python prints 3.<br />
<br />
===All Kinds Of Lists===<br />
<br />
Lists don't have to be only integers!<br />
<br />
myList = [1,"Hi","Hello world", 3.5, 3.14159265358979323]<br />
<br />
If fact, there can be lists inside of lists!<br />
<br />
myList = [[1,2,3], [3,4,5], [5,6,"Hello world"], "BOB", 3.1415926]<br />
<br />
Even this!<br />
<br />
myList = [[1, [1, [1,2,3],3],3], [[[3,["Hello world", 4],5],4,5],4,5], [5,6,7,[1,[1,2,3],3],"Hello world"], "BOB", 3.1415926, True]<br />
<br />
If you look at that list carefully, you will find lists inside of lists inside of lists inside of lists! And, a boolean at the end!<br />
<br />
Like variables, you can have as many lists in a program as you want (a list is a variable)!<br />
<br />
myList = [1,2,3,4]<br />
yourList = [5,6,7,8]<br />
hisList = [9,10,11,12]<br />
herList = [13,14,15,16]<br />
theirList = [17,18,19,20]<br />
ourList = [21,22,23,24]<br />
listsOfLists = [[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16],[17,18,19,20],[21,22,23,24]]<br />
<br />
===Splitting Lists===<br />
Split Operator Basics:<br />
genericList[where to start:where to end:what size steps to take]<br />
The value where to start is inclusive, and denotes the index where your split list begins. It has a default value of 0.<br />
The value where to end is exclusive, and denotes the index where your split list ends. It has a default value of len(genericList).<br />
The value what size steps denotes the size of the steps your split takes(more on that later). It has a default value of 1.<br />
Say you want to split a list and only return certain indices, for example if you wanted to split a list called data and put the first two elements into a list called head and the last two into a list called tail, you would split like this:<br />
data = [1, 3, 4, 23.5, 40, 55]<br />
head = data[:2]<br />
tail = data[-2:] # negative list indices represent the end of a list, so -1 is the last element and -2 is the second-to-last<br />
Step Size:<br />
We will practice writing a few functions that select every other element and will reverse in a list using step size.<br />
A step size of two means skip every other list index, so we can write our first function.<br />
def selectEveryOtherElement(list):<br />
return list[::2]<br />
But which step size will get us our desired reversed list. We could start at the end of the list and iterate backwards, but how would we do that...<br />
Negative Step Size:<br />
A step size that is negative means skip a certain amount of elements, but backwards. If we were to start at 0, with a step size of -1, we would be able to iterate backwards over the list!<br />
def reverse(list):<br />
return list[::-1]<br />
Splitting lists with ratios:<br />
What if we wanted to be able to split a list based upon a ratio. For example, the common 80:20 train to test ratio in machine learning? Here is how you would do it<br />
def eighty-twenty(list):<br />
train = list[:int(len(list) * (4 / 5))] # We must include the int() method to convert to an integer if len(list) % 5 != 0<br />
test = list[int(len(list) * 4 / 5)]<br />
return [train, test] # We then return a list with the train and test lists inside<br />
<br />
==Dictionaries==<br />
<br />
A dictionary (a type of datatype) is a bunch of keys and values. There is a major difference between dictionaries and lists. Lists are ordered; dictionaries are not.<br />
<br />
Here is the '''syntax''' of creating a dictionary:<br />
<br />
myDictionary = {1:"one",2:"two"}<br />
<br />
This dictionary has two key/value pairs. Notice it is surrounded in curly braces. The keys are 1 and 2; the values are "one" and "two."<br />
<br />
How is this useful? Let's make a simple program to test it out.<br />
<br />
myDictionary = {1:"one",2:"two"}<br />
print(myDictionary[1])<br />
print(myDictionary[2])<br />
<br />
===Accessing Values===<br />
<br />
To access a value in a dictionary, you put in the key.<br />
<br />
myDictionary[1]<br />
<br />
returns one, because 1 is the key to "one."<br />
<br />
===Adding New Values===<br />
<br />
To overwrite a value, we do this.<br />
<br />
myDictionary[1] = "won"<br />
<br />
The value to the key 1 is now "won."<br />
<br />
To add a value, we do the same thing!<br />
<br />
myDictionary[3] = "three"<br />
<br />
This adds a key 3 with a value of "three."<br />
<br />
==Misc Concepts==<br />
<br />
This section will talk about some concepts that we haven't learned yet.<br />
<br />
====Concatenating Strings====<br />
<br />
Concatenating strings is putting them together. For example, "one" concatenated with "two" gives "onetwo."<br />
<br />
The following string,<br />
<br />
"Hello, " + person2 + "! How are you?"<br />
<br />
depends on what person2 was. If person2 was Bob, the string would be:<br />
<br />
"Hello, Bob! How are you?"<br />
<br />
It fits together perfectly!<br />
<br />
You cannot concatenate strings with integers. For example, doing this:<br />
<br />
"2" + 3<br />
<br />
will not work. Instead, to get an answer of "23", you must do this:<br />
<br />
"2" + str(3)<br />
<br />
That turns 3 into a string so it is "3", and the result will be "23".<br />
<br />
====Line Breaks====<br />
<br />
We can use multiple line breaks to make our code more organized. There are some places that you cannot line break. For example, this code will produce an error:<br />
<br />
myList =<br />
[1,2,3]<br />
<br />
This code does not work.<br />
<br />
This code '''does work''':<br />
<br />
myList = [<br />
1,2,3]<br />
<br />
It is accepted when you break a line right after the [. It is also accepted right after a comma. (And right before the ending ].)<br />
<br />
myList = [<br />
1,<br />
2,<br />
3<br />
]<br />
<br />
==Challenge Program==<br />
<br />
In this section, we will attempt the hardest program so far in this article.<br />
<br />
'''Make a conversation generator that will generate random conversations between different people.'''<br />
<br />
First, we will generate the people. We can use a list and generate two random numbers.<br />
<br />
import random<br />
<br />
peopleNames = [<br />
"Bob",<br />
"Kyle",<br />
"James",<br />
"Richard",<br />
"Zachary",<br />
"Olivia",<br />
"Jonathan",<br />
"Will",<br />
"Bobby",<br />
"Kevin"<br />
]<br />
person1 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
peopleNames.remove(person1)<br />
person2 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
<br />
(I made it more organized by separating the long lines of code into multiple lines. It only works when you have a line break right after each item in the list.)<br />
<br />
Here, we use the remove() function to remove person1 from the list to make sure we don't use the same name twice. <br />
<br />
We also used the len() function to find the length of the list (soft-coding!)<br />
<br />
Now, we need to create a list of possible values for the first thing that person1 says (person1 will always be the first one to talk). <br />
<br />
Then, we will print it out.<br />
<br />
import random<br />
<br />
peopleNames = [<br />
"Bob",<br />
"Kyle",<br />
"James",<br />
"Richard",<br />
"Zachary",<br />
"Olivia",<br />
"Jonathan",<br />
"Will",<br />
"Bobby",<br />
"Kevin"<br />
]<br />
person1 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
peopleNames.remove(person1)<br />
person2 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
<br />
first = [<br />
"Hi!",<br />
"Hello!",<br />
"Good morning!",<br />
"Hello, " + person2 + "!",<br />
"Hi.",<br />
"Hi, " + person2 + "!"<br />
]<br />
print(person1 + ": " + first[random.randint(0, (len(first) - 1))])<br />
<br />
If we test out this program, we can confirm that this part indeed does work. This program is already getting long! Now, we will use the same method and create the second message.<br />
<br />
import random<br />
<br />
peopleNames = [<br />
"Bob",<br />
"Kyle",<br />
"James",<br />
"Richard",<br />
"Zachary",<br />
"Olivia",<br />
"Jonathan",<br />
"Will",<br />
"Bobby",<br />
"Kevin"<br />
]<br />
person1 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
peopleNames.remove(person1)<br />
person2 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
<br />
first = [<br />
"Hi!",<br />
"Hello!",<br />
"Good morning!",<br />
"Hello, " + person2 + "!",<br />
"Hi.",<br />
"Hi, " + person2 + "!"<br />
]<br />
print(person1 + ": " + first[random.randint(0, (len(first) - 1))])<br />
<br />
second = [<br />
"Hi! How are you today?",<br />
"Hello! How are you?",<br />
"Good morning! How are you today?",<br />
"Hello, " + person1 + "! How are you?",<br />
"Hi. How are you?",<br />
"Hi, " + person1 + "! How are you today?"<br />
]<br />
print(person2 + ": " + second[random.randint(0, (len(second) - 1))])<br />
<br />
We will repeat this for the rest of the conversation:<br />
<br />
import random<br />
<br />
peopleNames = [<br />
"Bob",<br />
"Kyle",<br />
"James",<br />
"Richard",<br />
"Zachary",<br />
"Olivia",<br />
"Jonathan",<br />
"Will", <br />
"Bobby",<br />
"Kevin"<br />
]<br />
person1 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
peopleNames.remove(person1)<br />
person2 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
<br />
first = [<br />
"Hi!",<br />
"Hello!",<br />
"Good morning!",<br />
"Hello, " + person2 + "!",<br />
"Hi.",<br />
"Hi, " + person2 + "!"<br />
]<br />
print(person1 + ": " + first[random.randint(0, (len(first) - 1))])<br />
<br />
second = [<br />
"Hi! How are you today?",<br />
"Hello! How are you?",<br />
"Good morning! How are you today?",<br />
"Hello, " + person1 + "! How are you?",<br />
"Hi. How are you?",<br />
"Hi, " + person1 + "! How are you today?"<br />
]<br />
print(person2 + ": " + second[random.randint(0, (len(second) - 1))])<br />
<br />
third = [<br />
"I'm feeling awesome! And you?",<br />
"I'm feeling alright! How are you?",<br />
"I'm good, thank you. How are you feeling?",<br />
"I'm fine!" ,<br />
"How are you today?"<br />
]<br />
print(person1 + ": " + third[random.randint(0, (len(third) - 1))])<br />
<br />
fourth = [<br />
"I'm feeling great!",<br />
"I'm awesome!",<br />
"Thanks for asking! I am feeling good today!",<br />
"I'm feeling awesome today! Yippee!"<br />
] <br />
print(person2 + ": " + fourth[random.randint(0, (len(fourth) - 1))])<br />
<br />
fifth = [<br />
"It's so nice out today!",<br />
"Today is such a cloudy day.",<br />
"I hate it when it is so cloudy outside!",<br />
"It's partly cloudy today!"<br />
]<br />
print(person1 + ": " + fifth[random.randint(0, (len(fifth) - 1))])<br />
<br />
sixth = [<br />
"I know, right?",<br />
"I know.",<br />
"Yeah!",<br />
"True."<br />
]<br />
print(person2 + ": " + sixth[random.randint(0, (len(sixth) - 1))])<br />
<br />
seventh = [<br />
"Sorry, I need to leave. Bye!",<br />
"I gotta go. Bye!",<br />
"Sorry, I don't have time to stay and chat. I've got to go somewhere. Bye!"<br />
]<br />
print(person1 + ": " + seventh[random.randint(0, (len(seventh) - 1))])<br />
<br />
eighth = [<br />
"Bye!",<br />
"Good-bye!",<br />
"Bye, " + person1 + "."<br />
]<br />
print(person2 + ": " + eighth[random.randint(0, (len(eighth) - 1))])<br />
<br />
Whew! So long!<br />
<br />
Once we run our program. It works! This program really wasn't that hard.<br />
<br />
Congrats! You've made it so far!</div>Anstarhttps://artofproblemsolving.com/wiki/index.php?title=User:Piphi&diff=131954User:Piphi2020-08-17T00:50:03Z<p>Anstar: /* User Count */</p>
<hr />
<div>{{User:Piphi/Template:Header}}<br />
<br><br />
__NOTOC__<div style="border:2px solid black; -webkit-border-radius: 10px; background:#dddddd"><br />
==<font color="black" style="font-family: ITC Avant Garde Gothic Std, Verdana"><div style="margin-left:10px">User Count</div></font>==<br />
<div style="margin-left: 10px; margin-bottom:10px"><font color="black">If this is your first time visiting this page, edit it by incrementing the user count below by one.</font></div><br />
<center><font size="100px">297</font></center><br />
</div><br />
<div style="border:2px solid black; background:#cccccc;-webkit-border-radius: 10px; align:center"><br />
<br />
==<font color="black" style="font-family: ITC Avant Garde Gothic Std, Verdana"><div style="margin-left:10px">About Me</div></font>==<br />
<div style="margin-left: 10px; margin-bottom:10px"><font color="black">Piphi is legendary and made the USA IMO team in 2019.<br><br />
<br />
Piphi is the creator of the [[User:Piphi/Games|AoPS Wiki Games by Piphi]], the future of games on AoPS.<br><br />
<br />
Piphi started the signature trend at around May 2020.<br><br />
<br />
Piphi is an extremely OP person - LJCoder619. <br><br />
<br />
Piphi is OP --[[User:Aray10|Aray10]] ([[User talk:Aray10|talk]]) 23:22, 17 June 2020 (EDT) <br><br />
<br />
Piphi has been very close to winning multiple [[Greed Control]] games, piphi placed 5th in game #18 and 2nd in game #19. Thanks to piphi, Greed Control games have started to be kept track of. Piphi made a spreadsheet that has all of Greed Control history [https://artofproblemsolving.com/community/c19451h2126208p15569802 here].<br><br />
<br />
Piphi also found out who won [[Reaper]] games #1 and #2 as seen [https://artofproblemsolving.com/community/c19451h1826745p15526330 here].<br><br />
<br />
Piphi has been called op by many AoPSers, including the legendary [[User:Radio2|Radio2]] himself [https://artofproblemsolving.com/community/c19451h1826745p15526800 here]. (note: Radio2 calls many users op.)<br><br />
<br />
Piphi created the [[AoPS Administrators]] page, added most of the AoPS Admins to it, and created the scrollable table.<br><br />
<br />
Piphi has also added a lot of the info that is in the [[Reaper Archives]].<br><br />
<br />
Piphi has a side-project that is making the Wiki's [[Main Page]] look better, you can check that out [[User:Piphi/AoPS Wiki|here]].<br><br />
<br />
Piphi published Greed Control Game 19 statistics [https://artofproblemsolving.com/community/c19451h2126212 here].<br />
<br />
Piphi has a post that was made an announcement on a official AoPS Forum [https://artofproblemsolving.com/community/c68h2175116 here].<br />
<br />
Piphi is a proud member of [https://artofproblemsolving.com/community/c562043 The Interuniversal GMAAS Society].<br />
</font></div><br />
</div><br />
<div style="border:2px solid black; background:#bbbbbb;-webkit-border-radius: 10px; align:center"><br />
<br />
==<font color="black" style="font-family: ITC Avant Garde Gothic Std, Verdana"><div style="margin-left:10px">Goals</div></font>==<br />
<div style="margin-left: 10px; margin-right: 10px; margin-bottom:10px"><br />
You can check out more goals/statistics [[User:Piphi/Statistics|here]].<br />
<br />
A User Count of 330<br />
{{User:Piphi/Template:Progress_Bar|87.88|width=100%}}<br />
<br />
200 subpages of [[User:Piphi]]<br />
{{User:Piphi/Template:Progress_Bar|60|width=100%}}<br />
<br />
200 signups for [[User:Piphi/Games|AoPS Wiki Games by Piphi]]<br />
{{User:Piphi/Template:Progress_Bar|40|width=100%}}<br />
<br />
Make 10,000 edits<br />
{{User:Piphi/Template:Progress_Bar|18.29|width=100%}}</div><br />
</div></div>Anstarhttps://artofproblemsolving.com/wiki/index.php?title=AoPS_Wiki:Administrators&diff=130745AoPS Wiki:Administrators2020-08-06T05:40:12Z<p>Anstar: Undo revision 130743 by Anstar (talk)</p>
<hr />
<div>{{shortcut|[[A:ADMIN]]}}<br />
<br />
'''Administrators''' (commonly known as '''sysops''' or '''admins''') on the [[AoPSWiki:About|AoPSWiki]] have certain powers which are not granted to ordinary users. <br />
<br />
==Admin abilities==<br />
Administrators have easy one-click rollback abilities to revert the previous user's moves; however, the rollback ability is generally only used to revert vandalism. If the revert is of a legitimate edit, then no useful edit summary is left and the revert may be seen as abusage of admin powers. <br />
<br />
They have the power to permanently delete articles beyond the average user's ability to restore, though administrators can restore these deleted articles. As a direct result, they can also move articles to the location of other already-existing articles by simply deleting the other one.<br />
<br />
Administrators have access to [[Special:Unwatchedpages]], a list containing all of the articles on the wiki which aren't being watched by users. This is to minimize the amount of damage that can be potentially done by a vandal. Sysops also have access to certain other special pages.<br />
<br />
There is also a protection ability in which articles subject to vandalism or other disputes can be locked from editing. Articles can be semi-protected, which bans new users from editing that article. They can also be fully-protected, which then only lets other sysops to edit. There are similar protection abilities against page moves to prevent page-move vandalism. <br />
<br />
Administrators also can block (prevent from editing all of the wiki except their own user page and user talk page) or ban (prevent from logging in) any user.<br />
<br />
Mostly only the administrators of the AoPS forums and certain moderators on the AoPS forums are administrators.<br />
<br />
==Bureaucrats==<br />
{{shortcut|[[A:BUREAU]]}}<br />
A '''bureaucrat''' is a special type of administrator with the ability to make users into sysops and other bureaucrats. Mostly only forum administrators are bureaucrats on the AoPSWiki.<br />
<br />
Bureaucrats have access to [[Special:Userrights]], where they edit user permissions.<br />
<br />
==List of sysops==<br />
* 5space<br />
* Ahuhn<br />
* Azjps<br />
* Btilm305<br />
* Copeland<br />
* DPatrick<br />
* IntrepidMath<br />
* JBL<br />
* LauraZed<br />
* Levans<br />
* Minsoens<br />
* Phxu<br />
* Rrusczyk<br />
* Sheriff<br />
* Solafidefarms<br />
* Valentin Vornicu<br />
* WikiSysop<br />
<br />
==List of bureaucrats==<br />
* 5space<br />
* Ahuhn<br />
* Copeland<br />
* DPatrick<br />
* LauraZed<br />
* Levans<br />
* Phxu<br />
* Rrusczyk<br />
* Sheriff<br />
* WikiSysop<br />
<br />
[[Category:AoPSWiki|Administrators]]</div>Anstarhttps://artofproblemsolving.com/wiki/index.php?title=AoPS_Wiki:Administrators&diff=130743AoPS Wiki:Administrators2020-08-06T05:39:08Z<p>Anstar: Added user links</p>
<hr />
<div>{{shortcut|[[A:ADMIN]]}}<br />
<br />
'''Administrators''' (commonly known as '''sysops''' or '''admins''') on the [[AoPSWiki:About|AoPSWiki]] have certain powers which are not granted to ordinary users. <br />
<br />
==Admin abilities==<br />
Administrators have easy one-click rollback abilities to revert the previous user's moves; however, the rollback ability is generally only used to revert vandalism. If the revert is of a legitimate edit, then no useful edit summary is left and the revert may be seen as abusage of admin powers. <br />
<br />
They have the power to permanently delete articles beyond the average user's ability to restore, though administrators can restore these deleted articles. As a direct result, they can also move articles to the location of other already-existing articles by simply deleting the other one.<br />
<br />
Administrators have access to [[Special:Unwatchedpages]], a list containing all of the articles on the wiki which aren't being watched by users. This is to minimize the amount of damage that can be potentially done by a vandal. Sysops also have access to certain other special pages.<br />
<br />
There is also a protection ability in which articles subject to vandalism or other disputes can be locked from editing. Articles can be semi-protected, which bans new users from editing that article. They can also be fully-protected, which then only lets other sysops to edit. There are similar protection abilities against page moves to prevent page-move vandalism. <br />
<br />
Administrators also can block (prevent from editing all of the wiki except their own user page and user talk page) or ban (prevent from logging in) any user.<br />
<br />
Mostly only the administrators of the AoPS forums and certain moderators on the AoPS forums are administrators.<br />
<br />
==Bureaucrats==<br />
{{shortcut|[[A:BUREAU]]}}<br />
A '''bureaucrat''' is a special type of administrator with the ability to make users into sysops and other bureaucrats. Mostly only forum administrators are bureaucrats on the AoPSWiki.<br />
<br />
Bureaucrats have access to [[Special:Userrights]], where they edit user permissions.<br />
<br />
==List of sysops==<br />
* {{user link|5space}}<br />
* {{user link|Ahuhn}}<br />
* {{user link|Azjps}}<br />
* {{user link|Btilm305}}<br />
* {{user link|Copeland}}<br />
* {{user link|DPatrick}}<br />
* IntrepidMath<br />
* JBL<br />
* LauraZed<br />
* Levans<br />
* Minsoens<br />
* Phxu<br />
* Rrusczyk<br />
* Sheriff<br />
* Solafidefarms<br />
* Valentin Vornicu<br />
* WikiSysop<br />
<br />
==List of bureaucrats==<br />
* 5space<br />
* Ahuhn<br />
* Copeland<br />
* DPatrick<br />
* LauraZed<br />
* Levans<br />
* Phxu<br />
* Rrusczyk<br />
* Sheriff<br />
* WikiSysop<br />
<br />
[[Category:AoPSWiki|Administrators]]</div>Anstarhttps://artofproblemsolving.com/wiki/index.php?title=AoPS_Wiki:Administrators&diff=130739AoPS Wiki:Administrators2020-08-06T05:35:43Z<p>Anstar: </p>
<hr />
<div>{{shortcut|[[A:ADMIN]]}}<br />
<br />
'''Administrators''' (commonly known as '''sysops''' or '''admins''') on the [[AoPSWiki:About|AoPSWiki]] have certain powers which are not granted to ordinary users. <br />
<br />
==Admin abilities==<br />
Administrators have easy one-click rollback abilities to revert the previous user's moves; however, the rollback ability is generally only used to revert vandalism. If the revert is of a legitimate edit, then no useful edit summary is left and the revert may be seen as abusage of admin powers. <br />
<br />
They have the power to permanently delete articles beyond the average user's ability to restore, though administrators can restore these deleted articles. As a direct result, they can also move articles to the location of other already-existing articles by simply deleting the other one.<br />
<br />
Administrators have access to [[Special:Unwatchedpages]], a list containing all of the articles on the wiki which aren't being watched by users. This is to minimize the amount of damage that can be potentially done by a vandal. Sysops also have access to certain other special pages.<br />
<br />
There is also a protection ability in which articles subject to vandalism or other disputes can be locked from editing. Articles can be semi-protected, which bans new users from editing that article. They can also be fully-protected, which then only lets other sysops to edit. There are similar protection abilities against page moves to prevent page-move vandalism. <br />
<br />
Administrators also can block (prevent from editing all of the wiki except their own user page and user talk page) or ban (prevent from logging in) any user.<br />
<br />
Mostly only the administrators of the AoPS forums and certain moderators on the AoPS forums are administrators.<br />
<br />
==Bureaucrats==<br />
{{shortcut|[[A:BUREAU]]}}<br />
A '''bureaucrat''' is a special type of administrator with the ability to make users into sysops and other bureaucrats. Mostly only forum administrators are bureaucrats on the AoPSWiki.<br />
<br />
Bureaucrats have access to [[Special:Userrights]], where they edit user permissions.<br />
<br />
==List of sysops==<br />
* 5space<br />
* Ahuhn<br />
* Azjps<br />
* Btilm305<br />
* Copeland<br />
* DPatrick<br />
* IntrepidMath<br />
* JBL<br />
* LauraZed<br />
* Levans<br />
* Minsoens<br />
* Phxu<br />
* Rrusczyk<br />
* Sheriff<br />
* Solafidefarms<br />
* Valentin Vornicu<br />
* WikiSysop<br />
<br />
==List of bureaucrats==<br />
* 5space<br />
* Ahuhn<br />
* Copeland<br />
* DPatrick<br />
* LauraZed<br />
* Levans<br />
* Phxu<br />
* Rrusczyk<br />
* Sheriff<br />
* WikiSysop<br />
<br />
[[Category:AoPSWiki|Administrators]]</div>Anstarhttps://artofproblemsolving.com/wiki/index.php?title=AoPS_Wiki:Administrators&diff=130738AoPS Wiki:Administrators2020-08-06T05:35:14Z<p>Anstar: </p>
<hr />
<div>{{shortcut|[[A:ADMIN]]}}<br />
<br />
'''Administrators''' (commonly known as '''sysops''' or '''admins''') on the [[AoPSWiki:About|AoPSWiki]] have certain powers which are not granted to ordinary users. <br />
<br />
==Admin abilities==<br />
Administrators have easy one-click rollback abilities to revert the previous user's moves; however, the rollback ability is generally only used to revert vandalism. If the revert is of a legitimate edit, then no useful edit summary is left and the revert may be seen as abusage of admin powers. <br />
<br />
They have the power to permanently delete articles beyond the average user's ability to restore, though administrators can restore these deleted articles. As a direct result, they can also move articles to the location of other already-existing articles by simply deleting the other one.<br />
<br />
Administrators have access to [[Special:Unwatchedpages]], a list containing all of the articles on the wiki which aren't being watched by users. This is to minimize the amount of damage that can be potentially done by a vandal. Sysops also have access to certain other special pages.<br />
<br />
There is also a protection ability in which articles subject to vandalism or other disputes can be locked from editing. Articles can be semi-protected, which bans new users from editing that article. They can also be fully-protected, which then only lets other sysops to edit. There are similar protection abilities against page moves to prevent page-move vandalism. <br />
<br />
Administrators also can block (prevent from editing all of the wiki except their own user page and user talk page) or ban (prevent from logging in) any user.<br />
<br />
Mostly only the administrators of the AoPS forums and certain moderators on the AoPS forums are administrators.<br />
<br />
==Bureaucrats==<br />
{{shortcut|[[A:BUREAU]]}}<br />
A '''bureaucrat''' is a special type of administrator with the ability to make users into sysops and other bureaucrats. Mostly only forum administrators are bureaucrats on the AoPSWiki.<br />
<br />
Bureaucrats have access to [[Special:Userrights]], where they edit user permissions.<br />
<br />
==List of sysops==<br />
* [[5space]]<br />
* [[Ahuhn]]<br />
* Azjps<br />
* Btilm305<br />
* Copeland<br />
* DPatrick<br />
* IntrepidMath<br />
* JBL<br />
* LauraZed<br />
* Levans<br />
* Minsoens<br />
* Phxu<br />
* Rrusczyk<br />
* Sheriff<br />
* Solafidefarms<br />
* Valentin Vornicu<br />
* WikiSysop<br />
<br />
==List of bureaucrats==<br />
* 5space<br />
* Ahuhn<br />
* Copeland<br />
* DPatrick<br />
* LauraZed<br />
* Levans<br />
* Phxu<br />
* Rrusczyk<br />
* Sheriff<br />
* WikiSysop<br />
<br />
[[Category:AoPSWiki|Administrators]]</div>Anstarhttps://artofproblemsolving.com/wiki/index.php?title=User:Anstar&diff=130736User:Anstar2020-08-06T05:27:40Z<p>Anstar: </p>
<hr />
<div>Anstar lives in the USA and likes doing math and programming.</div>Anstarhttps://artofproblemsolving.com/wiki/index.php?title=Cosmology&diff=130734Cosmology2020-08-06T05:22:59Z<p>Anstar: Created page with "Cosmology is a science about the begins of the universe"</p>
<hr />
<div>Cosmology is a science about the begins of the universe</div>Anstarhttps://artofproblemsolving.com/wiki/index.php?title=Basic_Programming_With_Python&diff=130600Basic Programming With Python2020-08-04T20:03:09Z<p>Anstar: /* Defining a class */</p>
<hr />
<div>'''Important: It is extremely recommended that you read [[Getting Started With Python Programming]] before reading this unless you already know some programming knowledge.'''<br />
<br />
(Note: This is a really long article. To learn the most from this article, you need to read everything in order and skip nothing, unless you are '''absolutely absolutely sure that that content is way too easy for you.''')<br />
<br />
This article will talk about some basic Python programming. If you don't even know how to install Python, look [[Getting Started With Python Programming|here]].<br />
<br />
Note that this article has lots of program examples. It is recommended (but not required) to try these on your own before looking at the solutions.<br />
<br />
==Loops==<br />
<br />
There are two different kinds of loops in Python: the for loop and the while loop.<br />
<br />
===The For Loop===<br />
<br />
The for loop iterates over a list, or an array, of objects. You have probably seen this code before:<br />
<br />
[[File:Capture.PNG|200px]]<br />
<br />
This for loop iterates over the list of integers from 1 to 51, excluding the 51 and including the 1. That means it is a list from 1 to 50, inclusive. On every iteration, Python will print the number that the loop is iterating through. <br />
<br />
For example, in the first iteration, i = 1, so Python prints 1.<br />
<br />
In the second iteration, i = 2, so Python prints 2.<br />
<br />
This continues so on until the number, 50, is reached. Therefore, the last number Python will print out is 50.<br />
<br />
====Program Example====<br />
<br />
'''Find <math>\sum_{n=1}^{50} 2^{n}.</math>'''<br />
<br />
To do this task, we must create a for loop and loop over the integers from 1 to 50 inclusive:<br />
<br />
for i in range(1,51):<br />
<br />
Now what? We must keep a running total and increase it by <math>2^i</math> every time:<br />
<br />
total = 0<br />
for i in range(1,51):<br />
total += 2**i<br />
<br />
We must not forget to print the total at the end!<br />
<br />
total = 0<br />
for i in range(1,51):<br />
total += 2**i<br />
print(total)<br />
<br />
You must exit out of the for loop one you reach the print(total) line by pressing backspace.<br />
<br />
Once you run your program, you should get an answer of <math>\boxed{2,251,799,813,685,246.}</math><br />
<br />
===The While Loop===<br />
<br />
While loops don't loop over a list. They loop over and over and over...'''until'''...a condition becomes false.<br />
<br />
i = 3<br />
total = 0<br />
while i < 1000:<br />
total += i<br />
i += 3<br />
print(total)<br />
<br />
In this code, the while loop loops 333 times, until <math>i</math> becomes greater than or equal to 1000.<br />
<br />
====Program Example====<br />
<br />
'''Find <math>\sum_{n=1}^{50} 2^n</math> using a while loop.'''<br />
<br />
We must create a while loop that will iterate until n is greater than <math>50.</math><br />
<br />
n = 1<br />
total = 0<br />
while n <= 50:<br />
total += 2**n<br />
n += 1<br />
print(total)<br />
<br />
We must not forget to include the n += 1 line at the end of the while loop! <br />
<br />
If we run this, we will get the same answer as last time, <math>2,251,799,813,685,246.</math><br />
<br />
==Functions==<br />
<br />
In this section, we will define new operations and do arithmetic with them in Python.<br />
<br />
===The New Operation===<br />
Let's say that you defined a new binary operation, the <math>\uparrow \downarrow.</math> You want it to be so <math>a \uparrow \downarrow b = a^{b}b^{a}.</math> Therefore, <math>1\uparrow \downarrow 2 = 1^{2}2^{1}=1\cdot 2= 2,</math> and <math>2\uparrow \downarrow 3 = 2^33^2 = 8\cdot 9 = 72.</math> Let's call this operation an '''up down arrow.'''<br />
<br />
===Program Example 1===<br />
<br />
'''Find <math>[2 \uparrow \downarrow (1 \uparrow \downarrow 2)] \uparrow \downarrow 2.</math>'''<br />
<br />
We know this will be a big number, so we should write a program to do it! We certainly don't want to do the exponentiation and multiplication every time we use the operation in our program, and that's where functions come in! Functions can take in parameters (<math>a</math> and <math>b</math>) and return a result depending on the parameters.<br />
<br />
def up_down_arrow(a,b): <br />
return ((a**b) * (b**a))<br />
<br />
Above is the code to define our function. We need to print the final result at the end, so we must put a print statement at the end.<br />
<br />
def up_down_arrow(a,b): <br />
return ((a**b) * (b**a))<br />
print(up_down_arrow(up_down_arrow(2,up_down_arrow(1,2)),2)<br />
<br />
All those nested up_down_arrow's might be confusing at first, but it really isn't that confusing.<br />
If you run your program, you should get your answer: <math>16,777,216.</math> <br />
<br />
You might be surprised that the answer is so big. If you actually start calculating the real answer without a program, you will really quickly find that the final result is <math>16 \uparrow \downarrow 2,</math> which does turn out to be 16,777,216 if you use a calculator.<br />
<br />
Let's make another operation!<br />
<br />
We will define the operation <math>\uparrow \downarrow \leftarrow \rightarrow</math> to be called '''all around.''' <math>a \uparrow \downarrow \leftarrow \rightarrow b = (ab(a \uparrow \downarrow b))^2.</math> That's an operation that will make really big numbers!<br />
<br />
===Program Example 2===<br />
<br />
'''Find 87 all around 132.'''<br />
<br />
The answer is bound to be a huge number, so we must make a program to solve it.<br />
<br />
We will keep our up_down_arrow function because in the definition of our all_around function we will use it. Then, we will define the all_around function.<br />
<br />
def up_down_arrow(a,b):<br />
return ((a**b) * (b**a))<br />
def all_around(a,b):<br />
return ((a * b * up_down_arrow(a,b)) ** 2)<br />
<br />
We must print all_around(87,132) at the end. Once we do that, and we run our program, we get a super huge number that has over 800 digits!<br />
<br />
===Understanding Functions===<br />
<br />
Every single function has a '''return value'''. If a function does not return anything, the return value is '''null'''. Null is a term used in programming as a placeholder that stands for nothing.<br />
<br />
====Simple Program Example 1====<br />
<br />
'''Define a function that adds 1 to an input.'''<br />
<br />
How will the function know what number to add 1 to? We will input a '''parameter''' for the function to add 1 to.<br />
<br />
def add_one(x):<br />
return x + 1<br />
<br />
In this function, <math>x</math> is the parameter.<br />
<br />
def add_one(x):<br />
return x + 1<br />
print(add_one(2))<br />
<br />
In the print statement, we set <math>x</math> as 2, and the function returns <math>2 + 1 = 3,</math> so the program prints <math>3</math>.<br />
<br />
====Simple Program Example 2====<br />
<br />
'''Define a function that prints out an input.'''<br />
<br />
We will use a parameter again.<br />
<br />
def print_function(x):<br />
print(x)<br />
<br />
Uh oh! We have nothing to return! Therefore, we will return nothing (or null), by just writing return.<br />
<br />
def print_function(x):<br />
print(x)<br />
return<br />
print_function("print_function")<br />
<br />
This code prints out print_function. print_function() is said to be '''called''' in the final line of the code. Again, we set <math>x</math>, our parameter, as "print_function."<br />
== Classes ==<br />
Classes are <br />
<br />
===Defining a class===<br />
We can define a class by doing the following:<br />
<br />
<br />
class example:<br />
pass<br />
<br />
<br />
We can call a class by doing the following<br />
<br />
===methods===<br />
methods are definition that apply to a class.<br />
===__init__===<br />
===__str__===<br />
===overloading===<br />
overloading means changing a builtin function to do what you want it to do.<br />
<br />
==Flow==<br />
<br />
Flow consists of if statements, elif (else if) statements, and else statements.<br />
<br />
*An if statement checks if a comparison is true.<br />
<br />
*An else statement checks if a comparison is not true. It is used after an if statement (and all elif statements after the if statement) and it shares the same comparison as the if statement.<br />
<br />
*An elif statement checks for two things: if a comparison is true, and if a comparison is not true. It is used right after the if statement.<br />
<br />
===Program Example===<br />
<br />
'''Does the number 10 have the property that when you multiply 10 by 5, you get a two digit number?'''<br />
<br />
This problem is super easy to solve without a program, but let's write a program to solve this anyway. We will use an if statement to check if <math>10\cdot 5</math> is less than 100 and greater than 9.<br />
<br />
if 10*5 > 9:<br />
if 10*5 < 100:<br />
print("Yes")<br />
else:<br />
print("No")<br />
else:<br />
print("No")<br />
<br />
This code means, if 10*5 > 9, then we will check if it is less than 100. If it is not greater than 9, however, we will print No. If it is greater than 9, we check if it is less than 100. If it is, we print Yes. If it isn't we print No.<br />
<br />
These nested if statements can be very confusing. Luckily, there is a faster an easier way to do this.<br />
<br />
if 10*5 > 9 and 10*5 < 100:<br />
print("Yes") <br />
else:<br />
print("No")<br />
<br />
This code checks for the two conditions at the same time. If we run it, we get our answer of Yes.<br />
<br />
==Booleans==<br />
<br />
===Program Example===<br />
<br />
'''Print all two-digit positive integers <math>x</math> such that <math>5x</math> is a two-digit positive integer.'''<br />
<br />
We can create a function with our previous code.<br />
<br />
We will have to slightly modify our function so we can use it in a for loop at the end:<br />
<br />
def check(a):<br />
if a*5 > 9 and a*5 < 100:<br />
return True <br />
else:<br />
return False<br />
<br />
True and False are what are called '''booleans'''. When an if or elif statement receives True, the code inside of the statement happens. When an if or elif statement receives False, the code inside of the statement does not happen. <br />
<br />
We must create a for loop that will iterate through all two digit positive integers. <br />
<br />
def check(a):<br />
if a*5 > 9 and a*5 < 100:<br />
return True <br />
else:<br />
return False<br />
for i in range(10,100):<br />
if check(i):<br />
print(i)<br />
<br />
The final for loop checks if <math>5i</math> is a two digit integer. If it is, the function returns True and the code inside the if statement gets run. If it isn't, the function returns False and the code inside the if statement gets ignored.<br />
<br />
If we run this, we will get the answer.<br />
<br />
All two digit integers from 10 to 19 inclusive work!<br />
<br />
=="Soft Coding" Programs==<br />
<br />
In the next few examples, you will see why hard coding programs is bad. Hard coding programs refers to coding a program that is hard to modify. For example:<br />
<br />
===Program Example 1===<br />
<br />
'''Print all two digit positive integers <math>x</math> such that <math>5x</math> is a three digit positive integer.'''<br />
<br />
We can keep our code and modify some parts of it.<br />
<br />
def check(a, min, max):<br />
if a*5 > min - 1 and a*5 < max + 1:<br />
return True <br />
else:<br />
return False<br />
<br />
def print_check(range_min, range_max, check_min, check_max):<br />
for i in range(range_min, range_max + 1):<br />
if check(i, check_min, check_max):<br />
print(i)<br />
return<br />
<br />
print_check(10, 99, 100, 999)<br />
<br />
Why did we add so many functions?<br />
<br />
Well, if the numbers in a problem change (and the words stay the same), and you need to change a lot of numbers in your program, your program is considered '''hard-coded'''. We want our programs to be as '''soft-coded''' as possible. In our new program, we only need to change 4 numbers (in the print_check() statement) if the numbers in the problem change. Therefore, our program is relatively soft-coded. There are still ways to soft-code this program even more, though.<br />
<br />
If we run our program, we get our answer.<br />
<br />
All numbers from 20 to 99 work!<br />
<br />
===Program Example 2===<br />
<br />
'''Print all three digit positive integers <math>x</math> such that <math>5x</math> is a three digit positive integer.'''<br />
<br />
We can just change the print_check line at the end to<br />
<br />
print_check(100, 999, 100, 999)<br />
<br />
and our program will be ready to be run.<br />
<br />
All numbers from 100 to 199 work.<br />
<br />
===Program Example 3===<br />
<br />
'''Print all two digit positive integers <math>x</math> such that <math>3x</math> is a three digit positive integer.'''<br />
<br />
Uh oh. Only changing the print_check line won't work. We will need to change our functions!<br />
<br />
def check(a, min, max, factor):<br />
if a*factor > min - 1 and a*factor < max + 1:<br />
return True <br />
else:<br />
return False<br />
<br />
def print_check(range_min, range_max, check_min, check_max, check_factor):<br />
for i in range(range_min, range_max + 1):<br />
if check(i, check_min, check_max, check_factor):<br />
print(i)<br />
return<br />
<br />
print_check(10, 99, 100, 999, 3)<br />
<br />
In this step, we added a parameter in both functions. We also soft-coded our program even more! Hooray!<br />
<br />
All integers from 34 to 99 work.<br />
<br />
===Program Example 4===<br />
<br />
'''Print all two digit positive integers <math>x</math> such that <math>12x</math> is a positive integer from 500 to 900.'''<br />
<br />
This problem may look a bit different from the other ones, but it really is the same thing, except that the factor is 12 and check_min and check_max are 500 and 900, respectively.<br />
<br />
Once we change the final print_check() line to satisfy our needs, we can run our program.<br />
<br />
All numbers from 42 to 75 work!<br />
<br />
Congrats! You have written your first programs above 10 lines of code!<br />
<br />
==Random==<br />
<br />
There is a package in Python that allows the use of random numbers.<br />
<br />
===Program Example 1===<br />
<br />
'''Generate a random number from 1 to 6.'''<br />
<br />
Easy peasy. We will just generate a random number from 1 to 6 with the package like this:<br />
<br />
import random<br />
print(random.randint(1,6))<br />
<br />
As you can see, when you run this program, you get a random integer from 1 to 6.<br />
<br />
===Program Example 2===<br />
<br />
'''Simulate the rolling of 1000 dice. Now, count the number of times you roll 6. Print that number out.'''<br />
<br />
We can create a function that returns a random number from 1 to 6. Then, we can make a for loop that rolls the dice 1000 times and check if it is a 6.<br />
<br />
import random<br />
count = 0<br />
<br />
def roll():<br />
return random.randint(1,6)<br />
<br />
for i in range(1, 1001):<br />
if roll() == 6:<br />
count += 1<br />
<br />
print(count)<br />
<br />
If we run this, we will get a number around 170.<br />
<br />
===Program Example 3===<br />
<br />
'''Simulate the rolling of 10,000 dice. Now, count the amount of times you roll 3. Print that amount out.'''<br />
<br />
We can keep our roll function and our code inside the for loop, but we need to change our for loop statement.<br />
<br />
We can actually soft-code our program more. Let's turn the whole for loop into a function!<br />
<br />
import random<br />
<br />
def roll():<br />
return random.randint(1,6)<br />
<br />
def count(amount):<br />
count_ = 0<br />
<br />
for i in range(1, amount+1):<br />
if roll() == 3:<br />
count_ += 1<br />
return count_<br />
<br />
print(count(10000))<br />
<br />
If we run this code, it works.<br />
<br />
===Program Example 4===<br />
<br />
'''One of my friends loves rolling dice. He is going to roll 1 die tomorrow, 2 dice two days from now, 3 dice three days from now, and so on so that he rolls <math>a</math> dice <math>a</math> days from now. He gets tired rolling dice after rolling dice for 365 days (so the last day he rolls 365 dice). In Python, simulate this. How many times does he roll 3 after 365 days of rolling dice?'''<br />
<br />
We can use a for loop that calls a function multiple times.<br />
<br />
import random<br />
<br />
def roll():<br />
return random.randint(1,6)<br />
<br />
def count(amount):<br />
count_ = 0<br />
for i in range(1, amount+1):<br />
if roll() == 3:<br />
count_ += 1<br />
return count_<br />
<br />
total = 0<br />
<br />
for i in range(1, 366):<br />
total += count(i)<br />
<br />
print(total)<br />
<br />
This is a really long program, but the whole program should make sense if you look at it for a while. We defined our count function in the previous example, and now we are using it with a for loop and a running total. <br />
<br />
You should get a number around 11,000 when you run it. Wow, lots of 3's!<br />
<br />
===Program Example 5===<br />
<br />
'''20 of my friends love rolling dice. They are all going to roll 1 die each tomorrow, 2 dice each two days from now, 3 dice each three days from now, and so on so that they roll <math>a</math> dice each <math>a</math> days from now. But, one of my friends gets tired very quickly and he only rolls dice for 1 day and stops. Another friend only will roll dice for 2 days, and another will roll dice for three days only, and so on up to the fact that my last friend will roll dice for 20 days. In Python, simulate this. How many times does someone roll 3 after everything?'''<br />
<br />
We will have to make our for loop into a function again.<br />
<br />
import random<br />
<br />
def roll():<br />
return random.randint(1,6)<br />
<br />
def count(amount):<br />
count_ = 0<br />
for i in range(1, amount+1):<br />
if roll() == 3:<br />
count_ += 1<br />
return count_<br />
<br />
def count2(amount)<br />
total = 0<br />
for i in range(1, amount + 1):<br />
total += count(i)<br />
return total<br />
<br />
def count3(amount)<br />
total = 0<br />
for i in range(1, amount + 1):<br />
total += count2(i)<br />
return total<br />
<br />
print(count3(20))<br />
<br />
(Our program is so long!)<br />
<br />
I also made a new function just in case we needed to turn that into a function later.<br />
<br />
'''Make sure''' you read the code carefully and you fully understand it. If you don't understand every single line of code, then you will get confused later on in this article.<br />
<br />
When you run this program, you might be surprised that the answer isn't so big.<br />
<br />
===Program Example 6===<br />
<br />
'''365 of my friends love rolling dice. They are all going to roll 1 die each tomorrow, 2 dice each two days from now, 3 dice each three days from now, and so on so that they roll <math>a</math> dice each <math>a</math> days from now. But, one of my friends gets tired very quickly and he only rolls dice for 1 day and stops. Another friend only will roll dice for 2 days, and another will roll dice for three days only, and so on up to the fact that my last friend will roll dice for 365 days. In Python, simulate this. How many times does someone roll 3 after everything?'''<br />
<br />
Because we soft-coded our program so much, all we have to do is change the last line so the parameter of count3() is 365.<br />
<br />
If we run it...we get a big answer, as expected. It also takes quite a while!<br />
<br />
You may not have realized that we soft-coded our program at all, but the whole point of functions is to soft-code programs!<br />
<br />
Congrats on writing a program that is around 25 lines long!<br />
<br />
==Very Basic Datatypes==<br />
<br />
An integer is a basic datatype in Python. Basically, all variables with the datatype of '''int''' is an integer.<br />
<br />
A string is another basic datatype, and it is a string of characters enclosed by quotes.<br />
<br />
===Why Are Datatypes So Important?===<br />
<br />
Let's say we wanted to make a program that would add 2 and 3. Some bogus code would be:<br />
<br />
x="2"<br />
y="3"<br />
print(x+y)<br />
<br />
If you ran this code, you would get 23. Why is that?<br />
<br />
Well, here, x and y are strings. When you perform the addition operator to strings in Python, it concatenates the strings, giving 23.<br />
<br />
The real code is:<br />
<br />
x=2<br />
y=3<br />
print(x+y)<br />
<br />
If you run this, you will get <math>5</math>, which is correct.<br />
<br />
Here's another reason datatypes are important. Now, we will introduce the datatype called the '''floating point number''', or '''float'''. A floating-point number is a number with a decimal point.<br />
<br />
Let's go back to the IDLE. Type "0.1*10". The result is 1.0. Notice the decimal point.<br />
<br />
Let's type something different. Type <math>0.1+0.1+0.1+0.1+0.1+0.1+0.1+0.1+0.1+0.1.</math><br />
<br />
'''WHAT!?'''<br />
<br />
You would have expected the answer to be 1, but it isn't 1. What happened?<br />
<br />
'''Float approximation''' happened. Most (almost all) programming languages have a bad float approximation. That means that 1.0 can turn into 0.99999999999999 and 0.5 can turn into 0.49999999999999999993. That only happens with floats, so we should try to use floats as sparingly as possible.<br />
<br />
==Lists==<br />
<br />
A for loop iterates over a '''list'''. A list is a bunch of objects stored in one variable. (Hey! A list is a datatype!) For loops are highly related to lists.<br />
<br />
Let's say we wanted to make a program to print all the items in a list.<br />
<br />
We will first create the list, using the code:<br />
<br />
myList = [1,4,6,8]<br />
<br />
This is a list with four items: 1, 4, 6, and 8.<br />
<br />
We must now print all elements of it with a for loop:<br />
<br />
myList = [1,4,6,8]<br />
for i in myList:<br />
print(i)<br />
<br />
When we run this program, we get the numbers 1, 4, 6, and 8, as expected.<br />
<br />
===Accessing Values===<br />
<br />
Let's say we wanted to print out the second item in a list. We will use '''indexes'''.<br />
<br />
The index of the first item in a list is always 0. The index of the second is 1. The index of the <math>n</math>th is <math>n-1.</math><br />
<br />
To print out the second item, we will use an index of 1, like this:<br />
<br />
myList = [1,4,6,8]<br />
print(myList[1])<br />
<br />
Notice that the index is inside of the square brackets.<br />
<br />
===Adding Values===<br />
<br />
We can use the list.append() function to add an object to the end of a list.<br />
<br />
myList.append(10)<br />
<br />
will add 10 to the list, which makes myList = [1,4,6,8,10].<br />
<br />
===Removing Items From Lists===<br />
<br />
We can use the list.remove() function to remove a specific item in a list.<br />
<br />
For example, consider this code.<br />
<br />
myList = [1,2,3]<br />
myList.remove(3)<br />
<br />
This code will make myList turn into [1,2]. The element, 3, gets removed.<br />
<br />
===len(list)===<br />
<br />
The len(list) function returns the length of a list.<br />
<br />
This code will print 3.<br />
<br />
myList = [1,2,3]<br />
print(len(myList))<br />
<br />
The length of myList is 3, so Python prints 3.<br />
<br />
===All Kinds Of Lists===<br />
<br />
Lists don't have to be only integers!<br />
<br />
myList = [1,"Hi","Hello world", 3.5, 3.14159265358979323]<br />
<br />
If fact, there can be lists inside of lists!<br />
<br />
myList = [[1,2,3], [3,4,5], [5,6,"Hello world"], "BOB", 3.1415926]<br />
<br />
Even this!<br />
<br />
myList = [[1, [1, [1,2,3],3],3], [[[3,["Hello world", 4],5],4,5],4,5], [5,6,7,[1,[1,2,3],3],"Hello world"], "BOB", 3.1415926, True]<br />
<br />
If you look at that list carefully, you will find lists inside of lists inside of lists inside of lists! And, a boolean at the end!<br />
<br />
Like variables, you can have as many lists in a program as you want (a list is a variable)!<br />
<br />
myList = [1,2,3,4]<br />
yourList = [5,6,7,8]<br />
hisList = [9,10,11,12]<br />
herList = [13,14,15,16]<br />
theirList = [17,18,19,20]<br />
ourList = [21,22,23,24]<br />
listsOfLists = [[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16],[17,18,19,20],[21,22,23,24]]<br />
<br />
===Splitting Lists===<br />
Split Operator Basics:<br />
genericList[where to start:where to end:what size steps to take]<br />
The value where to start is inclusive, and denotes the index where your split list begins. It has a default value of 0.<br />
The value where to end is exclusive, and denotes the index where your split list ends. It has a default value of len(genericList).<br />
The value what size steps denotes the size of the steps your split takes(more on that later). It has a default value of 1.<br />
Say you want to split a list and only return certain indices, for example if you wanted to split a list called data and put the first two elements into a list called head and the last two into a list called tail, you would split like this:<br />
data = [1, 3, 4, 23.5, 40, 55]<br />
head = data[:2]<br />
tail = data[-2:] # negative list indices represent the end of a list, so -1 is the last element and -2 is the second-to-last<br />
Step Size:<br />
We will practice writing a few functions that select every other element and will reverse in a list using step size.<br />
A step size of two means skip every other list index, so we can write our first function.<br />
def selectEveryOtherElement(list):<br />
return list[::2]<br />
But which step size will get us our desired reversed list. We could start at the end of the list and iterate backwards, but how would we do that...<br />
Negative Step Size:<br />
A step size that is negative means skip a certain amount of elements, but backwards. If we were to start at 0, with a step size of -1, we would be able to iterate backwards over the list!<br />
def reverse(list):<br />
return list[::-1]<br />
Splitting lists with ratios:<br />
What if we wanted to be able to split a list based upon a ratio. For example, the common 80:20 train to test ratio in machine learning? Here is how you would do it<br />
def eighty-twenty(list):<br />
train = list[:int(len(list) * (4 / 5))] # We must include the int() method to convert to an integer if len(list) % 5 != 0<br />
test = list[int(len(list) * 4 / 5)]<br />
return [train, test] # We then return a list with the train and test lists inside<br />
<br />
==Dictionaries==<br />
<br />
A dictionary (a type of datatype) is a bunch of keys and values. There is a major difference between dictionaries and lists. Lists are ordered; dictionaries are not.<br />
<br />
Here is the '''syntax''' of creating a dictionary:<br />
<br />
myDictionary = {1:"one",2:"two"}<br />
<br />
This dictionary has two key/value pairs. Notice it is surrounded in curly braces. The keys are 1 and 2; the values are "one" and "two."<br />
<br />
How is this useful? Let's make a simple program to test it out.<br />
<br />
myDictionary = {1:"one",2:"two"}<br />
print(myDictionary[1])<br />
print(myDictionary[2])<br />
<br />
===Accessing Values===<br />
<br />
To access a value in a dictionary, you put in the key.<br />
<br />
myDictionary[1]<br />
<br />
returns one, because 1 is the key to "one."<br />
<br />
===Adding New Values===<br />
<br />
To overwrite a value, we do this.<br />
<br />
myDictionary[1] = "won"<br />
<br />
The value to the key 1 is now "won."<br />
<br />
To add a value, we do the same thing!<br />
<br />
myDictionary[3] = "three"<br />
<br />
This adds a key 3 with a value of "three."<br />
<br />
==Misc Concepts==<br />
<br />
This section will talk about some concepts that we haven't learned yet.<br />
<br />
====Concatenating Strings====<br />
<br />
Concatenating strings is putting them together. For example, "one" concatenated with "two" gives "onetwo."<br />
<br />
The following string,<br />
<br />
"Hello, " + person2 + "! How are you?"<br />
<br />
depends on what person2 was. If person2 was Bob, the string would be:<br />
<br />
"Hello, Bob! How are you?"<br />
<br />
It fits together perfectly!<br />
<br />
You cannot concatenate strings with integers. For example, doing this:<br />
<br />
"2" + 3<br />
<br />
will not work. Instead, to get an answer of "23", you must do this:<br />
<br />
"2" + str(3)<br />
<br />
That turns 3 into a string so it is "3", and the result will be "23".<br />
<br />
====Line Breaks====<br />
<br />
We can use multiple line breaks to make our code more organized. There are some places that you cannot line break. For example, this code will produce an error:<br />
<br />
myList =<br />
[1,2,3]<br />
<br />
This code does not work.<br />
<br />
This code '''does work''':<br />
<br />
myList = [<br />
1,2,3]<br />
<br />
It is accepted when you break a line right after the [. It is also accepted right after a comma. (And right before the ending ].)<br />
<br />
myList = [<br />
1,<br />
2,<br />
3<br />
]<br />
<br />
==Challenge Program==<br />
<br />
In this section, we will attempt the hardest program so far in this article.<br />
<br />
'''Make a conversation generator that will generate random conversations between different people.'''<br />
<br />
First, we will generate the people. We can use a list and generate two random numbers.<br />
<br />
import random<br />
<br />
peopleNames = [<br />
"Bob",<br />
"Kyle",<br />
"James",<br />
"Richard",<br />
"Zachary",<br />
"Olivia",<br />
"Jonathan",<br />
"Will",<br />
"Bobby",<br />
"Kevin"<br />
]<br />
person1 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
peopleNames.remove(person1)<br />
person2 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
<br />
(I made it more organized by separating the long lines of code into multiple lines. It only works when you have a line break right after each item in the list.)<br />
<br />
Here, we use the remove() function to remove person1 from the list to make sure we don't use the same name twice. <br />
<br />
We also used the len() function to find the length of the list (soft-coding!)<br />
<br />
Now, we need to create a list of possible values for the first thing that person1 says (person1 will always be the first one to talk). <br />
<br />
Then, we will print it out.<br />
<br />
import random<br />
<br />
peopleNames = [<br />
"Bob",<br />
"Kyle",<br />
"James",<br />
"Richard",<br />
"Zachary",<br />
"Olivia",<br />
"Jonathan",<br />
"Will",<br />
"Bobby",<br />
"Kevin"<br />
]<br />
person1 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
peopleNames.remove(person1)<br />
person2 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
<br />
first = [<br />
"Hi!",<br />
"Hello!",<br />
"Good morning!",<br />
"Hello, " + person2 + "!",<br />
"Hi.",<br />
"Hi, " + person2 + "!"<br />
]<br />
print(person1 + ": " + first[random.randint(0, (len(first) - 1))])<br />
<br />
If we test out this program, we can confirm that this part indeed does work. This program is already getting long! Now, we will use the same method and create the second message.<br />
<br />
import random<br />
<br />
peopleNames = [<br />
"Bob",<br />
"Kyle",<br />
"James",<br />
"Richard",<br />
"Zachary",<br />
"Olivia",<br />
"Jonathan",<br />
"Will",<br />
"Bobby",<br />
"Kevin"<br />
]<br />
person1 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
peopleNames.remove(person1)<br />
person2 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
<br />
first = [<br />
"Hi!",<br />
"Hello!",<br />
"Good morning!",<br />
"Hello, " + person2 + "!",<br />
"Hi.",<br />
"Hi, " + person2 + "!"<br />
]<br />
print(person1 + ": " + first[random.randint(0, (len(first) - 1))])<br />
<br />
second = [<br />
"Hi! How are you today?",<br />
"Hello! How are you?",<br />
"Good morning! How are you today?",<br />
"Hello, " + person1 + "! How are you?",<br />
"Hi. How are you?",<br />
"Hi, " + person1 + "! How are you today?"<br />
]<br />
print(person2 + ": " + second[random.randint(0, (len(second) - 1))])<br />
<br />
We will repeat this for the rest of the conversation:<br />
<br />
import random<br />
<br />
peopleNames = [<br />
"Bob",<br />
"Kyle",<br />
"James",<br />
"Richard",<br />
"Zachary",<br />
"Olivia",<br />
"Jonathan",<br />
"Will", <br />
"Bobby",<br />
"Kevin"<br />
]<br />
person1 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
peopleNames.remove(person1)<br />
person2 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
<br />
first = [<br />
"Hi!",<br />
"Hello!",<br />
"Good morning!",<br />
"Hello, " + person2 + "!",<br />
"Hi.",<br />
"Hi, " + person2 + "!"<br />
]<br />
print(person1 + ": " + first[random.randint(0, (len(first) - 1))])<br />
<br />
second = [<br />
"Hi! How are you today?",<br />
"Hello! How are you?",<br />
"Good morning! How are you today?",<br />
"Hello, " + person1 + "! How are you?",<br />
"Hi. How are you?",<br />
"Hi, " + person1 + "! How are you today?"<br />
]<br />
print(person2 + ": " + second[random.randint(0, (len(second) - 1))])<br />
<br />
third = [<br />
"I'm feeling awesome! And you?",<br />
"I'm feeling alright! How are you?",<br />
"I'm good, thank you. How are you feeling?",<br />
"I'm fine!" ,<br />
"How are you today?"<br />
]<br />
print(person1 + ": " + third[random.randint(0, (len(third) - 1))])<br />
<br />
fourth = [<br />
"I'm feeling great!",<br />
"I'm awesome!",<br />
"Thanks for asking! I am feeling good today!",<br />
"I'm feeling awesome today! Yippee!"<br />
] <br />
print(person2 + ": " + fourth[random.randint(0, (len(fourth) - 1))])<br />
<br />
fifth = [<br />
"It's so nice out today!",<br />
"Today is such a cloudy day.",<br />
"I hate it when it is so cloudy outside!",<br />
"It's partly cloudy today!"<br />
]<br />
print(person1 + ": " + fifth[random.randint(0, (len(fifth) - 1))])<br />
<br />
sixth = [<br />
"I know, right?",<br />
"I know.",<br />
"Yeah!",<br />
"True."<br />
]<br />
print(person2 + ": " + sixth[random.randint(0, (len(sixth) - 1))])<br />
<br />
seventh = [<br />
"Sorry, I need to leave. Bye!",<br />
"I gotta go. Bye!",<br />
"Sorry, I don't have time to stay and chat. I've got to go somewhere. Bye!"<br />
]<br />
print(person1 + ": " + seventh[random.randint(0, (len(seventh) - 1))])<br />
<br />
eighth = [<br />
"Bye!",<br />
"Good-bye!",<br />
"Bye, " + person1 + "."<br />
]<br />
print(person2 + ": " + eighth[random.randint(0, (len(eighth) - 1))])<br />
<br />
Whew! So long!<br />
<br />
Once we run our program. It works! This program really wasn't that hard.<br />
<br />
Congrats! You've made it so far!</div>Anstarhttps://artofproblemsolving.com/wiki/index.php?title=Basic_Programming_With_Python&diff=130599Basic Programming With Python2020-08-04T20:02:26Z<p>Anstar: /* Defining a class */</p>
<hr />
<div>'''Important: It is extremely recommended that you read [[Getting Started With Python Programming]] before reading this unless you already know some programming knowledge.'''<br />
<br />
(Note: This is a really long article. To learn the most from this article, you need to read everything in order and skip nothing, unless you are '''absolutely absolutely sure that that content is way too easy for you.''')<br />
<br />
This article will talk about some basic Python programming. If you don't even know how to install Python, look [[Getting Started With Python Programming|here]].<br />
<br />
Note that this article has lots of program examples. It is recommended (but not required) to try these on your own before looking at the solutions.<br />
<br />
==Loops==<br />
<br />
There are two different kinds of loops in Python: the for loop and the while loop.<br />
<br />
===The For Loop===<br />
<br />
The for loop iterates over a list, or an array, of objects. You have probably seen this code before:<br />
<br />
[[File:Capture.PNG|200px]]<br />
<br />
This for loop iterates over the list of integers from 1 to 51, excluding the 51 and including the 1. That means it is a list from 1 to 50, inclusive. On every iteration, Python will print the number that the loop is iterating through. <br />
<br />
For example, in the first iteration, i = 1, so Python prints 1.<br />
<br />
In the second iteration, i = 2, so Python prints 2.<br />
<br />
This continues so on until the number, 50, is reached. Therefore, the last number Python will print out is 50.<br />
<br />
====Program Example====<br />
<br />
'''Find <math>\sum_{n=1}^{50} 2^{n}.</math>'''<br />
<br />
To do this task, we must create a for loop and loop over the integers from 1 to 50 inclusive:<br />
<br />
for i in range(1,51):<br />
<br />
Now what? We must keep a running total and increase it by <math>2^i</math> every time:<br />
<br />
total = 0<br />
for i in range(1,51):<br />
total += 2**i<br />
<br />
We must not forget to print the total at the end!<br />
<br />
total = 0<br />
for i in range(1,51):<br />
total += 2**i<br />
print(total)<br />
<br />
You must exit out of the for loop one you reach the print(total) line by pressing backspace.<br />
<br />
Once you run your program, you should get an answer of <math>\boxed{2,251,799,813,685,246.}</math><br />
<br />
===The While Loop===<br />
<br />
While loops don't loop over a list. They loop over and over and over...'''until'''...a condition becomes false.<br />
<br />
i = 3<br />
total = 0<br />
while i < 1000:<br />
total += i<br />
i += 3<br />
print(total)<br />
<br />
In this code, the while loop loops 333 times, until <math>i</math> becomes greater than or equal to 1000.<br />
<br />
====Program Example====<br />
<br />
'''Find <math>\sum_{n=1}^{50} 2^n</math> using a while loop.'''<br />
<br />
We must create a while loop that will iterate until n is greater than <math>50.</math><br />
<br />
n = 1<br />
total = 0<br />
while n <= 50:<br />
total += 2**n<br />
n += 1<br />
print(total)<br />
<br />
We must not forget to include the n += 1 line at the end of the while loop! <br />
<br />
If we run this, we will get the same answer as last time, <math>2,251,799,813,685,246.</math><br />
<br />
==Functions==<br />
<br />
In this section, we will define new operations and do arithmetic with them in Python.<br />
<br />
===The New Operation===<br />
Let's say that you defined a new binary operation, the <math>\uparrow \downarrow.</math> You want it to be so <math>a \uparrow \downarrow b = a^{b}b^{a}.</math> Therefore, <math>1\uparrow \downarrow 2 = 1^{2}2^{1}=1\cdot 2= 2,</math> and <math>2\uparrow \downarrow 3 = 2^33^2 = 8\cdot 9 = 72.</math> Let's call this operation an '''up down arrow.'''<br />
<br />
===Program Example 1===<br />
<br />
'''Find <math>[2 \uparrow \downarrow (1 \uparrow \downarrow 2)] \uparrow \downarrow 2.</math>'''<br />
<br />
We know this will be a big number, so we should write a program to do it! We certainly don't want to do the exponentiation and multiplication every time we use the operation in our program, and that's where functions come in! Functions can take in parameters (<math>a</math> and <math>b</math>) and return a result depending on the parameters.<br />
<br />
def up_down_arrow(a,b): <br />
return ((a**b) * (b**a))<br />
<br />
Above is the code to define our function. We need to print the final result at the end, so we must put a print statement at the end.<br />
<br />
def up_down_arrow(a,b): <br />
return ((a**b) * (b**a))<br />
print(up_down_arrow(up_down_arrow(2,up_down_arrow(1,2)),2)<br />
<br />
All those nested up_down_arrow's might be confusing at first, but it really isn't that confusing.<br />
If you run your program, you should get your answer: <math>16,777,216.</math> <br />
<br />
You might be surprised that the answer is so big. If you actually start calculating the real answer without a program, you will really quickly find that the final result is <math>16 \uparrow \downarrow 2,</math> which does turn out to be 16,777,216 if you use a calculator.<br />
<br />
Let's make another operation!<br />
<br />
We will define the operation <math>\uparrow \downarrow \leftarrow \rightarrow</math> to be called '''all around.''' <math>a \uparrow \downarrow \leftarrow \rightarrow b = (ab(a \uparrow \downarrow b))^2.</math> That's an operation that will make really big numbers!<br />
<br />
===Program Example 2===<br />
<br />
'''Find 87 all around 132.'''<br />
<br />
The answer is bound to be a huge number, so we must make a program to solve it.<br />
<br />
We will keep our up_down_arrow function because in the definition of our all_around function we will use it. Then, we will define the all_around function.<br />
<br />
def up_down_arrow(a,b):<br />
return ((a**b) * (b**a))<br />
def all_around(a,b):<br />
return ((a * b * up_down_arrow(a,b)) ** 2)<br />
<br />
We must print all_around(87,132) at the end. Once we do that, and we run our program, we get a super huge number that has over 800 digits!<br />
<br />
===Understanding Functions===<br />
<br />
Every single function has a '''return value'''. If a function does not return anything, the return value is '''null'''. Null is a term used in programming as a placeholder that stands for nothing.<br />
<br />
====Simple Program Example 1====<br />
<br />
'''Define a function that adds 1 to an input.'''<br />
<br />
How will the function know what number to add 1 to? We will input a '''parameter''' for the function to add 1 to.<br />
<br />
def add_one(x):<br />
return x + 1<br />
<br />
In this function, <math>x</math> is the parameter.<br />
<br />
def add_one(x):<br />
return x + 1<br />
print(add_one(2))<br />
<br />
In the print statement, we set <math>x</math> as 2, and the function returns <math>2 + 1 = 3,</math> so the program prints <math>3</math>.<br />
<br />
====Simple Program Example 2====<br />
<br />
'''Define a function that prints out an input.'''<br />
<br />
We will use a parameter again.<br />
<br />
def print_function(x):<br />
print(x)<br />
<br />
Uh oh! We have nothing to return! Therefore, we will return nothing (or null), by just writing return.<br />
<br />
def print_function(x):<br />
print(x)<br />
return<br />
print_function("print_function")<br />
<br />
This code prints out print_function. print_function() is said to be '''called''' in the final line of the code. Again, we set <math>x</math>, our parameter, as "print_function."<br />
== Classes ==<br />
Classes are <br />
<br />
===Defining a class===<br />
We can define a class by doing the following:<br />
class example:<br />
pass<br />
<br />
===methods===<br />
methods are definition that apply to a class.<br />
===__init__===<br />
===__str__===<br />
===overloading===<br />
overloading means changing a builtin function to do what you want it to do.<br />
<br />
==Flow==<br />
<br />
Flow consists of if statements, elif (else if) statements, and else statements.<br />
<br />
*An if statement checks if a comparison is true.<br />
<br />
*An else statement checks if a comparison is not true. It is used after an if statement (and all elif statements after the if statement) and it shares the same comparison as the if statement.<br />
<br />
*An elif statement checks for two things: if a comparison is true, and if a comparison is not true. It is used right after the if statement.<br />
<br />
===Program Example===<br />
<br />
'''Does the number 10 have the property that when you multiply 10 by 5, you get a two digit number?'''<br />
<br />
This problem is super easy to solve without a program, but let's write a program to solve this anyway. We will use an if statement to check if <math>10\cdot 5</math> is less than 100 and greater than 9.<br />
<br />
if 10*5 > 9:<br />
if 10*5 < 100:<br />
print("Yes")<br />
else:<br />
print("No")<br />
else:<br />
print("No")<br />
<br />
This code means, if 10*5 > 9, then we will check if it is less than 100. If it is not greater than 9, however, we will print No. If it is greater than 9, we check if it is less than 100. If it is, we print Yes. If it isn't we print No.<br />
<br />
These nested if statements can be very confusing. Luckily, there is a faster an easier way to do this.<br />
<br />
if 10*5 > 9 and 10*5 < 100:<br />
print("Yes") <br />
else:<br />
print("No")<br />
<br />
This code checks for the two conditions at the same time. If we run it, we get our answer of Yes.<br />
<br />
==Booleans==<br />
<br />
===Program Example===<br />
<br />
'''Print all two-digit positive integers <math>x</math> such that <math>5x</math> is a two-digit positive integer.'''<br />
<br />
We can create a function with our previous code.<br />
<br />
We will have to slightly modify our function so we can use it in a for loop at the end:<br />
<br />
def check(a):<br />
if a*5 > 9 and a*5 < 100:<br />
return True <br />
else:<br />
return False<br />
<br />
True and False are what are called '''booleans'''. When an if or elif statement receives True, the code inside of the statement happens. When an if or elif statement receives False, the code inside of the statement does not happen. <br />
<br />
We must create a for loop that will iterate through all two digit positive integers. <br />
<br />
def check(a):<br />
if a*5 > 9 and a*5 < 100:<br />
return True <br />
else:<br />
return False<br />
for i in range(10,100):<br />
if check(i):<br />
print(i)<br />
<br />
The final for loop checks if <math>5i</math> is a two digit integer. If it is, the function returns True and the code inside the if statement gets run. If it isn't, the function returns False and the code inside the if statement gets ignored.<br />
<br />
If we run this, we will get the answer.<br />
<br />
All two digit integers from 10 to 19 inclusive work!<br />
<br />
=="Soft Coding" Programs==<br />
<br />
In the next few examples, you will see why hard coding programs is bad. Hard coding programs refers to coding a program that is hard to modify. For example:<br />
<br />
===Program Example 1===<br />
<br />
'''Print all two digit positive integers <math>x</math> such that <math>5x</math> is a three digit positive integer.'''<br />
<br />
We can keep our code and modify some parts of it.<br />
<br />
def check(a, min, max):<br />
if a*5 > min - 1 and a*5 < max + 1:<br />
return True <br />
else:<br />
return False<br />
<br />
def print_check(range_min, range_max, check_min, check_max):<br />
for i in range(range_min, range_max + 1):<br />
if check(i, check_min, check_max):<br />
print(i)<br />
return<br />
<br />
print_check(10, 99, 100, 999)<br />
<br />
Why did we add so many functions?<br />
<br />
Well, if the numbers in a problem change (and the words stay the same), and you need to change a lot of numbers in your program, your program is considered '''hard-coded'''. We want our programs to be as '''soft-coded''' as possible. In our new program, we only need to change 4 numbers (in the print_check() statement) if the numbers in the problem change. Therefore, our program is relatively soft-coded. There are still ways to soft-code this program even more, though.<br />
<br />
If we run our program, we get our answer.<br />
<br />
All numbers from 20 to 99 work!<br />
<br />
===Program Example 2===<br />
<br />
'''Print all three digit positive integers <math>x</math> such that <math>5x</math> is a three digit positive integer.'''<br />
<br />
We can just change the print_check line at the end to<br />
<br />
print_check(100, 999, 100, 999)<br />
<br />
and our program will be ready to be run.<br />
<br />
All numbers from 100 to 199 work.<br />
<br />
===Program Example 3===<br />
<br />
'''Print all two digit positive integers <math>x</math> such that <math>3x</math> is a three digit positive integer.'''<br />
<br />
Uh oh. Only changing the print_check line won't work. We will need to change our functions!<br />
<br />
def check(a, min, max, factor):<br />
if a*factor > min - 1 and a*factor < max + 1:<br />
return True <br />
else:<br />
return False<br />
<br />
def print_check(range_min, range_max, check_min, check_max, check_factor):<br />
for i in range(range_min, range_max + 1):<br />
if check(i, check_min, check_max, check_factor):<br />
print(i)<br />
return<br />
<br />
print_check(10, 99, 100, 999, 3)<br />
<br />
In this step, we added a parameter in both functions. We also soft-coded our program even more! Hooray!<br />
<br />
All integers from 34 to 99 work.<br />
<br />
===Program Example 4===<br />
<br />
'''Print all two digit positive integers <math>x</math> such that <math>12x</math> is a positive integer from 500 to 900.'''<br />
<br />
This problem may look a bit different from the other ones, but it really is the same thing, except that the factor is 12 and check_min and check_max are 500 and 900, respectively.<br />
<br />
Once we change the final print_check() line to satisfy our needs, we can run our program.<br />
<br />
All numbers from 42 to 75 work!<br />
<br />
Congrats! You have written your first programs above 10 lines of code!<br />
<br />
==Random==<br />
<br />
There is a package in Python that allows the use of random numbers.<br />
<br />
===Program Example 1===<br />
<br />
'''Generate a random number from 1 to 6.'''<br />
<br />
Easy peasy. We will just generate a random number from 1 to 6 with the package like this:<br />
<br />
import random<br />
print(random.randint(1,6))<br />
<br />
As you can see, when you run this program, you get a random integer from 1 to 6.<br />
<br />
===Program Example 2===<br />
<br />
'''Simulate the rolling of 1000 dice. Now, count the number of times you roll 6. Print that number out.'''<br />
<br />
We can create a function that returns a random number from 1 to 6. Then, we can make a for loop that rolls the dice 1000 times and check if it is a 6.<br />
<br />
import random<br />
count = 0<br />
<br />
def roll():<br />
return random.randint(1,6)<br />
<br />
for i in range(1, 1001):<br />
if roll() == 6:<br />
count += 1<br />
<br />
print(count)<br />
<br />
If we run this, we will get a number around 170.<br />
<br />
===Program Example 3===<br />
<br />
'''Simulate the rolling of 10,000 dice. Now, count the amount of times you roll 3. Print that amount out.'''<br />
<br />
We can keep our roll function and our code inside the for loop, but we need to change our for loop statement.<br />
<br />
We can actually soft-code our program more. Let's turn the whole for loop into a function!<br />
<br />
import random<br />
<br />
def roll():<br />
return random.randint(1,6)<br />
<br />
def count(amount):<br />
count_ = 0<br />
<br />
for i in range(1, amount+1):<br />
if roll() == 3:<br />
count_ += 1<br />
return count_<br />
<br />
print(count(10000))<br />
<br />
If we run this code, it works.<br />
<br />
===Program Example 4===<br />
<br />
'''One of my friends loves rolling dice. He is going to roll 1 die tomorrow, 2 dice two days from now, 3 dice three days from now, and so on so that he rolls <math>a</math> dice <math>a</math> days from now. He gets tired rolling dice after rolling dice for 365 days (so the last day he rolls 365 dice). In Python, simulate this. How many times does he roll 3 after 365 days of rolling dice?'''<br />
<br />
We can use a for loop that calls a function multiple times.<br />
<br />
import random<br />
<br />
def roll():<br />
return random.randint(1,6)<br />
<br />
def count(amount):<br />
count_ = 0<br />
for i in range(1, amount+1):<br />
if roll() == 3:<br />
count_ += 1<br />
return count_<br />
<br />
total = 0<br />
<br />
for i in range(1, 366):<br />
total += count(i)<br />
<br />
print(total)<br />
<br />
This is a really long program, but the whole program should make sense if you look at it for a while. We defined our count function in the previous example, and now we are using it with a for loop and a running total. <br />
<br />
You should get a number around 11,000 when you run it. Wow, lots of 3's!<br />
<br />
===Program Example 5===<br />
<br />
'''20 of my friends love rolling dice. They are all going to roll 1 die each tomorrow, 2 dice each two days from now, 3 dice each three days from now, and so on so that they roll <math>a</math> dice each <math>a</math> days from now. But, one of my friends gets tired very quickly and he only rolls dice for 1 day and stops. Another friend only will roll dice for 2 days, and another will roll dice for three days only, and so on up to the fact that my last friend will roll dice for 20 days. In Python, simulate this. How many times does someone roll 3 after everything?'''<br />
<br />
We will have to make our for loop into a function again.<br />
<br />
import random<br />
<br />
def roll():<br />
return random.randint(1,6)<br />
<br />
def count(amount):<br />
count_ = 0<br />
for i in range(1, amount+1):<br />
if roll() == 3:<br />
count_ += 1<br />
return count_<br />
<br />
def count2(amount)<br />
total = 0<br />
for i in range(1, amount + 1):<br />
total += count(i)<br />
return total<br />
<br />
def count3(amount)<br />
total = 0<br />
for i in range(1, amount + 1):<br />
total += count2(i)<br />
return total<br />
<br />
print(count3(20))<br />
<br />
(Our program is so long!)<br />
<br />
I also made a new function just in case we needed to turn that into a function later.<br />
<br />
'''Make sure''' you read the code carefully and you fully understand it. If you don't understand every single line of code, then you will get confused later on in this article.<br />
<br />
When you run this program, you might be surprised that the answer isn't so big.<br />
<br />
===Program Example 6===<br />
<br />
'''365 of my friends love rolling dice. They are all going to roll 1 die each tomorrow, 2 dice each two days from now, 3 dice each three days from now, and so on so that they roll <math>a</math> dice each <math>a</math> days from now. But, one of my friends gets tired very quickly and he only rolls dice for 1 day and stops. Another friend only will roll dice for 2 days, and another will roll dice for three days only, and so on up to the fact that my last friend will roll dice for 365 days. In Python, simulate this. How many times does someone roll 3 after everything?'''<br />
<br />
Because we soft-coded our program so much, all we have to do is change the last line so the parameter of count3() is 365.<br />
<br />
If we run it...we get a big answer, as expected. It also takes quite a while!<br />
<br />
You may not have realized that we soft-coded our program at all, but the whole point of functions is to soft-code programs!<br />
<br />
Congrats on writing a program that is around 25 lines long!<br />
<br />
==Very Basic Datatypes==<br />
<br />
An integer is a basic datatype in Python. Basically, all variables with the datatype of '''int''' is an integer.<br />
<br />
A string is another basic datatype, and it is a string of characters enclosed by quotes.<br />
<br />
===Why Are Datatypes So Important?===<br />
<br />
Let's say we wanted to make a program that would add 2 and 3. Some bogus code would be:<br />
<br />
x="2"<br />
y="3"<br />
print(x+y)<br />
<br />
If you ran this code, you would get 23. Why is that?<br />
<br />
Well, here, x and y are strings. When you perform the addition operator to strings in Python, it concatenates the strings, giving 23.<br />
<br />
The real code is:<br />
<br />
x=2<br />
y=3<br />
print(x+y)<br />
<br />
If you run this, you will get <math>5</math>, which is correct.<br />
<br />
Here's another reason datatypes are important. Now, we will introduce the datatype called the '''floating point number''', or '''float'''. A floating-point number is a number with a decimal point.<br />
<br />
Let's go back to the IDLE. Type "0.1*10". The result is 1.0. Notice the decimal point.<br />
<br />
Let's type something different. Type <math>0.1+0.1+0.1+0.1+0.1+0.1+0.1+0.1+0.1+0.1.</math><br />
<br />
'''WHAT!?'''<br />
<br />
You would have expected the answer to be 1, but it isn't 1. What happened?<br />
<br />
'''Float approximation''' happened. Most (almost all) programming languages have a bad float approximation. That means that 1.0 can turn into 0.99999999999999 and 0.5 can turn into 0.49999999999999999993. That only happens with floats, so we should try to use floats as sparingly as possible.<br />
<br />
==Lists==<br />
<br />
A for loop iterates over a '''list'''. A list is a bunch of objects stored in one variable. (Hey! A list is a datatype!) For loops are highly related to lists.<br />
<br />
Let's say we wanted to make a program to print all the items in a list.<br />
<br />
We will first create the list, using the code:<br />
<br />
myList = [1,4,6,8]<br />
<br />
This is a list with four items: 1, 4, 6, and 8.<br />
<br />
We must now print all elements of it with a for loop:<br />
<br />
myList = [1,4,6,8]<br />
for i in myList:<br />
print(i)<br />
<br />
When we run this program, we get the numbers 1, 4, 6, and 8, as expected.<br />
<br />
===Accessing Values===<br />
<br />
Let's say we wanted to print out the second item in a list. We will use '''indexes'''.<br />
<br />
The index of the first item in a list is always 0. The index of the second is 1. The index of the <math>n</math>th is <math>n-1.</math><br />
<br />
To print out the second item, we will use an index of 1, like this:<br />
<br />
myList = [1,4,6,8]<br />
print(myList[1])<br />
<br />
Notice that the index is inside of the square brackets.<br />
<br />
===Adding Values===<br />
<br />
We can use the list.append() function to add an object to the end of a list.<br />
<br />
myList.append(10)<br />
<br />
will add 10 to the list, which makes myList = [1,4,6,8,10].<br />
<br />
===Removing Items From Lists===<br />
<br />
We can use the list.remove() function to remove a specific item in a list.<br />
<br />
For example, consider this code.<br />
<br />
myList = [1,2,3]<br />
myList.remove(3)<br />
<br />
This code will make myList turn into [1,2]. The element, 3, gets removed.<br />
<br />
===len(list)===<br />
<br />
The len(list) function returns the length of a list.<br />
<br />
This code will print 3.<br />
<br />
myList = [1,2,3]<br />
print(len(myList))<br />
<br />
The length of myList is 3, so Python prints 3.<br />
<br />
===All Kinds Of Lists===<br />
<br />
Lists don't have to be only integers!<br />
<br />
myList = [1,"Hi","Hello world", 3.5, 3.14159265358979323]<br />
<br />
If fact, there can be lists inside of lists!<br />
<br />
myList = [[1,2,3], [3,4,5], [5,6,"Hello world"], "BOB", 3.1415926]<br />
<br />
Even this!<br />
<br />
myList = [[1, [1, [1,2,3],3],3], [[[3,["Hello world", 4],5],4,5],4,5], [5,6,7,[1,[1,2,3],3],"Hello world"], "BOB", 3.1415926, True]<br />
<br />
If you look at that list carefully, you will find lists inside of lists inside of lists inside of lists! And, a boolean at the end!<br />
<br />
Like variables, you can have as many lists in a program as you want (a list is a variable)!<br />
<br />
myList = [1,2,3,4]<br />
yourList = [5,6,7,8]<br />
hisList = [9,10,11,12]<br />
herList = [13,14,15,16]<br />
theirList = [17,18,19,20]<br />
ourList = [21,22,23,24]<br />
listsOfLists = [[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16],[17,18,19,20],[21,22,23,24]]<br />
<br />
===Splitting Lists===<br />
Split Operator Basics:<br />
genericList[where to start:where to end:what size steps to take]<br />
The value where to start is inclusive, and denotes the index where your split list begins. It has a default value of 0.<br />
The value where to end is exclusive, and denotes the index where your split list ends. It has a default value of len(genericList).<br />
The value what size steps denotes the size of the steps your split takes(more on that later). It has a default value of 1.<br />
Say you want to split a list and only return certain indices, for example if you wanted to split a list called data and put the first two elements into a list called head and the last two into a list called tail, you would split like this:<br />
data = [1, 3, 4, 23.5, 40, 55]<br />
head = data[:2]<br />
tail = data[-2:] # negative list indices represent the end of a list, so -1 is the last element and -2 is the second-to-last<br />
Step Size:<br />
We will practice writing a few functions that select every other element and will reverse in a list using step size.<br />
A step size of two means skip every other list index, so we can write our first function.<br />
def selectEveryOtherElement(list):<br />
return list[::2]<br />
But which step size will get us our desired reversed list. We could start at the end of the list and iterate backwards, but how would we do that...<br />
Negative Step Size:<br />
A step size that is negative means skip a certain amount of elements, but backwards. If we were to start at 0, with a step size of -1, we would be able to iterate backwards over the list!<br />
def reverse(list):<br />
return list[::-1]<br />
Splitting lists with ratios:<br />
What if we wanted to be able to split a list based upon a ratio. For example, the common 80:20 train to test ratio in machine learning? Here is how you would do it<br />
def eighty-twenty(list):<br />
train = list[:int(len(list) * (4 / 5))] # We must include the int() method to convert to an integer if len(list) % 5 != 0<br />
test = list[int(len(list) * 4 / 5)]<br />
return [train, test] # We then return a list with the train and test lists inside<br />
<br />
==Dictionaries==<br />
<br />
A dictionary (a type of datatype) is a bunch of keys and values. There is a major difference between dictionaries and lists. Lists are ordered; dictionaries are not.<br />
<br />
Here is the '''syntax''' of creating a dictionary:<br />
<br />
myDictionary = {1:"one",2:"two"}<br />
<br />
This dictionary has two key/value pairs. Notice it is surrounded in curly braces. The keys are 1 and 2; the values are "one" and "two."<br />
<br />
How is this useful? Let's make a simple program to test it out.<br />
<br />
myDictionary = {1:"one",2:"two"}<br />
print(myDictionary[1])<br />
print(myDictionary[2])<br />
<br />
===Accessing Values===<br />
<br />
To access a value in a dictionary, you put in the key.<br />
<br />
myDictionary[1]<br />
<br />
returns one, because 1 is the key to "one."<br />
<br />
===Adding New Values===<br />
<br />
To overwrite a value, we do this.<br />
<br />
myDictionary[1] = "won"<br />
<br />
The value to the key 1 is now "won."<br />
<br />
To add a value, we do the same thing!<br />
<br />
myDictionary[3] = "three"<br />
<br />
This adds a key 3 with a value of "three."<br />
<br />
==Misc Concepts==<br />
<br />
This section will talk about some concepts that we haven't learned yet.<br />
<br />
====Concatenating Strings====<br />
<br />
Concatenating strings is putting them together. For example, "one" concatenated with "two" gives "onetwo."<br />
<br />
The following string,<br />
<br />
"Hello, " + person2 + "! How are you?"<br />
<br />
depends on what person2 was. If person2 was Bob, the string would be:<br />
<br />
"Hello, Bob! How are you?"<br />
<br />
It fits together perfectly!<br />
<br />
You cannot concatenate strings with integers. For example, doing this:<br />
<br />
"2" + 3<br />
<br />
will not work. Instead, to get an answer of "23", you must do this:<br />
<br />
"2" + str(3)<br />
<br />
That turns 3 into a string so it is "3", and the result will be "23".<br />
<br />
====Line Breaks====<br />
<br />
We can use multiple line breaks to make our code more organized. There are some places that you cannot line break. For example, this code will produce an error:<br />
<br />
myList =<br />
[1,2,3]<br />
<br />
This code does not work.<br />
<br />
This code '''does work''':<br />
<br />
myList = [<br />
1,2,3]<br />
<br />
It is accepted when you break a line right after the [. It is also accepted right after a comma. (And right before the ending ].)<br />
<br />
myList = [<br />
1,<br />
2,<br />
3<br />
]<br />
<br />
==Challenge Program==<br />
<br />
In this section, we will attempt the hardest program so far in this article.<br />
<br />
'''Make a conversation generator that will generate random conversations between different people.'''<br />
<br />
First, we will generate the people. We can use a list and generate two random numbers.<br />
<br />
import random<br />
<br />
peopleNames = [<br />
"Bob",<br />
"Kyle",<br />
"James",<br />
"Richard",<br />
"Zachary",<br />
"Olivia",<br />
"Jonathan",<br />
"Will",<br />
"Bobby",<br />
"Kevin"<br />
]<br />
person1 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
peopleNames.remove(person1)<br />
person2 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
<br />
(I made it more organized by separating the long lines of code into multiple lines. It only works when you have a line break right after each item in the list.)<br />
<br />
Here, we use the remove() function to remove person1 from the list to make sure we don't use the same name twice. <br />
<br />
We also used the len() function to find the length of the list (soft-coding!)<br />
<br />
Now, we need to create a list of possible values for the first thing that person1 says (person1 will always be the first one to talk). <br />
<br />
Then, we will print it out.<br />
<br />
import random<br />
<br />
peopleNames = [<br />
"Bob",<br />
"Kyle",<br />
"James",<br />
"Richard",<br />
"Zachary",<br />
"Olivia",<br />
"Jonathan",<br />
"Will",<br />
"Bobby",<br />
"Kevin"<br />
]<br />
person1 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
peopleNames.remove(person1)<br />
person2 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
<br />
first = [<br />
"Hi!",<br />
"Hello!",<br />
"Good morning!",<br />
"Hello, " + person2 + "!",<br />
"Hi.",<br />
"Hi, " + person2 + "!"<br />
]<br />
print(person1 + ": " + first[random.randint(0, (len(first) - 1))])<br />
<br />
If we test out this program, we can confirm that this part indeed does work. This program is already getting long! Now, we will use the same method and create the second message.<br />
<br />
import random<br />
<br />
peopleNames = [<br />
"Bob",<br />
"Kyle",<br />
"James",<br />
"Richard",<br />
"Zachary",<br />
"Olivia",<br />
"Jonathan",<br />
"Will",<br />
"Bobby",<br />
"Kevin"<br />
]<br />
person1 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
peopleNames.remove(person1)<br />
person2 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
<br />
first = [<br />
"Hi!",<br />
"Hello!",<br />
"Good morning!",<br />
"Hello, " + person2 + "!",<br />
"Hi.",<br />
"Hi, " + person2 + "!"<br />
]<br />
print(person1 + ": " + first[random.randint(0, (len(first) - 1))])<br />
<br />
second = [<br />
"Hi! How are you today?",<br />
"Hello! How are you?",<br />
"Good morning! How are you today?",<br />
"Hello, " + person1 + "! How are you?",<br />
"Hi. How are you?",<br />
"Hi, " + person1 + "! How are you today?"<br />
]<br />
print(person2 + ": " + second[random.randint(0, (len(second) - 1))])<br />
<br />
We will repeat this for the rest of the conversation:<br />
<br />
import random<br />
<br />
peopleNames = [<br />
"Bob",<br />
"Kyle",<br />
"James",<br />
"Richard",<br />
"Zachary",<br />
"Olivia",<br />
"Jonathan",<br />
"Will", <br />
"Bobby",<br />
"Kevin"<br />
]<br />
person1 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
peopleNames.remove(person1)<br />
person2 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
<br />
first = [<br />
"Hi!",<br />
"Hello!",<br />
"Good morning!",<br />
"Hello, " + person2 + "!",<br />
"Hi.",<br />
"Hi, " + person2 + "!"<br />
]<br />
print(person1 + ": " + first[random.randint(0, (len(first) - 1))])<br />
<br />
second = [<br />
"Hi! How are you today?",<br />
"Hello! How are you?",<br />
"Good morning! How are you today?",<br />
"Hello, " + person1 + "! How are you?",<br />
"Hi. How are you?",<br />
"Hi, " + person1 + "! How are you today?"<br />
]<br />
print(person2 + ": " + second[random.randint(0, (len(second) - 1))])<br />
<br />
third = [<br />
"I'm feeling awesome! And you?",<br />
"I'm feeling alright! How are you?",<br />
"I'm good, thank you. How are you feeling?",<br />
"I'm fine!" ,<br />
"How are you today?"<br />
]<br />
print(person1 + ": " + third[random.randint(0, (len(third) - 1))])<br />
<br />
fourth = [<br />
"I'm feeling great!",<br />
"I'm awesome!",<br />
"Thanks for asking! I am feeling good today!",<br />
"I'm feeling awesome today! Yippee!"<br />
] <br />
print(person2 + ": " + fourth[random.randint(0, (len(fourth) - 1))])<br />
<br />
fifth = [<br />
"It's so nice out today!",<br />
"Today is such a cloudy day.",<br />
"I hate it when it is so cloudy outside!",<br />
"It's partly cloudy today!"<br />
]<br />
print(person1 + ": " + fifth[random.randint(0, (len(fifth) - 1))])<br />
<br />
sixth = [<br />
"I know, right?",<br />
"I know.",<br />
"Yeah!",<br />
"True."<br />
]<br />
print(person2 + ": " + sixth[random.randint(0, (len(sixth) - 1))])<br />
<br />
seventh = [<br />
"Sorry, I need to leave. Bye!",<br />
"I gotta go. Bye!",<br />
"Sorry, I don't have time to stay and chat. I've got to go somewhere. Bye!"<br />
]<br />
print(person1 + ": " + seventh[random.randint(0, (len(seventh) - 1))])<br />
<br />
eighth = [<br />
"Bye!",<br />
"Good-bye!",<br />
"Bye, " + person1 + "."<br />
]<br />
print(person2 + ": " + eighth[random.randint(0, (len(eighth) - 1))])<br />
<br />
Whew! So long!<br />
<br />
Once we run our program. It works! This program really wasn't that hard.<br />
<br />
Congrats! You've made it so far!</div>Anstarhttps://artofproblemsolving.com/wiki/index.php?title=Basic_Programming_With_Python&diff=130597Basic Programming With Python2020-08-04T20:00:44Z<p>Anstar: /* =__str__ */</p>
<hr />
<div>'''Important: It is extremely recommended that you read [[Getting Started With Python Programming]] before reading this unless you already know some programming knowledge.'''<br />
<br />
(Note: This is a really long article. To learn the most from this article, you need to read everything in order and skip nothing, unless you are '''absolutely absolutely sure that that content is way too easy for you.''')<br />
<br />
This article will talk about some basic Python programming. If you don't even know how to install Python, look [[Getting Started With Python Programming|here]].<br />
<br />
Note that this article has lots of program examples. It is recommended (but not required) to try these on your own before looking at the solutions.<br />
<br />
==Loops==<br />
<br />
There are two different kinds of loops in Python: the for loop and the while loop.<br />
<br />
===The For Loop===<br />
<br />
The for loop iterates over a list, or an array, of objects. You have probably seen this code before:<br />
<br />
[[File:Capture.PNG|200px]]<br />
<br />
This for loop iterates over the list of integers from 1 to 51, excluding the 51 and including the 1. That means it is a list from 1 to 50, inclusive. On every iteration, Python will print the number that the loop is iterating through. <br />
<br />
For example, in the first iteration, i = 1, so Python prints 1.<br />
<br />
In the second iteration, i = 2, so Python prints 2.<br />
<br />
This continues so on until the number, 50, is reached. Therefore, the last number Python will print out is 50.<br />
<br />
====Program Example====<br />
<br />
'''Find <math>\sum_{n=1}^{50} 2^{n}.</math>'''<br />
<br />
To do this task, we must create a for loop and loop over the integers from 1 to 50 inclusive:<br />
<br />
for i in range(1,51):<br />
<br />
Now what? We must keep a running total and increase it by <math>2^i</math> every time:<br />
<br />
total = 0<br />
for i in range(1,51):<br />
total += 2**i<br />
<br />
We must not forget to print the total at the end!<br />
<br />
total = 0<br />
for i in range(1,51):<br />
total += 2**i<br />
print(total)<br />
<br />
You must exit out of the for loop one you reach the print(total) line by pressing backspace.<br />
<br />
Once you run your program, you should get an answer of <math>\boxed{2,251,799,813,685,246.}</math><br />
<br />
===The While Loop===<br />
<br />
While loops don't loop over a list. They loop over and over and over...'''until'''...a condition becomes false.<br />
<br />
i = 3<br />
total = 0<br />
while i < 1000:<br />
total += i<br />
i += 3<br />
print(total)<br />
<br />
In this code, the while loop loops 333 times, until <math>i</math> becomes greater than or equal to 1000.<br />
<br />
====Program Example====<br />
<br />
'''Find <math>\sum_{n=1}^{50} 2^n</math> using a while loop.'''<br />
<br />
We must create a while loop that will iterate until n is greater than <math>50.</math><br />
<br />
n = 1<br />
total = 0<br />
while n <= 50:<br />
total += 2**n<br />
n += 1<br />
print(total)<br />
<br />
We must not forget to include the n += 1 line at the end of the while loop! <br />
<br />
If we run this, we will get the same answer as last time, <math>2,251,799,813,685,246.</math><br />
<br />
==Functions==<br />
<br />
In this section, we will define new operations and do arithmetic with them in Python.<br />
<br />
===The New Operation===<br />
Let's say that you defined a new binary operation, the <math>\uparrow \downarrow.</math> You want it to be so <math>a \uparrow \downarrow b = a^{b}b^{a}.</math> Therefore, <math>1\uparrow \downarrow 2 = 1^{2}2^{1}=1\cdot 2= 2,</math> and <math>2\uparrow \downarrow 3 = 2^33^2 = 8\cdot 9 = 72.</math> Let's call this operation an '''up down arrow.'''<br />
<br />
===Program Example 1===<br />
<br />
'''Find <math>[2 \uparrow \downarrow (1 \uparrow \downarrow 2)] \uparrow \downarrow 2.</math>'''<br />
<br />
We know this will be a big number, so we should write a program to do it! We certainly don't want to do the exponentiation and multiplication every time we use the operation in our program, and that's where functions come in! Functions can take in parameters (<math>a</math> and <math>b</math>) and return a result depending on the parameters.<br />
<br />
def up_down_arrow(a,b): <br />
return ((a**b) * (b**a))<br />
<br />
Above is the code to define our function. We need to print the final result at the end, so we must put a print statement at the end.<br />
<br />
def up_down_arrow(a,b): <br />
return ((a**b) * (b**a))<br />
print(up_down_arrow(up_down_arrow(2,up_down_arrow(1,2)),2)<br />
<br />
All those nested up_down_arrow's might be confusing at first, but it really isn't that confusing.<br />
If you run your program, you should get your answer: <math>16,777,216.</math> <br />
<br />
You might be surprised that the answer is so big. If you actually start calculating the real answer without a program, you will really quickly find that the final result is <math>16 \uparrow \downarrow 2,</math> which does turn out to be 16,777,216 if you use a calculator.<br />
<br />
Let's make another operation!<br />
<br />
We will define the operation <math>\uparrow \downarrow \leftarrow \rightarrow</math> to be called '''all around.''' <math>a \uparrow \downarrow \leftarrow \rightarrow b = (ab(a \uparrow \downarrow b))^2.</math> That's an operation that will make really big numbers!<br />
<br />
===Program Example 2===<br />
<br />
'''Find 87 all around 132.'''<br />
<br />
The answer is bound to be a huge number, so we must make a program to solve it.<br />
<br />
We will keep our up_down_arrow function because in the definition of our all_around function we will use it. Then, we will define the all_around function.<br />
<br />
def up_down_arrow(a,b):<br />
return ((a**b) * (b**a))<br />
def all_around(a,b):<br />
return ((a * b * up_down_arrow(a,b)) ** 2)<br />
<br />
We must print all_around(87,132) at the end. Once we do that, and we run our program, we get a super huge number that has over 800 digits!<br />
<br />
===Understanding Functions===<br />
<br />
Every single function has a '''return value'''. If a function does not return anything, the return value is '''null'''. Null is a term used in programming as a placeholder that stands for nothing.<br />
<br />
====Simple Program Example 1====<br />
<br />
'''Define a function that adds 1 to an input.'''<br />
<br />
How will the function know what number to add 1 to? We will input a '''parameter''' for the function to add 1 to.<br />
<br />
def add_one(x):<br />
return x + 1<br />
<br />
In this function, <math>x</math> is the parameter.<br />
<br />
def add_one(x):<br />
return x + 1<br />
print(add_one(2))<br />
<br />
In the print statement, we set <math>x</math> as 2, and the function returns <math>2 + 1 = 3,</math> so the program prints <math>3</math>.<br />
<br />
====Simple Program Example 2====<br />
<br />
'''Define a function that prints out an input.'''<br />
<br />
We will use a parameter again.<br />
<br />
def print_function(x):<br />
print(x)<br />
<br />
Uh oh! We have nothing to return! Therefore, we will return nothing (or null), by just writing return.<br />
<br />
def print_function(x):<br />
print(x)<br />
return<br />
print_function("print_function")<br />
<br />
This code prints out print_function. print_function() is said to be '''called''' in the final line of the code. Again, we set <math>x</math>, our parameter, as "print_function."<br />
== Classes ==<br />
Classes are <br />
<br />
===Defining a class===<br />
===methods===<br />
methods are definition that apply to a class.<br />
===__init__===<br />
===__str__===<br />
===overloading===<br />
overloading means changing a builtin function to do what you want it to do.<br />
<br />
==Flow==<br />
<br />
Flow consists of if statements, elif (else if) statements, and else statements.<br />
<br />
*An if statement checks if a comparison is true.<br />
<br />
*An else statement checks if a comparison is not true. It is used after an if statement (and all elif statements after the if statement) and it shares the same comparison as the if statement.<br />
<br />
*An elif statement checks for two things: if a comparison is true, and if a comparison is not true. It is used right after the if statement.<br />
<br />
===Program Example===<br />
<br />
'''Does the number 10 have the property that when you multiply 10 by 5, you get a two digit number?'''<br />
<br />
This problem is super easy to solve without a program, but let's write a program to solve this anyway. We will use an if statement to check if <math>10\cdot 5</math> is less than 100 and greater than 9.<br />
<br />
if 10*5 > 9:<br />
if 10*5 < 100:<br />
print("Yes")<br />
else:<br />
print("No")<br />
else:<br />
print("No")<br />
<br />
This code means, if 10*5 > 9, then we will check if it is less than 100. If it is not greater than 9, however, we will print No. If it is greater than 9, we check if it is less than 100. If it is, we print Yes. If it isn't we print No.<br />
<br />
These nested if statements can be very confusing. Luckily, there is a faster an easier way to do this.<br />
<br />
if 10*5 > 9 and 10*5 < 100:<br />
print("Yes") <br />
else:<br />
print("No")<br />
<br />
This code checks for the two conditions at the same time. If we run it, we get our answer of Yes.<br />
<br />
==Booleans==<br />
<br />
===Program Example===<br />
<br />
'''Print all two-digit positive integers <math>x</math> such that <math>5x</math> is a two-digit positive integer.'''<br />
<br />
We can create a function with our previous code.<br />
<br />
We will have to slightly modify our function so we can use it in a for loop at the end:<br />
<br />
def check(a):<br />
if a*5 > 9 and a*5 < 100:<br />
return True <br />
else:<br />
return False<br />
<br />
True and False are what are called '''booleans'''. When an if or elif statement receives True, the code inside of the statement happens. When an if or elif statement receives False, the code inside of the statement does not happen. <br />
<br />
We must create a for loop that will iterate through all two digit positive integers. <br />
<br />
def check(a):<br />
if a*5 > 9 and a*5 < 100:<br />
return True <br />
else:<br />
return False<br />
for i in range(10,100):<br />
if check(i):<br />
print(i)<br />
<br />
The final for loop checks if <math>5i</math> is a two digit integer. If it is, the function returns True and the code inside the if statement gets run. If it isn't, the function returns False and the code inside the if statement gets ignored.<br />
<br />
If we run this, we will get the answer.<br />
<br />
All two digit integers from 10 to 19 inclusive work!<br />
<br />
=="Soft Coding" Programs==<br />
<br />
In the next few examples, you will see why hard coding programs is bad. Hard coding programs refers to coding a program that is hard to modify. For example:<br />
<br />
===Program Example 1===<br />
<br />
'''Print all two digit positive integers <math>x</math> such that <math>5x</math> is a three digit positive integer.'''<br />
<br />
We can keep our code and modify some parts of it.<br />
<br />
def check(a, min, max):<br />
if a*5 > min - 1 and a*5 < max + 1:<br />
return True <br />
else:<br />
return False<br />
<br />
def print_check(range_min, range_max, check_min, check_max):<br />
for i in range(range_min, range_max + 1):<br />
if check(i, check_min, check_max):<br />
print(i)<br />
return<br />
<br />
print_check(10, 99, 100, 999)<br />
<br />
Why did we add so many functions?<br />
<br />
Well, if the numbers in a problem change (and the words stay the same), and you need to change a lot of numbers in your program, your program is considered '''hard-coded'''. We want our programs to be as '''soft-coded''' as possible. In our new program, we only need to change 4 numbers (in the print_check() statement) if the numbers in the problem change. Therefore, our program is relatively soft-coded. There are still ways to soft-code this program even more, though.<br />
<br />
If we run our program, we get our answer.<br />
<br />
All numbers from 20 to 99 work!<br />
<br />
===Program Example 2===<br />
<br />
'''Print all three digit positive integers <math>x</math> such that <math>5x</math> is a three digit positive integer.'''<br />
<br />
We can just change the print_check line at the end to<br />
<br />
print_check(100, 999, 100, 999)<br />
<br />
and our program will be ready to be run.<br />
<br />
All numbers from 100 to 199 work.<br />
<br />
===Program Example 3===<br />
<br />
'''Print all two digit positive integers <math>x</math> such that <math>3x</math> is a three digit positive integer.'''<br />
<br />
Uh oh. Only changing the print_check line won't work. We will need to change our functions!<br />
<br />
def check(a, min, max, factor):<br />
if a*factor > min - 1 and a*factor < max + 1:<br />
return True <br />
else:<br />
return False<br />
<br />
def print_check(range_min, range_max, check_min, check_max, check_factor):<br />
for i in range(range_min, range_max + 1):<br />
if check(i, check_min, check_max, check_factor):<br />
print(i)<br />
return<br />
<br />
print_check(10, 99, 100, 999, 3)<br />
<br />
In this step, we added a parameter in both functions. We also soft-coded our program even more! Hooray!<br />
<br />
All integers from 34 to 99 work.<br />
<br />
===Program Example 4===<br />
<br />
'''Print all two digit positive integers <math>x</math> such that <math>12x</math> is a positive integer from 500 to 900.'''<br />
<br />
This problem may look a bit different from the other ones, but it really is the same thing, except that the factor is 12 and check_min and check_max are 500 and 900, respectively.<br />
<br />
Once we change the final print_check() line to satisfy our needs, we can run our program.<br />
<br />
All numbers from 42 to 75 work!<br />
<br />
Congrats! You have written your first programs above 10 lines of code!<br />
<br />
==Random==<br />
<br />
There is a package in Python that allows the use of random numbers.<br />
<br />
===Program Example 1===<br />
<br />
'''Generate a random number from 1 to 6.'''<br />
<br />
Easy peasy. We will just generate a random number from 1 to 6 with the package like this:<br />
<br />
import random<br />
print(random.randint(1,6))<br />
<br />
As you can see, when you run this program, you get a random integer from 1 to 6.<br />
<br />
===Program Example 2===<br />
<br />
'''Simulate the rolling of 1000 dice. Now, count the number of times you roll 6. Print that number out.'''<br />
<br />
We can create a function that returns a random number from 1 to 6. Then, we can make a for loop that rolls the dice 1000 times and check if it is a 6.<br />
<br />
import random<br />
count = 0<br />
<br />
def roll():<br />
return random.randint(1,6)<br />
<br />
for i in range(1, 1001):<br />
if roll() == 6:<br />
count += 1<br />
<br />
print(count)<br />
<br />
If we run this, we will get a number around 170.<br />
<br />
===Program Example 3===<br />
<br />
'''Simulate the rolling of 10,000 dice. Now, count the amount of times you roll 3. Print that amount out.'''<br />
<br />
We can keep our roll function and our code inside the for loop, but we need to change our for loop statement.<br />
<br />
We can actually soft-code our program more. Let's turn the whole for loop into a function!<br />
<br />
import random<br />
<br />
def roll():<br />
return random.randint(1,6)<br />
<br />
def count(amount):<br />
count_ = 0<br />
<br />
for i in range(1, amount+1):<br />
if roll() == 3:<br />
count_ += 1<br />
return count_<br />
<br />
print(count(10000))<br />
<br />
If we run this code, it works.<br />
<br />
===Program Example 4===<br />
<br />
'''One of my friends loves rolling dice. He is going to roll 1 die tomorrow, 2 dice two days from now, 3 dice three days from now, and so on so that he rolls <math>a</math> dice <math>a</math> days from now. He gets tired rolling dice after rolling dice for 365 days (so the last day he rolls 365 dice). In Python, simulate this. How many times does he roll 3 after 365 days of rolling dice?'''<br />
<br />
We can use a for loop that calls a function multiple times.<br />
<br />
import random<br />
<br />
def roll():<br />
return random.randint(1,6)<br />
<br />
def count(amount):<br />
count_ = 0<br />
for i in range(1, amount+1):<br />
if roll() == 3:<br />
count_ += 1<br />
return count_<br />
<br />
total = 0<br />
<br />
for i in range(1, 366):<br />
total += count(i)<br />
<br />
print(total)<br />
<br />
This is a really long program, but the whole program should make sense if you look at it for a while. We defined our count function in the previous example, and now we are using it with a for loop and a running total. <br />
<br />
You should get a number around 11,000 when you run it. Wow, lots of 3's!<br />
<br />
===Program Example 5===<br />
<br />
'''20 of my friends love rolling dice. They are all going to roll 1 die each tomorrow, 2 dice each two days from now, 3 dice each three days from now, and so on so that they roll <math>a</math> dice each <math>a</math> days from now. But, one of my friends gets tired very quickly and he only rolls dice for 1 day and stops. Another friend only will roll dice for 2 days, and another will roll dice for three days only, and so on up to the fact that my last friend will roll dice for 20 days. In Python, simulate this. How many times does someone roll 3 after everything?'''<br />
<br />
We will have to make our for loop into a function again.<br />
<br />
import random<br />
<br />
def roll():<br />
return random.randint(1,6)<br />
<br />
def count(amount):<br />
count_ = 0<br />
for i in range(1, amount+1):<br />
if roll() == 3:<br />
count_ += 1<br />
return count_<br />
<br />
def count2(amount)<br />
total = 0<br />
for i in range(1, amount + 1):<br />
total += count(i)<br />
return total<br />
<br />
def count3(amount)<br />
total = 0<br />
for i in range(1, amount + 1):<br />
total += count2(i)<br />
return total<br />
<br />
print(count3(20))<br />
<br />
(Our program is so long!)<br />
<br />
I also made a new function just in case we needed to turn that into a function later.<br />
<br />
'''Make sure''' you read the code carefully and you fully understand it. If you don't understand every single line of code, then you will get confused later on in this article.<br />
<br />
When you run this program, you might be surprised that the answer isn't so big.<br />
<br />
===Program Example 6===<br />
<br />
'''365 of my friends love rolling dice. They are all going to roll 1 die each tomorrow, 2 dice each two days from now, 3 dice each three days from now, and so on so that they roll <math>a</math> dice each <math>a</math> days from now. But, one of my friends gets tired very quickly and he only rolls dice for 1 day and stops. Another friend only will roll dice for 2 days, and another will roll dice for three days only, and so on up to the fact that my last friend will roll dice for 365 days. In Python, simulate this. How many times does someone roll 3 after everything?'''<br />
<br />
Because we soft-coded our program so much, all we have to do is change the last line so the parameter of count3() is 365.<br />
<br />
If we run it...we get a big answer, as expected. It also takes quite a while!<br />
<br />
You may not have realized that we soft-coded our program at all, but the whole point of functions is to soft-code programs!<br />
<br />
Congrats on writing a program that is around 25 lines long!<br />
<br />
==Very Basic Datatypes==<br />
<br />
An integer is a basic datatype in Python. Basically, all variables with the datatype of '''int''' is an integer.<br />
<br />
A string is another basic datatype, and it is a string of characters enclosed by quotes.<br />
<br />
===Why Are Datatypes So Important?===<br />
<br />
Let's say we wanted to make a program that would add 2 and 3. Some bogus code would be:<br />
<br />
x="2"<br />
y="3"<br />
print(x+y)<br />
<br />
If you ran this code, you would get 23. Why is that?<br />
<br />
Well, here, x and y are strings. When you perform the addition operator to strings in Python, it concatenates the strings, giving 23.<br />
<br />
The real code is:<br />
<br />
x=2<br />
y=3<br />
print(x+y)<br />
<br />
If you run this, you will get <math>5</math>, which is correct.<br />
<br />
Here's another reason datatypes are important. Now, we will introduce the datatype called the '''floating point number''', or '''float'''. A floating-point number is a number with a decimal point.<br />
<br />
Let's go back to the IDLE. Type "0.1*10". The result is 1.0. Notice the decimal point.<br />
<br />
Let's type something different. Type <math>0.1+0.1+0.1+0.1+0.1+0.1+0.1+0.1+0.1+0.1.</math><br />
<br />
'''WHAT!?'''<br />
<br />
You would have expected the answer to be 1, but it isn't 1. What happened?<br />
<br />
'''Float approximation''' happened. Most (almost all) programming languages have a bad float approximation. That means that 1.0 can turn into 0.99999999999999 and 0.5 can turn into 0.49999999999999999993. That only happens with floats, so we should try to use floats as sparingly as possible.<br />
<br />
==Lists==<br />
<br />
A for loop iterates over a '''list'''. A list is a bunch of objects stored in one variable. (Hey! A list is a datatype!) For loops are highly related to lists.<br />
<br />
Let's say we wanted to make a program to print all the items in a list.<br />
<br />
We will first create the list, using the code:<br />
<br />
myList = [1,4,6,8]<br />
<br />
This is a list with four items: 1, 4, 6, and 8.<br />
<br />
We must now print all elements of it with a for loop:<br />
<br />
myList = [1,4,6,8]<br />
for i in myList:<br />
print(i)<br />
<br />
When we run this program, we get the numbers 1, 4, 6, and 8, as expected.<br />
<br />
===Accessing Values===<br />
<br />
Let's say we wanted to print out the second item in a list. We will use '''indexes'''.<br />
<br />
The index of the first item in a list is always 0. The index of the second is 1. The index of the <math>n</math>th is <math>n-1.</math><br />
<br />
To print out the second item, we will use an index of 1, like this:<br />
<br />
myList = [1,4,6,8]<br />
print(myList[1])<br />
<br />
Notice that the index is inside of the square brackets.<br />
<br />
===Adding Values===<br />
<br />
We can use the list.append() function to add an object to the end of a list.<br />
<br />
myList.append(10)<br />
<br />
will add 10 to the list, which makes myList = [1,4,6,8,10].<br />
<br />
===Removing Items From Lists===<br />
<br />
We can use the list.remove() function to remove a specific item in a list.<br />
<br />
For example, consider this code.<br />
<br />
myList = [1,2,3]<br />
myList.remove(3)<br />
<br />
This code will make myList turn into [1,2]. The element, 3, gets removed.<br />
<br />
===len(list)===<br />
<br />
The len(list) function returns the length of a list.<br />
<br />
This code will print 3.<br />
<br />
myList = [1,2,3]<br />
print(len(myList))<br />
<br />
The length of myList is 3, so Python prints 3.<br />
<br />
===All Kinds Of Lists===<br />
<br />
Lists don't have to be only integers!<br />
<br />
myList = [1,"Hi","Hello world", 3.5, 3.14159265358979323]<br />
<br />
If fact, there can be lists inside of lists!<br />
<br />
myList = [[1,2,3], [3,4,5], [5,6,"Hello world"], "BOB", 3.1415926]<br />
<br />
Even this!<br />
<br />
myList = [[1, [1, [1,2,3],3],3], [[[3,["Hello world", 4],5],4,5],4,5], [5,6,7,[1,[1,2,3],3],"Hello world"], "BOB", 3.1415926, True]<br />
<br />
If you look at that list carefully, you will find lists inside of lists inside of lists inside of lists! And, a boolean at the end!<br />
<br />
Like variables, you can have as many lists in a program as you want (a list is a variable)!<br />
<br />
myList = [1,2,3,4]<br />
yourList = [5,6,7,8]<br />
hisList = [9,10,11,12]<br />
herList = [13,14,15,16]<br />
theirList = [17,18,19,20]<br />
ourList = [21,22,23,24]<br />
listsOfLists = [[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16],[17,18,19,20],[21,22,23,24]]<br />
<br />
===Splitting Lists===<br />
Split Operator Basics:<br />
genericList[where to start:where to end:what size steps to take]<br />
The value where to start is inclusive, and denotes the index where your split list begins. It has a default value of 0.<br />
The value where to end is exclusive, and denotes the index where your split list ends. It has a default value of len(genericList).<br />
The value what size steps denotes the size of the steps your split takes(more on that later). It has a default value of 1.<br />
Say you want to split a list and only return certain indices, for example if you wanted to split a list called data and put the first two elements into a list called head and the last two into a list called tail, you would split like this:<br />
data = [1, 3, 4, 23.5, 40, 55]<br />
head = data[:2]<br />
tail = data[-2:] # negative list indices represent the end of a list, so -1 is the last element and -2 is the second-to-last<br />
Step Size:<br />
We will practice writing a few functions that select every other element and will reverse in a list using step size.<br />
A step size of two means skip every other list index, so we can write our first function.<br />
def selectEveryOtherElement(list):<br />
return list[::2]<br />
But which step size will get us our desired reversed list. We could start at the end of the list and iterate backwards, but how would we do that...<br />
Negative Step Size:<br />
A step size that is negative means skip a certain amount of elements, but backwards. If we were to start at 0, with a step size of -1, we would be able to iterate backwards over the list!<br />
def reverse(list):<br />
return list[::-1]<br />
Splitting lists with ratios:<br />
What if we wanted to be able to split a list based upon a ratio. For example, the common 80:20 train to test ratio in machine learning? Here is how you would do it<br />
def eighty-twenty(list):<br />
train = list[:int(len(list) * (4 / 5))] # We must include the int() method to convert to an integer if len(list) % 5 != 0<br />
test = list[int(len(list) * 4 / 5)]<br />
return [train, test] # We then return a list with the train and test lists inside<br />
<br />
==Dictionaries==<br />
<br />
A dictionary (a type of datatype) is a bunch of keys and values. There is a major difference between dictionaries and lists. Lists are ordered; dictionaries are not.<br />
<br />
Here is the '''syntax''' of creating a dictionary:<br />
<br />
myDictionary = {1:"one",2:"two"}<br />
<br />
This dictionary has two key/value pairs. Notice it is surrounded in curly braces. The keys are 1 and 2; the values are "one" and "two."<br />
<br />
How is this useful? Let's make a simple program to test it out.<br />
<br />
myDictionary = {1:"one",2:"two"}<br />
print(myDictionary[1])<br />
print(myDictionary[2])<br />
<br />
===Accessing Values===<br />
<br />
To access a value in a dictionary, you put in the key.<br />
<br />
myDictionary[1]<br />
<br />
returns one, because 1 is the key to "one."<br />
<br />
===Adding New Values===<br />
<br />
To overwrite a value, we do this.<br />
<br />
myDictionary[1] = "won"<br />
<br />
The value to the key 1 is now "won."<br />
<br />
To add a value, we do the same thing!<br />
<br />
myDictionary[3] = "three"<br />
<br />
This adds a key 3 with a value of "three."<br />
<br />
==Misc Concepts==<br />
<br />
This section will talk about some concepts that we haven't learned yet.<br />
<br />
====Concatenating Strings====<br />
<br />
Concatenating strings is putting them together. For example, "one" concatenated with "two" gives "onetwo."<br />
<br />
The following string,<br />
<br />
"Hello, " + person2 + "! How are you?"<br />
<br />
depends on what person2 was. If person2 was Bob, the string would be:<br />
<br />
"Hello, Bob! How are you?"<br />
<br />
It fits together perfectly!<br />
<br />
You cannot concatenate strings with integers. For example, doing this:<br />
<br />
"2" + 3<br />
<br />
will not work. Instead, to get an answer of "23", you must do this:<br />
<br />
"2" + str(3)<br />
<br />
That turns 3 into a string so it is "3", and the result will be "23".<br />
<br />
====Line Breaks====<br />
<br />
We can use multiple line breaks to make our code more organized. There are some places that you cannot line break. For example, this code will produce an error:<br />
<br />
myList =<br />
[1,2,3]<br />
<br />
This code does not work.<br />
<br />
This code '''does work''':<br />
<br />
myList = [<br />
1,2,3]<br />
<br />
It is accepted when you break a line right after the [. It is also accepted right after a comma. (And right before the ending ].)<br />
<br />
myList = [<br />
1,<br />
2,<br />
3<br />
]<br />
<br />
==Challenge Program==<br />
<br />
In this section, we will attempt the hardest program so far in this article.<br />
<br />
'''Make a conversation generator that will generate random conversations between different people.'''<br />
<br />
First, we will generate the people. We can use a list and generate two random numbers.<br />
<br />
import random<br />
<br />
peopleNames = [<br />
"Bob",<br />
"Kyle",<br />
"James",<br />
"Richard",<br />
"Zachary",<br />
"Olivia",<br />
"Jonathan",<br />
"Will",<br />
"Bobby",<br />
"Kevin"<br />
]<br />
person1 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
peopleNames.remove(person1)<br />
person2 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
<br />
(I made it more organized by separating the long lines of code into multiple lines. It only works when you have a line break right after each item in the list.)<br />
<br />
Here, we use the remove() function to remove person1 from the list to make sure we don't use the same name twice. <br />
<br />
We also used the len() function to find the length of the list (soft-coding!)<br />
<br />
Now, we need to create a list of possible values for the first thing that person1 says (person1 will always be the first one to talk). <br />
<br />
Then, we will print it out.<br />
<br />
import random<br />
<br />
peopleNames = [<br />
"Bob",<br />
"Kyle",<br />
"James",<br />
"Richard",<br />
"Zachary",<br />
"Olivia",<br />
"Jonathan",<br />
"Will",<br />
"Bobby",<br />
"Kevin"<br />
]<br />
person1 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
peopleNames.remove(person1)<br />
person2 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
<br />
first = [<br />
"Hi!",<br />
"Hello!",<br />
"Good morning!",<br />
"Hello, " + person2 + "!",<br />
"Hi.",<br />
"Hi, " + person2 + "!"<br />
]<br />
print(person1 + ": " + first[random.randint(0, (len(first) - 1))])<br />
<br />
If we test out this program, we can confirm that this part indeed does work. This program is already getting long! Now, we will use the same method and create the second message.<br />
<br />
import random<br />
<br />
peopleNames = [<br />
"Bob",<br />
"Kyle",<br />
"James",<br />
"Richard",<br />
"Zachary",<br />
"Olivia",<br />
"Jonathan",<br />
"Will",<br />
"Bobby",<br />
"Kevin"<br />
]<br />
person1 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
peopleNames.remove(person1)<br />
person2 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
<br />
first = [<br />
"Hi!",<br />
"Hello!",<br />
"Good morning!",<br />
"Hello, " + person2 + "!",<br />
"Hi.",<br />
"Hi, " + person2 + "!"<br />
]<br />
print(person1 + ": " + first[random.randint(0, (len(first) - 1))])<br />
<br />
second = [<br />
"Hi! How are you today?",<br />
"Hello! How are you?",<br />
"Good morning! How are you today?",<br />
"Hello, " + person1 + "! How are you?",<br />
"Hi. How are you?",<br />
"Hi, " + person1 + "! How are you today?"<br />
]<br />
print(person2 + ": " + second[random.randint(0, (len(second) - 1))])<br />
<br />
We will repeat this for the rest of the conversation:<br />
<br />
import random<br />
<br />
peopleNames = [<br />
"Bob",<br />
"Kyle",<br />
"James",<br />
"Richard",<br />
"Zachary",<br />
"Olivia",<br />
"Jonathan",<br />
"Will", <br />
"Bobby",<br />
"Kevin"<br />
]<br />
person1 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
peopleNames.remove(person1)<br />
person2 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
<br />
first = [<br />
"Hi!",<br />
"Hello!",<br />
"Good morning!",<br />
"Hello, " + person2 + "!",<br />
"Hi.",<br />
"Hi, " + person2 + "!"<br />
]<br />
print(person1 + ": " + first[random.randint(0, (len(first) - 1))])<br />
<br />
second = [<br />
"Hi! How are you today?",<br />
"Hello! How are you?",<br />
"Good morning! How are you today?",<br />
"Hello, " + person1 + "! How are you?",<br />
"Hi. How are you?",<br />
"Hi, " + person1 + "! How are you today?"<br />
]<br />
print(person2 + ": " + second[random.randint(0, (len(second) - 1))])<br />
<br />
third = [<br />
"I'm feeling awesome! And you?",<br />
"I'm feeling alright! How are you?",<br />
"I'm good, thank you. How are you feeling?",<br />
"I'm fine!" ,<br />
"How are you today?"<br />
]<br />
print(person1 + ": " + third[random.randint(0, (len(third) - 1))])<br />
<br />
fourth = [<br />
"I'm feeling great!",<br />
"I'm awesome!",<br />
"Thanks for asking! I am feeling good today!",<br />
"I'm feeling awesome today! Yippee!"<br />
] <br />
print(person2 + ": " + fourth[random.randint(0, (len(fourth) - 1))])<br />
<br />
fifth = [<br />
"It's so nice out today!",<br />
"Today is such a cloudy day.",<br />
"I hate it when it is so cloudy outside!",<br />
"It's partly cloudy today!"<br />
]<br />
print(person1 + ": " + fifth[random.randint(0, (len(fifth) - 1))])<br />
<br />
sixth = [<br />
"I know, right?",<br />
"I know.",<br />
"Yeah!",<br />
"True."<br />
]<br />
print(person2 + ": " + sixth[random.randint(0, (len(sixth) - 1))])<br />
<br />
seventh = [<br />
"Sorry, I need to leave. Bye!",<br />
"I gotta go. Bye!",<br />
"Sorry, I don't have time to stay and chat. I've got to go somewhere. Bye!"<br />
]<br />
print(person1 + ": " + seventh[random.randint(0, (len(seventh) - 1))])<br />
<br />
eighth = [<br />
"Bye!",<br />
"Good-bye!",<br />
"Bye, " + person1 + "."<br />
]<br />
print(person2 + ": " + eighth[random.randint(0, (len(eighth) - 1))])<br />
<br />
Whew! So long!<br />
<br />
Once we run our program. It works! This program really wasn't that hard.<br />
<br />
Congrats! You've made it so far!</div>Anstarhttps://artofproblemsolving.com/wiki/index.php?title=Basic_Programming_With_Python&diff=130596Basic Programming With Python2020-08-04T20:00:22Z<p>Anstar: /* overloading */</p>
<hr />
<div>'''Important: It is extremely recommended that you read [[Getting Started With Python Programming]] before reading this unless you already know some programming knowledge.'''<br />
<br />
(Note: This is a really long article. To learn the most from this article, you need to read everything in order and skip nothing, unless you are '''absolutely absolutely sure that that content is way too easy for you.''')<br />
<br />
This article will talk about some basic Python programming. If you don't even know how to install Python, look [[Getting Started With Python Programming|here]].<br />
<br />
Note that this article has lots of program examples. It is recommended (but not required) to try these on your own before looking at the solutions.<br />
<br />
==Loops==<br />
<br />
There are two different kinds of loops in Python: the for loop and the while loop.<br />
<br />
===The For Loop===<br />
<br />
The for loop iterates over a list, or an array, of objects. You have probably seen this code before:<br />
<br />
[[File:Capture.PNG|200px]]<br />
<br />
This for loop iterates over the list of integers from 1 to 51, excluding the 51 and including the 1. That means it is a list from 1 to 50, inclusive. On every iteration, Python will print the number that the loop is iterating through. <br />
<br />
For example, in the first iteration, i = 1, so Python prints 1.<br />
<br />
In the second iteration, i = 2, so Python prints 2.<br />
<br />
This continues so on until the number, 50, is reached. Therefore, the last number Python will print out is 50.<br />
<br />
====Program Example====<br />
<br />
'''Find <math>\sum_{n=1}^{50} 2^{n}.</math>'''<br />
<br />
To do this task, we must create a for loop and loop over the integers from 1 to 50 inclusive:<br />
<br />
for i in range(1,51):<br />
<br />
Now what? We must keep a running total and increase it by <math>2^i</math> every time:<br />
<br />
total = 0<br />
for i in range(1,51):<br />
total += 2**i<br />
<br />
We must not forget to print the total at the end!<br />
<br />
total = 0<br />
for i in range(1,51):<br />
total += 2**i<br />
print(total)<br />
<br />
You must exit out of the for loop one you reach the print(total) line by pressing backspace.<br />
<br />
Once you run your program, you should get an answer of <math>\boxed{2,251,799,813,685,246.}</math><br />
<br />
===The While Loop===<br />
<br />
While loops don't loop over a list. They loop over and over and over...'''until'''...a condition becomes false.<br />
<br />
i = 3<br />
total = 0<br />
while i < 1000:<br />
total += i<br />
i += 3<br />
print(total)<br />
<br />
In this code, the while loop loops 333 times, until <math>i</math> becomes greater than or equal to 1000.<br />
<br />
====Program Example====<br />
<br />
'''Find <math>\sum_{n=1}^{50} 2^n</math> using a while loop.'''<br />
<br />
We must create a while loop that will iterate until n is greater than <math>50.</math><br />
<br />
n = 1<br />
total = 0<br />
while n <= 50:<br />
total += 2**n<br />
n += 1<br />
print(total)<br />
<br />
We must not forget to include the n += 1 line at the end of the while loop! <br />
<br />
If we run this, we will get the same answer as last time, <math>2,251,799,813,685,246.</math><br />
<br />
==Functions==<br />
<br />
In this section, we will define new operations and do arithmetic with them in Python.<br />
<br />
===The New Operation===<br />
Let's say that you defined a new binary operation, the <math>\uparrow \downarrow.</math> You want it to be so <math>a \uparrow \downarrow b = a^{b}b^{a}.</math> Therefore, <math>1\uparrow \downarrow 2 = 1^{2}2^{1}=1\cdot 2= 2,</math> and <math>2\uparrow \downarrow 3 = 2^33^2 = 8\cdot 9 = 72.</math> Let's call this operation an '''up down arrow.'''<br />
<br />
===Program Example 1===<br />
<br />
'''Find <math>[2 \uparrow \downarrow (1 \uparrow \downarrow 2)] \uparrow \downarrow 2.</math>'''<br />
<br />
We know this will be a big number, so we should write a program to do it! We certainly don't want to do the exponentiation and multiplication every time we use the operation in our program, and that's where functions come in! Functions can take in parameters (<math>a</math> and <math>b</math>) and return a result depending on the parameters.<br />
<br />
def up_down_arrow(a,b): <br />
return ((a**b) * (b**a))<br />
<br />
Above is the code to define our function. We need to print the final result at the end, so we must put a print statement at the end.<br />
<br />
def up_down_arrow(a,b): <br />
return ((a**b) * (b**a))<br />
print(up_down_arrow(up_down_arrow(2,up_down_arrow(1,2)),2)<br />
<br />
All those nested up_down_arrow's might be confusing at first, but it really isn't that confusing.<br />
If you run your program, you should get your answer: <math>16,777,216.</math> <br />
<br />
You might be surprised that the answer is so big. If you actually start calculating the real answer without a program, you will really quickly find that the final result is <math>16 \uparrow \downarrow 2,</math> which does turn out to be 16,777,216 if you use a calculator.<br />
<br />
Let's make another operation!<br />
<br />
We will define the operation <math>\uparrow \downarrow \leftarrow \rightarrow</math> to be called '''all around.''' <math>a \uparrow \downarrow \leftarrow \rightarrow b = (ab(a \uparrow \downarrow b))^2.</math> That's an operation that will make really big numbers!<br />
<br />
===Program Example 2===<br />
<br />
'''Find 87 all around 132.'''<br />
<br />
The answer is bound to be a huge number, so we must make a program to solve it.<br />
<br />
We will keep our up_down_arrow function because in the definition of our all_around function we will use it. Then, we will define the all_around function.<br />
<br />
def up_down_arrow(a,b):<br />
return ((a**b) * (b**a))<br />
def all_around(a,b):<br />
return ((a * b * up_down_arrow(a,b)) ** 2)<br />
<br />
We must print all_around(87,132) at the end. Once we do that, and we run our program, we get a super huge number that has over 800 digits!<br />
<br />
===Understanding Functions===<br />
<br />
Every single function has a '''return value'''. If a function does not return anything, the return value is '''null'''. Null is a term used in programming as a placeholder that stands for nothing.<br />
<br />
====Simple Program Example 1====<br />
<br />
'''Define a function that adds 1 to an input.'''<br />
<br />
How will the function know what number to add 1 to? We will input a '''parameter''' for the function to add 1 to.<br />
<br />
def add_one(x):<br />
return x + 1<br />
<br />
In this function, <math>x</math> is the parameter.<br />
<br />
def add_one(x):<br />
return x + 1<br />
print(add_one(2))<br />
<br />
In the print statement, we set <math>x</math> as 2, and the function returns <math>2 + 1 = 3,</math> so the program prints <math>3</math>.<br />
<br />
====Simple Program Example 2====<br />
<br />
'''Define a function that prints out an input.'''<br />
<br />
We will use a parameter again.<br />
<br />
def print_function(x):<br />
print(x)<br />
<br />
Uh oh! We have nothing to return! Therefore, we will return nothing (or null), by just writing return.<br />
<br />
def print_function(x):<br />
print(x)<br />
return<br />
print_function("print_function")<br />
<br />
This code prints out print_function. print_function() is said to be '''called''' in the final line of the code. Again, we set <math>x</math>, our parameter, as "print_function."<br />
== Classes ==<br />
Classes are <br />
<br />
===Defining a class===<br />
===methods===<br />
methods are definition that apply to a class.<br />
===__init__===<br />
===__str__==<br />
===overloading===<br />
overloading means changing a builtin function to do what you want it to do.<br />
<br />
==Flow==<br />
<br />
Flow consists of if statements, elif (else if) statements, and else statements.<br />
<br />
*An if statement checks if a comparison is true.<br />
<br />
*An else statement checks if a comparison is not true. It is used after an if statement (and all elif statements after the if statement) and it shares the same comparison as the if statement.<br />
<br />
*An elif statement checks for two things: if a comparison is true, and if a comparison is not true. It is used right after the if statement.<br />
<br />
===Program Example===<br />
<br />
'''Does the number 10 have the property that when you multiply 10 by 5, you get a two digit number?'''<br />
<br />
This problem is super easy to solve without a program, but let's write a program to solve this anyway. We will use an if statement to check if <math>10\cdot 5</math> is less than 100 and greater than 9.<br />
<br />
if 10*5 > 9:<br />
if 10*5 < 100:<br />
print("Yes")<br />
else:<br />
print("No")<br />
else:<br />
print("No")<br />
<br />
This code means, if 10*5 > 9, then we will check if it is less than 100. If it is not greater than 9, however, we will print No. If it is greater than 9, we check if it is less than 100. If it is, we print Yes. If it isn't we print No.<br />
<br />
These nested if statements can be very confusing. Luckily, there is a faster an easier way to do this.<br />
<br />
if 10*5 > 9 and 10*5 < 100:<br />
print("Yes") <br />
else:<br />
print("No")<br />
<br />
This code checks for the two conditions at the same time. If we run it, we get our answer of Yes.<br />
<br />
==Booleans==<br />
<br />
===Program Example===<br />
<br />
'''Print all two-digit positive integers <math>x</math> such that <math>5x</math> is a two-digit positive integer.'''<br />
<br />
We can create a function with our previous code.<br />
<br />
We will have to slightly modify our function so we can use it in a for loop at the end:<br />
<br />
def check(a):<br />
if a*5 > 9 and a*5 < 100:<br />
return True <br />
else:<br />
return False<br />
<br />
True and False are what are called '''booleans'''. When an if or elif statement receives True, the code inside of the statement happens. When an if or elif statement receives False, the code inside of the statement does not happen. <br />
<br />
We must create a for loop that will iterate through all two digit positive integers. <br />
<br />
def check(a):<br />
if a*5 > 9 and a*5 < 100:<br />
return True <br />
else:<br />
return False<br />
for i in range(10,100):<br />
if check(i):<br />
print(i)<br />
<br />
The final for loop checks if <math>5i</math> is a two digit integer. If it is, the function returns True and the code inside the if statement gets run. If it isn't, the function returns False and the code inside the if statement gets ignored.<br />
<br />
If we run this, we will get the answer.<br />
<br />
All two digit integers from 10 to 19 inclusive work!<br />
<br />
=="Soft Coding" Programs==<br />
<br />
In the next few examples, you will see why hard coding programs is bad. Hard coding programs refers to coding a program that is hard to modify. For example:<br />
<br />
===Program Example 1===<br />
<br />
'''Print all two digit positive integers <math>x</math> such that <math>5x</math> is a three digit positive integer.'''<br />
<br />
We can keep our code and modify some parts of it.<br />
<br />
def check(a, min, max):<br />
if a*5 > min - 1 and a*5 < max + 1:<br />
return True <br />
else:<br />
return False<br />
<br />
def print_check(range_min, range_max, check_min, check_max):<br />
for i in range(range_min, range_max + 1):<br />
if check(i, check_min, check_max):<br />
print(i)<br />
return<br />
<br />
print_check(10, 99, 100, 999)<br />
<br />
Why did we add so many functions?<br />
<br />
Well, if the numbers in a problem change (and the words stay the same), and you need to change a lot of numbers in your program, your program is considered '''hard-coded'''. We want our programs to be as '''soft-coded''' as possible. In our new program, we only need to change 4 numbers (in the print_check() statement) if the numbers in the problem change. Therefore, our program is relatively soft-coded. There are still ways to soft-code this program even more, though.<br />
<br />
If we run our program, we get our answer.<br />
<br />
All numbers from 20 to 99 work!<br />
<br />
===Program Example 2===<br />
<br />
'''Print all three digit positive integers <math>x</math> such that <math>5x</math> is a three digit positive integer.'''<br />
<br />
We can just change the print_check line at the end to<br />
<br />
print_check(100, 999, 100, 999)<br />
<br />
and our program will be ready to be run.<br />
<br />
All numbers from 100 to 199 work.<br />
<br />
===Program Example 3===<br />
<br />
'''Print all two digit positive integers <math>x</math> such that <math>3x</math> is a three digit positive integer.'''<br />
<br />
Uh oh. Only changing the print_check line won't work. We will need to change our functions!<br />
<br />
def check(a, min, max, factor):<br />
if a*factor > min - 1 and a*factor < max + 1:<br />
return True <br />
else:<br />
return False<br />
<br />
def print_check(range_min, range_max, check_min, check_max, check_factor):<br />
for i in range(range_min, range_max + 1):<br />
if check(i, check_min, check_max, check_factor):<br />
print(i)<br />
return<br />
<br />
print_check(10, 99, 100, 999, 3)<br />
<br />
In this step, we added a parameter in both functions. We also soft-coded our program even more! Hooray!<br />
<br />
All integers from 34 to 99 work.<br />
<br />
===Program Example 4===<br />
<br />
'''Print all two digit positive integers <math>x</math> such that <math>12x</math> is a positive integer from 500 to 900.'''<br />
<br />
This problem may look a bit different from the other ones, but it really is the same thing, except that the factor is 12 and check_min and check_max are 500 and 900, respectively.<br />
<br />
Once we change the final print_check() line to satisfy our needs, we can run our program.<br />
<br />
All numbers from 42 to 75 work!<br />
<br />
Congrats! You have written your first programs above 10 lines of code!<br />
<br />
==Random==<br />
<br />
There is a package in Python that allows the use of random numbers.<br />
<br />
===Program Example 1===<br />
<br />
'''Generate a random number from 1 to 6.'''<br />
<br />
Easy peasy. We will just generate a random number from 1 to 6 with the package like this:<br />
<br />
import random<br />
print(random.randint(1,6))<br />
<br />
As you can see, when you run this program, you get a random integer from 1 to 6.<br />
<br />
===Program Example 2===<br />
<br />
'''Simulate the rolling of 1000 dice. Now, count the number of times you roll 6. Print that number out.'''<br />
<br />
We can create a function that returns a random number from 1 to 6. Then, we can make a for loop that rolls the dice 1000 times and check if it is a 6.<br />
<br />
import random<br />
count = 0<br />
<br />
def roll():<br />
return random.randint(1,6)<br />
<br />
for i in range(1, 1001):<br />
if roll() == 6:<br />
count += 1<br />
<br />
print(count)<br />
<br />
If we run this, we will get a number around 170.<br />
<br />
===Program Example 3===<br />
<br />
'''Simulate the rolling of 10,000 dice. Now, count the amount of times you roll 3. Print that amount out.'''<br />
<br />
We can keep our roll function and our code inside the for loop, but we need to change our for loop statement.<br />
<br />
We can actually soft-code our program more. Let's turn the whole for loop into a function!<br />
<br />
import random<br />
<br />
def roll():<br />
return random.randint(1,6)<br />
<br />
def count(amount):<br />
count_ = 0<br />
<br />
for i in range(1, amount+1):<br />
if roll() == 3:<br />
count_ += 1<br />
return count_<br />
<br />
print(count(10000))<br />
<br />
If we run this code, it works.<br />
<br />
===Program Example 4===<br />
<br />
'''One of my friends loves rolling dice. He is going to roll 1 die tomorrow, 2 dice two days from now, 3 dice three days from now, and so on so that he rolls <math>a</math> dice <math>a</math> days from now. He gets tired rolling dice after rolling dice for 365 days (so the last day he rolls 365 dice). In Python, simulate this. How many times does he roll 3 after 365 days of rolling dice?'''<br />
<br />
We can use a for loop that calls a function multiple times.<br />
<br />
import random<br />
<br />
def roll():<br />
return random.randint(1,6)<br />
<br />
def count(amount):<br />
count_ = 0<br />
for i in range(1, amount+1):<br />
if roll() == 3:<br />
count_ += 1<br />
return count_<br />
<br />
total = 0<br />
<br />
for i in range(1, 366):<br />
total += count(i)<br />
<br />
print(total)<br />
<br />
This is a really long program, but the whole program should make sense if you look at it for a while. We defined our count function in the previous example, and now we are using it with a for loop and a running total. <br />
<br />
You should get a number around 11,000 when you run it. Wow, lots of 3's!<br />
<br />
===Program Example 5===<br />
<br />
'''20 of my friends love rolling dice. They are all going to roll 1 die each tomorrow, 2 dice each two days from now, 3 dice each three days from now, and so on so that they roll <math>a</math> dice each <math>a</math> days from now. But, one of my friends gets tired very quickly and he only rolls dice for 1 day and stops. Another friend only will roll dice for 2 days, and another will roll dice for three days only, and so on up to the fact that my last friend will roll dice for 20 days. In Python, simulate this. How many times does someone roll 3 after everything?'''<br />
<br />
We will have to make our for loop into a function again.<br />
<br />
import random<br />
<br />
def roll():<br />
return random.randint(1,6)<br />
<br />
def count(amount):<br />
count_ = 0<br />
for i in range(1, amount+1):<br />
if roll() == 3:<br />
count_ += 1<br />
return count_<br />
<br />
def count2(amount)<br />
total = 0<br />
for i in range(1, amount + 1):<br />
total += count(i)<br />
return total<br />
<br />
def count3(amount)<br />
total = 0<br />
for i in range(1, amount + 1):<br />
total += count2(i)<br />
return total<br />
<br />
print(count3(20))<br />
<br />
(Our program is so long!)<br />
<br />
I also made a new function just in case we needed to turn that into a function later.<br />
<br />
'''Make sure''' you read the code carefully and you fully understand it. If you don't understand every single line of code, then you will get confused later on in this article.<br />
<br />
When you run this program, you might be surprised that the answer isn't so big.<br />
<br />
===Program Example 6===<br />
<br />
'''365 of my friends love rolling dice. They are all going to roll 1 die each tomorrow, 2 dice each two days from now, 3 dice each three days from now, and so on so that they roll <math>a</math> dice each <math>a</math> days from now. But, one of my friends gets tired very quickly and he only rolls dice for 1 day and stops. Another friend only will roll dice for 2 days, and another will roll dice for three days only, and so on up to the fact that my last friend will roll dice for 365 days. In Python, simulate this. How many times does someone roll 3 after everything?'''<br />
<br />
Because we soft-coded our program so much, all we have to do is change the last line so the parameter of count3() is 365.<br />
<br />
If we run it...we get a big answer, as expected. It also takes quite a while!<br />
<br />
You may not have realized that we soft-coded our program at all, but the whole point of functions is to soft-code programs!<br />
<br />
Congrats on writing a program that is around 25 lines long!<br />
<br />
==Very Basic Datatypes==<br />
<br />
An integer is a basic datatype in Python. Basically, all variables with the datatype of '''int''' is an integer.<br />
<br />
A string is another basic datatype, and it is a string of characters enclosed by quotes.<br />
<br />
===Why Are Datatypes So Important?===<br />
<br />
Let's say we wanted to make a program that would add 2 and 3. Some bogus code would be:<br />
<br />
x="2"<br />
y="3"<br />
print(x+y)<br />
<br />
If you ran this code, you would get 23. Why is that?<br />
<br />
Well, here, x and y are strings. When you perform the addition operator to strings in Python, it concatenates the strings, giving 23.<br />
<br />
The real code is:<br />
<br />
x=2<br />
y=3<br />
print(x+y)<br />
<br />
If you run this, you will get <math>5</math>, which is correct.<br />
<br />
Here's another reason datatypes are important. Now, we will introduce the datatype called the '''floating point number''', or '''float'''. A floating-point number is a number with a decimal point.<br />
<br />
Let's go back to the IDLE. Type "0.1*10". The result is 1.0. Notice the decimal point.<br />
<br />
Let's type something different. Type <math>0.1+0.1+0.1+0.1+0.1+0.1+0.1+0.1+0.1+0.1.</math><br />
<br />
'''WHAT!?'''<br />
<br />
You would have expected the answer to be 1, but it isn't 1. What happened?<br />
<br />
'''Float approximation''' happened. Most (almost all) programming languages have a bad float approximation. That means that 1.0 can turn into 0.99999999999999 and 0.5 can turn into 0.49999999999999999993. That only happens with floats, so we should try to use floats as sparingly as possible.<br />
<br />
==Lists==<br />
<br />
A for loop iterates over a '''list'''. A list is a bunch of objects stored in one variable. (Hey! A list is a datatype!) For loops are highly related to lists.<br />
<br />
Let's say we wanted to make a program to print all the items in a list.<br />
<br />
We will first create the list, using the code:<br />
<br />
myList = [1,4,6,8]<br />
<br />
This is a list with four items: 1, 4, 6, and 8.<br />
<br />
We must now print all elements of it with a for loop:<br />
<br />
myList = [1,4,6,8]<br />
for i in myList:<br />
print(i)<br />
<br />
When we run this program, we get the numbers 1, 4, 6, and 8, as expected.<br />
<br />
===Accessing Values===<br />
<br />
Let's say we wanted to print out the second item in a list. We will use '''indexes'''.<br />
<br />
The index of the first item in a list is always 0. The index of the second is 1. The index of the <math>n</math>th is <math>n-1.</math><br />
<br />
To print out the second item, we will use an index of 1, like this:<br />
<br />
myList = [1,4,6,8]<br />
print(myList[1])<br />
<br />
Notice that the index is inside of the square brackets.<br />
<br />
===Adding Values===<br />
<br />
We can use the list.append() function to add an object to the end of a list.<br />
<br />
myList.append(10)<br />
<br />
will add 10 to the list, which makes myList = [1,4,6,8,10].<br />
<br />
===Removing Items From Lists===<br />
<br />
We can use the list.remove() function to remove a specific item in a list.<br />
<br />
For example, consider this code.<br />
<br />
myList = [1,2,3]<br />
myList.remove(3)<br />
<br />
This code will make myList turn into [1,2]. The element, 3, gets removed.<br />
<br />
===len(list)===<br />
<br />
The len(list) function returns the length of a list.<br />
<br />
This code will print 3.<br />
<br />
myList = [1,2,3]<br />
print(len(myList))<br />
<br />
The length of myList is 3, so Python prints 3.<br />
<br />
===All Kinds Of Lists===<br />
<br />
Lists don't have to be only integers!<br />
<br />
myList = [1,"Hi","Hello world", 3.5, 3.14159265358979323]<br />
<br />
If fact, there can be lists inside of lists!<br />
<br />
myList = [[1,2,3], [3,4,5], [5,6,"Hello world"], "BOB", 3.1415926]<br />
<br />
Even this!<br />
<br />
myList = [[1, [1, [1,2,3],3],3], [[[3,["Hello world", 4],5],4,5],4,5], [5,6,7,[1,[1,2,3],3],"Hello world"], "BOB", 3.1415926, True]<br />
<br />
If you look at that list carefully, you will find lists inside of lists inside of lists inside of lists! And, a boolean at the end!<br />
<br />
Like variables, you can have as many lists in a program as you want (a list is a variable)!<br />
<br />
myList = [1,2,3,4]<br />
yourList = [5,6,7,8]<br />
hisList = [9,10,11,12]<br />
herList = [13,14,15,16]<br />
theirList = [17,18,19,20]<br />
ourList = [21,22,23,24]<br />
listsOfLists = [[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16],[17,18,19,20],[21,22,23,24]]<br />
<br />
===Splitting Lists===<br />
Split Operator Basics:<br />
genericList[where to start:where to end:what size steps to take]<br />
The value where to start is inclusive, and denotes the index where your split list begins. It has a default value of 0.<br />
The value where to end is exclusive, and denotes the index where your split list ends. It has a default value of len(genericList).<br />
The value what size steps denotes the size of the steps your split takes(more on that later). It has a default value of 1.<br />
Say you want to split a list and only return certain indices, for example if you wanted to split a list called data and put the first two elements into a list called head and the last two into a list called tail, you would split like this:<br />
data = [1, 3, 4, 23.5, 40, 55]<br />
head = data[:2]<br />
tail = data[-2:] # negative list indices represent the end of a list, so -1 is the last element and -2 is the second-to-last<br />
Step Size:<br />
We will practice writing a few functions that select every other element and will reverse in a list using step size.<br />
A step size of two means skip every other list index, so we can write our first function.<br />
def selectEveryOtherElement(list):<br />
return list[::2]<br />
But which step size will get us our desired reversed list. We could start at the end of the list and iterate backwards, but how would we do that...<br />
Negative Step Size:<br />
A step size that is negative means skip a certain amount of elements, but backwards. If we were to start at 0, with a step size of -1, we would be able to iterate backwards over the list!<br />
def reverse(list):<br />
return list[::-1]<br />
Splitting lists with ratios:<br />
What if we wanted to be able to split a list based upon a ratio. For example, the common 80:20 train to test ratio in machine learning? Here is how you would do it<br />
def eighty-twenty(list):<br />
train = list[:int(len(list) * (4 / 5))] # We must include the int() method to convert to an integer if len(list) % 5 != 0<br />
test = list[int(len(list) * 4 / 5)]<br />
return [train, test] # We then return a list with the train and test lists inside<br />
<br />
==Dictionaries==<br />
<br />
A dictionary (a type of datatype) is a bunch of keys and values. There is a major difference between dictionaries and lists. Lists are ordered; dictionaries are not.<br />
<br />
Here is the '''syntax''' of creating a dictionary:<br />
<br />
myDictionary = {1:"one",2:"two"}<br />
<br />
This dictionary has two key/value pairs. Notice it is surrounded in curly braces. The keys are 1 and 2; the values are "one" and "two."<br />
<br />
How is this useful? Let's make a simple program to test it out.<br />
<br />
myDictionary = {1:"one",2:"two"}<br />
print(myDictionary[1])<br />
print(myDictionary[2])<br />
<br />
===Accessing Values===<br />
<br />
To access a value in a dictionary, you put in the key.<br />
<br />
myDictionary[1]<br />
<br />
returns one, because 1 is the key to "one."<br />
<br />
===Adding New Values===<br />
<br />
To overwrite a value, we do this.<br />
<br />
myDictionary[1] = "won"<br />
<br />
The value to the key 1 is now "won."<br />
<br />
To add a value, we do the same thing!<br />
<br />
myDictionary[3] = "three"<br />
<br />
This adds a key 3 with a value of "three."<br />
<br />
==Misc Concepts==<br />
<br />
This section will talk about some concepts that we haven't learned yet.<br />
<br />
====Concatenating Strings====<br />
<br />
Concatenating strings is putting them together. For example, "one" concatenated with "two" gives "onetwo."<br />
<br />
The following string,<br />
<br />
"Hello, " + person2 + "! How are you?"<br />
<br />
depends on what person2 was. If person2 was Bob, the string would be:<br />
<br />
"Hello, Bob! How are you?"<br />
<br />
It fits together perfectly!<br />
<br />
You cannot concatenate strings with integers. For example, doing this:<br />
<br />
"2" + 3<br />
<br />
will not work. Instead, to get an answer of "23", you must do this:<br />
<br />
"2" + str(3)<br />
<br />
That turns 3 into a string so it is "3", and the result will be "23".<br />
<br />
====Line Breaks====<br />
<br />
We can use multiple line breaks to make our code more organized. There are some places that you cannot line break. For example, this code will produce an error:<br />
<br />
myList =<br />
[1,2,3]<br />
<br />
This code does not work.<br />
<br />
This code '''does work''':<br />
<br />
myList = [<br />
1,2,3]<br />
<br />
It is accepted when you break a line right after the [. It is also accepted right after a comma. (And right before the ending ].)<br />
<br />
myList = [<br />
1,<br />
2,<br />
3<br />
]<br />
<br />
==Challenge Program==<br />
<br />
In this section, we will attempt the hardest program so far in this article.<br />
<br />
'''Make a conversation generator that will generate random conversations between different people.'''<br />
<br />
First, we will generate the people. We can use a list and generate two random numbers.<br />
<br />
import random<br />
<br />
peopleNames = [<br />
"Bob",<br />
"Kyle",<br />
"James",<br />
"Richard",<br />
"Zachary",<br />
"Olivia",<br />
"Jonathan",<br />
"Will",<br />
"Bobby",<br />
"Kevin"<br />
]<br />
person1 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
peopleNames.remove(person1)<br />
person2 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
<br />
(I made it more organized by separating the long lines of code into multiple lines. It only works when you have a line break right after each item in the list.)<br />
<br />
Here, we use the remove() function to remove person1 from the list to make sure we don't use the same name twice. <br />
<br />
We also used the len() function to find the length of the list (soft-coding!)<br />
<br />
Now, we need to create a list of possible values for the first thing that person1 says (person1 will always be the first one to talk). <br />
<br />
Then, we will print it out.<br />
<br />
import random<br />
<br />
peopleNames = [<br />
"Bob",<br />
"Kyle",<br />
"James",<br />
"Richard",<br />
"Zachary",<br />
"Olivia",<br />
"Jonathan",<br />
"Will",<br />
"Bobby",<br />
"Kevin"<br />
]<br />
person1 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
peopleNames.remove(person1)<br />
person2 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
<br />
first = [<br />
"Hi!",<br />
"Hello!",<br />
"Good morning!",<br />
"Hello, " + person2 + "!",<br />
"Hi.",<br />
"Hi, " + person2 + "!"<br />
]<br />
print(person1 + ": " + first[random.randint(0, (len(first) - 1))])<br />
<br />
If we test out this program, we can confirm that this part indeed does work. This program is already getting long! Now, we will use the same method and create the second message.<br />
<br />
import random<br />
<br />
peopleNames = [<br />
"Bob",<br />
"Kyle",<br />
"James",<br />
"Richard",<br />
"Zachary",<br />
"Olivia",<br />
"Jonathan",<br />
"Will",<br />
"Bobby",<br />
"Kevin"<br />
]<br />
person1 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
peopleNames.remove(person1)<br />
person2 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
<br />
first = [<br />
"Hi!",<br />
"Hello!",<br />
"Good morning!",<br />
"Hello, " + person2 + "!",<br />
"Hi.",<br />
"Hi, " + person2 + "!"<br />
]<br />
print(person1 + ": " + first[random.randint(0, (len(first) - 1))])<br />
<br />
second = [<br />
"Hi! How are you today?",<br />
"Hello! How are you?",<br />
"Good morning! How are you today?",<br />
"Hello, " + person1 + "! How are you?",<br />
"Hi. How are you?",<br />
"Hi, " + person1 + "! How are you today?"<br />
]<br />
print(person2 + ": " + second[random.randint(0, (len(second) - 1))])<br />
<br />
We will repeat this for the rest of the conversation:<br />
<br />
import random<br />
<br />
peopleNames = [<br />
"Bob",<br />
"Kyle",<br />
"James",<br />
"Richard",<br />
"Zachary",<br />
"Olivia",<br />
"Jonathan",<br />
"Will", <br />
"Bobby",<br />
"Kevin"<br />
]<br />
person1 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
peopleNames.remove(person1)<br />
person2 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
<br />
first = [<br />
"Hi!",<br />
"Hello!",<br />
"Good morning!",<br />
"Hello, " + person2 + "!",<br />
"Hi.",<br />
"Hi, " + person2 + "!"<br />
]<br />
print(person1 + ": " + first[random.randint(0, (len(first) - 1))])<br />
<br />
second = [<br />
"Hi! How are you today?",<br />
"Hello! How are you?",<br />
"Good morning! How are you today?",<br />
"Hello, " + person1 + "! How are you?",<br />
"Hi. How are you?",<br />
"Hi, " + person1 + "! How are you today?"<br />
]<br />
print(person2 + ": " + second[random.randint(0, (len(second) - 1))])<br />
<br />
third = [<br />
"I'm feeling awesome! And you?",<br />
"I'm feeling alright! How are you?",<br />
"I'm good, thank you. How are you feeling?",<br />
"I'm fine!" ,<br />
"How are you today?"<br />
]<br />
print(person1 + ": " + third[random.randint(0, (len(third) - 1))])<br />
<br />
fourth = [<br />
"I'm feeling great!",<br />
"I'm awesome!",<br />
"Thanks for asking! I am feeling good today!",<br />
"I'm feeling awesome today! Yippee!"<br />
] <br />
print(person2 + ": " + fourth[random.randint(0, (len(fourth) - 1))])<br />
<br />
fifth = [<br />
"It's so nice out today!",<br />
"Today is such a cloudy day.",<br />
"I hate it when it is so cloudy outside!",<br />
"It's partly cloudy today!"<br />
]<br />
print(person1 + ": " + fifth[random.randint(0, (len(fifth) - 1))])<br />
<br />
sixth = [<br />
"I know, right?",<br />
"I know.",<br />
"Yeah!",<br />
"True."<br />
]<br />
print(person2 + ": " + sixth[random.randint(0, (len(sixth) - 1))])<br />
<br />
seventh = [<br />
"Sorry, I need to leave. Bye!",<br />
"I gotta go. Bye!",<br />
"Sorry, I don't have time to stay and chat. I've got to go somewhere. Bye!"<br />
]<br />
print(person1 + ": " + seventh[random.randint(0, (len(seventh) - 1))])<br />
<br />
eighth = [<br />
"Bye!",<br />
"Good-bye!",<br />
"Bye, " + person1 + "."<br />
]<br />
print(person2 + ": " + eighth[random.randint(0, (len(eighth) - 1))])<br />
<br />
Whew! So long!<br />
<br />
Once we run our program. It works! This program really wasn't that hard.<br />
<br />
Congrats! You've made it so far!</div>Anstarhttps://artofproblemsolving.com/wiki/index.php?title=Basic_Programming_With_Python&diff=130595Basic Programming With Python2020-08-04T19:59:11Z<p>Anstar: /* Classes */</p>
<hr />
<div>'''Important: It is extremely recommended that you read [[Getting Started With Python Programming]] before reading this unless you already know some programming knowledge.'''<br />
<br />
(Note: This is a really long article. To learn the most from this article, you need to read everything in order and skip nothing, unless you are '''absolutely absolutely sure that that content is way too easy for you.''')<br />
<br />
This article will talk about some basic Python programming. If you don't even know how to install Python, look [[Getting Started With Python Programming|here]].<br />
<br />
Note that this article has lots of program examples. It is recommended (but not required) to try these on your own before looking at the solutions.<br />
<br />
==Loops==<br />
<br />
There are two different kinds of loops in Python: the for loop and the while loop.<br />
<br />
===The For Loop===<br />
<br />
The for loop iterates over a list, or an array, of objects. You have probably seen this code before:<br />
<br />
[[File:Capture.PNG|200px]]<br />
<br />
This for loop iterates over the list of integers from 1 to 51, excluding the 51 and including the 1. That means it is a list from 1 to 50, inclusive. On every iteration, Python will print the number that the loop is iterating through. <br />
<br />
For example, in the first iteration, i = 1, so Python prints 1.<br />
<br />
In the second iteration, i = 2, so Python prints 2.<br />
<br />
This continues so on until the number, 50, is reached. Therefore, the last number Python will print out is 50.<br />
<br />
====Program Example====<br />
<br />
'''Find <math>\sum_{n=1}^{50} 2^{n}.</math>'''<br />
<br />
To do this task, we must create a for loop and loop over the integers from 1 to 50 inclusive:<br />
<br />
for i in range(1,51):<br />
<br />
Now what? We must keep a running total and increase it by <math>2^i</math> every time:<br />
<br />
total = 0<br />
for i in range(1,51):<br />
total += 2**i<br />
<br />
We must not forget to print the total at the end!<br />
<br />
total = 0<br />
for i in range(1,51):<br />
total += 2**i<br />
print(total)<br />
<br />
You must exit out of the for loop one you reach the print(total) line by pressing backspace.<br />
<br />
Once you run your program, you should get an answer of <math>\boxed{2,251,799,813,685,246.}</math><br />
<br />
===The While Loop===<br />
<br />
While loops don't loop over a list. They loop over and over and over...'''until'''...a condition becomes false.<br />
<br />
i = 3<br />
total = 0<br />
while i < 1000:<br />
total += i<br />
i += 3<br />
print(total)<br />
<br />
In this code, the while loop loops 333 times, until <math>i</math> becomes greater than or equal to 1000.<br />
<br />
====Program Example====<br />
<br />
'''Find <math>\sum_{n=1}^{50} 2^n</math> using a while loop.'''<br />
<br />
We must create a while loop that will iterate until n is greater than <math>50.</math><br />
<br />
n = 1<br />
total = 0<br />
while n <= 50:<br />
total += 2**n<br />
n += 1<br />
print(total)<br />
<br />
We must not forget to include the n += 1 line at the end of the while loop! <br />
<br />
If we run this, we will get the same answer as last time, <math>2,251,799,813,685,246.</math><br />
<br />
==Functions==<br />
<br />
In this section, we will define new operations and do arithmetic with them in Python.<br />
<br />
===The New Operation===<br />
Let's say that you defined a new binary operation, the <math>\uparrow \downarrow.</math> You want it to be so <math>a \uparrow \downarrow b = a^{b}b^{a}.</math> Therefore, <math>1\uparrow \downarrow 2 = 1^{2}2^{1}=1\cdot 2= 2,</math> and <math>2\uparrow \downarrow 3 = 2^33^2 = 8\cdot 9 = 72.</math> Let's call this operation an '''up down arrow.'''<br />
<br />
===Program Example 1===<br />
<br />
'''Find <math>[2 \uparrow \downarrow (1 \uparrow \downarrow 2)] \uparrow \downarrow 2.</math>'''<br />
<br />
We know this will be a big number, so we should write a program to do it! We certainly don't want to do the exponentiation and multiplication every time we use the operation in our program, and that's where functions come in! Functions can take in parameters (<math>a</math> and <math>b</math>) and return a result depending on the parameters.<br />
<br />
def up_down_arrow(a,b): <br />
return ((a**b) * (b**a))<br />
<br />
Above is the code to define our function. We need to print the final result at the end, so we must put a print statement at the end.<br />
<br />
def up_down_arrow(a,b): <br />
return ((a**b) * (b**a))<br />
print(up_down_arrow(up_down_arrow(2,up_down_arrow(1,2)),2)<br />
<br />
All those nested up_down_arrow's might be confusing at first, but it really isn't that confusing.<br />
If you run your program, you should get your answer: <math>16,777,216.</math> <br />
<br />
You might be surprised that the answer is so big. If you actually start calculating the real answer without a program, you will really quickly find that the final result is <math>16 \uparrow \downarrow 2,</math> which does turn out to be 16,777,216 if you use a calculator.<br />
<br />
Let's make another operation!<br />
<br />
We will define the operation <math>\uparrow \downarrow \leftarrow \rightarrow</math> to be called '''all around.''' <math>a \uparrow \downarrow \leftarrow \rightarrow b = (ab(a \uparrow \downarrow b))^2.</math> That's an operation that will make really big numbers!<br />
<br />
===Program Example 2===<br />
<br />
'''Find 87 all around 132.'''<br />
<br />
The answer is bound to be a huge number, so we must make a program to solve it.<br />
<br />
We will keep our up_down_arrow function because in the definition of our all_around function we will use it. Then, we will define the all_around function.<br />
<br />
def up_down_arrow(a,b):<br />
return ((a**b) * (b**a))<br />
def all_around(a,b):<br />
return ((a * b * up_down_arrow(a,b)) ** 2)<br />
<br />
We must print all_around(87,132) at the end. Once we do that, and we run our program, we get a super huge number that has over 800 digits!<br />
<br />
===Understanding Functions===<br />
<br />
Every single function has a '''return value'''. If a function does not return anything, the return value is '''null'''. Null is a term used in programming as a placeholder that stands for nothing.<br />
<br />
====Simple Program Example 1====<br />
<br />
'''Define a function that adds 1 to an input.'''<br />
<br />
How will the function know what number to add 1 to? We will input a '''parameter''' for the function to add 1 to.<br />
<br />
def add_one(x):<br />
return x + 1<br />
<br />
In this function, <math>x</math> is the parameter.<br />
<br />
def add_one(x):<br />
return x + 1<br />
print(add_one(2))<br />
<br />
In the print statement, we set <math>x</math> as 2, and the function returns <math>2 + 1 = 3,</math> so the program prints <math>3</math>.<br />
<br />
====Simple Program Example 2====<br />
<br />
'''Define a function that prints out an input.'''<br />
<br />
We will use a parameter again.<br />
<br />
def print_function(x):<br />
print(x)<br />
<br />
Uh oh! We have nothing to return! Therefore, we will return nothing (or null), by just writing return.<br />
<br />
def print_function(x):<br />
print(x)<br />
return<br />
print_function("print_function")<br />
<br />
This code prints out print_function. print_function() is said to be '''called''' in the final line of the code. Again, we set <math>x</math>, our parameter, as "print_function."<br />
== Classes ==<br />
Classes are <br />
<br />
===Defining a class===<br />
===methods===<br />
methods are definition that apply to a class.<br />
===__init__===<br />
===__str__==<br />
==overloading==<br />
overloading means changing a builtin function to do what you want it to do.<br />
<br />
==Flow==<br />
<br />
Flow consists of if statements, elif (else if) statements, and else statements.<br />
<br />
*An if statement checks if a comparison is true.<br />
<br />
*An else statement checks if a comparison is not true. It is used after an if statement (and all elif statements after the if statement) and it shares the same comparison as the if statement.<br />
<br />
*An elif statement checks for two things: if a comparison is true, and if a comparison is not true. It is used right after the if statement.<br />
<br />
===Program Example===<br />
<br />
'''Does the number 10 have the property that when you multiply 10 by 5, you get a two digit number?'''<br />
<br />
This problem is super easy to solve without a program, but let's write a program to solve this anyway. We will use an if statement to check if <math>10\cdot 5</math> is less than 100 and greater than 9.<br />
<br />
if 10*5 > 9:<br />
if 10*5 < 100:<br />
print("Yes")<br />
else:<br />
print("No")<br />
else:<br />
print("No")<br />
<br />
This code means, if 10*5 > 9, then we will check if it is less than 100. If it is not greater than 9, however, we will print No. If it is greater than 9, we check if it is less than 100. If it is, we print Yes. If it isn't we print No.<br />
<br />
These nested if statements can be very confusing. Luckily, there is a faster an easier way to do this.<br />
<br />
if 10*5 > 9 and 10*5 < 100:<br />
print("Yes") <br />
else:<br />
print("No")<br />
<br />
This code checks for the two conditions at the same time. If we run it, we get our answer of Yes.<br />
<br />
==Booleans==<br />
<br />
===Program Example===<br />
<br />
'''Print all two-digit positive integers <math>x</math> such that <math>5x</math> is a two-digit positive integer.'''<br />
<br />
We can create a function with our previous code.<br />
<br />
We will have to slightly modify our function so we can use it in a for loop at the end:<br />
<br />
def check(a):<br />
if a*5 > 9 and a*5 < 100:<br />
return True <br />
else:<br />
return False<br />
<br />
True and False are what are called '''booleans'''. When an if or elif statement receives True, the code inside of the statement happens. When an if or elif statement receives False, the code inside of the statement does not happen. <br />
<br />
We must create a for loop that will iterate through all two digit positive integers. <br />
<br />
def check(a):<br />
if a*5 > 9 and a*5 < 100:<br />
return True <br />
else:<br />
return False<br />
for i in range(10,100):<br />
if check(i):<br />
print(i)<br />
<br />
The final for loop checks if <math>5i</math> is a two digit integer. If it is, the function returns True and the code inside the if statement gets run. If it isn't, the function returns False and the code inside the if statement gets ignored.<br />
<br />
If we run this, we will get the answer.<br />
<br />
All two digit integers from 10 to 19 inclusive work!<br />
<br />
=="Soft Coding" Programs==<br />
<br />
In the next few examples, you will see why hard coding programs is bad. Hard coding programs refers to coding a program that is hard to modify. For example:<br />
<br />
===Program Example 1===<br />
<br />
'''Print all two digit positive integers <math>x</math> such that <math>5x</math> is a three digit positive integer.'''<br />
<br />
We can keep our code and modify some parts of it.<br />
<br />
def check(a, min, max):<br />
if a*5 > min - 1 and a*5 < max + 1:<br />
return True <br />
else:<br />
return False<br />
<br />
def print_check(range_min, range_max, check_min, check_max):<br />
for i in range(range_min, range_max + 1):<br />
if check(i, check_min, check_max):<br />
print(i)<br />
return<br />
<br />
print_check(10, 99, 100, 999)<br />
<br />
Why did we add so many functions?<br />
<br />
Well, if the numbers in a problem change (and the words stay the same), and you need to change a lot of numbers in your program, your program is considered '''hard-coded'''. We want our programs to be as '''soft-coded''' as possible. In our new program, we only need to change 4 numbers (in the print_check() statement) if the numbers in the problem change. Therefore, our program is relatively soft-coded. There are still ways to soft-code this program even more, though.<br />
<br />
If we run our program, we get our answer.<br />
<br />
All numbers from 20 to 99 work!<br />
<br />
===Program Example 2===<br />
<br />
'''Print all three digit positive integers <math>x</math> such that <math>5x</math> is a three digit positive integer.'''<br />
<br />
We can just change the print_check line at the end to<br />
<br />
print_check(100, 999, 100, 999)<br />
<br />
and our program will be ready to be run.<br />
<br />
All numbers from 100 to 199 work.<br />
<br />
===Program Example 3===<br />
<br />
'''Print all two digit positive integers <math>x</math> such that <math>3x</math> is a three digit positive integer.'''<br />
<br />
Uh oh. Only changing the print_check line won't work. We will need to change our functions!<br />
<br />
def check(a, min, max, factor):<br />
if a*factor > min - 1 and a*factor < max + 1:<br />
return True <br />
else:<br />
return False<br />
<br />
def print_check(range_min, range_max, check_min, check_max, check_factor):<br />
for i in range(range_min, range_max + 1):<br />
if check(i, check_min, check_max, check_factor):<br />
print(i)<br />
return<br />
<br />
print_check(10, 99, 100, 999, 3)<br />
<br />
In this step, we added a parameter in both functions. We also soft-coded our program even more! Hooray!<br />
<br />
All integers from 34 to 99 work.<br />
<br />
===Program Example 4===<br />
<br />
'''Print all two digit positive integers <math>x</math> such that <math>12x</math> is a positive integer from 500 to 900.'''<br />
<br />
This problem may look a bit different from the other ones, but it really is the same thing, except that the factor is 12 and check_min and check_max are 500 and 900, respectively.<br />
<br />
Once we change the final print_check() line to satisfy our needs, we can run our program.<br />
<br />
All numbers from 42 to 75 work!<br />
<br />
Congrats! You have written your first programs above 10 lines of code!<br />
<br />
==Random==<br />
<br />
There is a package in Python that allows the use of random numbers.<br />
<br />
===Program Example 1===<br />
<br />
'''Generate a random number from 1 to 6.'''<br />
<br />
Easy peasy. We will just generate a random number from 1 to 6 with the package like this:<br />
<br />
import random<br />
print(random.randint(1,6))<br />
<br />
As you can see, when you run this program, you get a random integer from 1 to 6.<br />
<br />
===Program Example 2===<br />
<br />
'''Simulate the rolling of 1000 dice. Now, count the number of times you roll 6. Print that number out.'''<br />
<br />
We can create a function that returns a random number from 1 to 6. Then, we can make a for loop that rolls the dice 1000 times and check if it is a 6.<br />
<br />
import random<br />
count = 0<br />
<br />
def roll():<br />
return random.randint(1,6)<br />
<br />
for i in range(1, 1001):<br />
if roll() == 6:<br />
count += 1<br />
<br />
print(count)<br />
<br />
If we run this, we will get a number around 170.<br />
<br />
===Program Example 3===<br />
<br />
'''Simulate the rolling of 10,000 dice. Now, count the amount of times you roll 3. Print that amount out.'''<br />
<br />
We can keep our roll function and our code inside the for loop, but we need to change our for loop statement.<br />
<br />
We can actually soft-code our program more. Let's turn the whole for loop into a function!<br />
<br />
import random<br />
<br />
def roll():<br />
return random.randint(1,6)<br />
<br />
def count(amount):<br />
count_ = 0<br />
<br />
for i in range(1, amount+1):<br />
if roll() == 3:<br />
count_ += 1<br />
return count_<br />
<br />
print(count(10000))<br />
<br />
If we run this code, it works.<br />
<br />
===Program Example 4===<br />
<br />
'''One of my friends loves rolling dice. He is going to roll 1 die tomorrow, 2 dice two days from now, 3 dice three days from now, and so on so that he rolls <math>a</math> dice <math>a</math> days from now. He gets tired rolling dice after rolling dice for 365 days (so the last day he rolls 365 dice). In Python, simulate this. How many times does he roll 3 after 365 days of rolling dice?'''<br />
<br />
We can use a for loop that calls a function multiple times.<br />
<br />
import random<br />
<br />
def roll():<br />
return random.randint(1,6)<br />
<br />
def count(amount):<br />
count_ = 0<br />
for i in range(1, amount+1):<br />
if roll() == 3:<br />
count_ += 1<br />
return count_<br />
<br />
total = 0<br />
<br />
for i in range(1, 366):<br />
total += count(i)<br />
<br />
print(total)<br />
<br />
This is a really long program, but the whole program should make sense if you look at it for a while. We defined our count function in the previous example, and now we are using it with a for loop and a running total. <br />
<br />
You should get a number around 11,000 when you run it. Wow, lots of 3's!<br />
<br />
===Program Example 5===<br />
<br />
'''20 of my friends love rolling dice. They are all going to roll 1 die each tomorrow, 2 dice each two days from now, 3 dice each three days from now, and so on so that they roll <math>a</math> dice each <math>a</math> days from now. But, one of my friends gets tired very quickly and he only rolls dice for 1 day and stops. Another friend only will roll dice for 2 days, and another will roll dice for three days only, and so on up to the fact that my last friend will roll dice for 20 days. In Python, simulate this. How many times does someone roll 3 after everything?'''<br />
<br />
We will have to make our for loop into a function again.<br />
<br />
import random<br />
<br />
def roll():<br />
return random.randint(1,6)<br />
<br />
def count(amount):<br />
count_ = 0<br />
for i in range(1, amount+1):<br />
if roll() == 3:<br />
count_ += 1<br />
return count_<br />
<br />
def count2(amount)<br />
total = 0<br />
for i in range(1, amount + 1):<br />
total += count(i)<br />
return total<br />
<br />
def count3(amount)<br />
total = 0<br />
for i in range(1, amount + 1):<br />
total += count2(i)<br />
return total<br />
<br />
print(count3(20))<br />
<br />
(Our program is so long!)<br />
<br />
I also made a new function just in case we needed to turn that into a function later.<br />
<br />
'''Make sure''' you read the code carefully and you fully understand it. If you don't understand every single line of code, then you will get confused later on in this article.<br />
<br />
When you run this program, you might be surprised that the answer isn't so big.<br />
<br />
===Program Example 6===<br />
<br />
'''365 of my friends love rolling dice. They are all going to roll 1 die each tomorrow, 2 dice each two days from now, 3 dice each three days from now, and so on so that they roll <math>a</math> dice each <math>a</math> days from now. But, one of my friends gets tired very quickly and he only rolls dice for 1 day and stops. Another friend only will roll dice for 2 days, and another will roll dice for three days only, and so on up to the fact that my last friend will roll dice for 365 days. In Python, simulate this. How many times does someone roll 3 after everything?'''<br />
<br />
Because we soft-coded our program so much, all we have to do is change the last line so the parameter of count3() is 365.<br />
<br />
If we run it...we get a big answer, as expected. It also takes quite a while!<br />
<br />
You may not have realized that we soft-coded our program at all, but the whole point of functions is to soft-code programs!<br />
<br />
Congrats on writing a program that is around 25 lines long!<br />
<br />
==Very Basic Datatypes==<br />
<br />
An integer is a basic datatype in Python. Basically, all variables with the datatype of '''int''' is an integer.<br />
<br />
A string is another basic datatype, and it is a string of characters enclosed by quotes.<br />
<br />
===Why Are Datatypes So Important?===<br />
<br />
Let's say we wanted to make a program that would add 2 and 3. Some bogus code would be:<br />
<br />
x="2"<br />
y="3"<br />
print(x+y)<br />
<br />
If you ran this code, you would get 23. Why is that?<br />
<br />
Well, here, x and y are strings. When you perform the addition operator to strings in Python, it concatenates the strings, giving 23.<br />
<br />
The real code is:<br />
<br />
x=2<br />
y=3<br />
print(x+y)<br />
<br />
If you run this, you will get <math>5</math>, which is correct.<br />
<br />
Here's another reason datatypes are important. Now, we will introduce the datatype called the '''floating point number''', or '''float'''. A floating-point number is a number with a decimal point.<br />
<br />
Let's go back to the IDLE. Type "0.1*10". The result is 1.0. Notice the decimal point.<br />
<br />
Let's type something different. Type <math>0.1+0.1+0.1+0.1+0.1+0.1+0.1+0.1+0.1+0.1.</math><br />
<br />
'''WHAT!?'''<br />
<br />
You would have expected the answer to be 1, but it isn't 1. What happened?<br />
<br />
'''Float approximation''' happened. Most (almost all) programming languages have a bad float approximation. That means that 1.0 can turn into 0.99999999999999 and 0.5 can turn into 0.49999999999999999993. That only happens with floats, so we should try to use floats as sparingly as possible.<br />
<br />
==Lists==<br />
<br />
A for loop iterates over a '''list'''. A list is a bunch of objects stored in one variable. (Hey! A list is a datatype!) For loops are highly related to lists.<br />
<br />
Let's say we wanted to make a program to print all the items in a list.<br />
<br />
We will first create the list, using the code:<br />
<br />
myList = [1,4,6,8]<br />
<br />
This is a list with four items: 1, 4, 6, and 8.<br />
<br />
We must now print all elements of it with a for loop:<br />
<br />
myList = [1,4,6,8]<br />
for i in myList:<br />
print(i)<br />
<br />
When we run this program, we get the numbers 1, 4, 6, and 8, as expected.<br />
<br />
===Accessing Values===<br />
<br />
Let's say we wanted to print out the second item in a list. We will use '''indexes'''.<br />
<br />
The index of the first item in a list is always 0. The index of the second is 1. The index of the <math>n</math>th is <math>n-1.</math><br />
<br />
To print out the second item, we will use an index of 1, like this:<br />
<br />
myList = [1,4,6,8]<br />
print(myList[1])<br />
<br />
Notice that the index is inside of the square brackets.<br />
<br />
===Adding Values===<br />
<br />
We can use the list.append() function to add an object to the end of a list.<br />
<br />
myList.append(10)<br />
<br />
will add 10 to the list, which makes myList = [1,4,6,8,10].<br />
<br />
===Removing Items From Lists===<br />
<br />
We can use the list.remove() function to remove a specific item in a list.<br />
<br />
For example, consider this code.<br />
<br />
myList = [1,2,3]<br />
myList.remove(3)<br />
<br />
This code will make myList turn into [1,2]. The element, 3, gets removed.<br />
<br />
===len(list)===<br />
<br />
The len(list) function returns the length of a list.<br />
<br />
This code will print 3.<br />
<br />
myList = [1,2,3]<br />
print(len(myList))<br />
<br />
The length of myList is 3, so Python prints 3.<br />
<br />
===All Kinds Of Lists===<br />
<br />
Lists don't have to be only integers!<br />
<br />
myList = [1,"Hi","Hello world", 3.5, 3.14159265358979323]<br />
<br />
If fact, there can be lists inside of lists!<br />
<br />
myList = [[1,2,3], [3,4,5], [5,6,"Hello world"], "BOB", 3.1415926]<br />
<br />
Even this!<br />
<br />
myList = [[1, [1, [1,2,3],3],3], [[[3,["Hello world", 4],5],4,5],4,5], [5,6,7,[1,[1,2,3],3],"Hello world"], "BOB", 3.1415926, True]<br />
<br />
If you look at that list carefully, you will find lists inside of lists inside of lists inside of lists! And, a boolean at the end!<br />
<br />
Like variables, you can have as many lists in a program as you want (a list is a variable)!<br />
<br />
myList = [1,2,3,4]<br />
yourList = [5,6,7,8]<br />
hisList = [9,10,11,12]<br />
herList = [13,14,15,16]<br />
theirList = [17,18,19,20]<br />
ourList = [21,22,23,24]<br />
listsOfLists = [[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16],[17,18,19,20],[21,22,23,24]]<br />
<br />
===Splitting Lists===<br />
Split Operator Basics:<br />
genericList[where to start:where to end:what size steps to take]<br />
The value where to start is inclusive, and denotes the index where your split list begins. It has a default value of 0.<br />
The value where to end is exclusive, and denotes the index where your split list ends. It has a default value of len(genericList).<br />
The value what size steps denotes the size of the steps your split takes(more on that later). It has a default value of 1.<br />
Say you want to split a list and only return certain indices, for example if you wanted to split a list called data and put the first two elements into a list called head and the last two into a list called tail, you would split like this:<br />
data = [1, 3, 4, 23.5, 40, 55]<br />
head = data[:2]<br />
tail = data[-2:] # negative list indices represent the end of a list, so -1 is the last element and -2 is the second-to-last<br />
Step Size:<br />
We will practice writing a few functions that select every other element and will reverse in a list using step size.<br />
A step size of two means skip every other list index, so we can write our first function.<br />
def selectEveryOtherElement(list):<br />
return list[::2]<br />
But which step size will get us our desired reversed list. We could start at the end of the list and iterate backwards, but how would we do that...<br />
Negative Step Size:<br />
A step size that is negative means skip a certain amount of elements, but backwards. If we were to start at 0, with a step size of -1, we would be able to iterate backwards over the list!<br />
def reverse(list):<br />
return list[::-1]<br />
Splitting lists with ratios:<br />
What if we wanted to be able to split a list based upon a ratio. For example, the common 80:20 train to test ratio in machine learning? Here is how you would do it<br />
def eighty-twenty(list):<br />
train = list[:int(len(list) * (4 / 5))] # We must include the int() method to convert to an integer if len(list) % 5 != 0<br />
test = list[int(len(list) * 4 / 5)]<br />
return [train, test] # We then return a list with the train and test lists inside<br />
<br />
==Dictionaries==<br />
<br />
A dictionary (a type of datatype) is a bunch of keys and values. There is a major difference between dictionaries and lists. Lists are ordered; dictionaries are not.<br />
<br />
Here is the '''syntax''' of creating a dictionary:<br />
<br />
myDictionary = {1:"one",2:"two"}<br />
<br />
This dictionary has two key/value pairs. Notice it is surrounded in curly braces. The keys are 1 and 2; the values are "one" and "two."<br />
<br />
How is this useful? Let's make a simple program to test it out.<br />
<br />
myDictionary = {1:"one",2:"two"}<br />
print(myDictionary[1])<br />
print(myDictionary[2])<br />
<br />
===Accessing Values===<br />
<br />
To access a value in a dictionary, you put in the key.<br />
<br />
myDictionary[1]<br />
<br />
returns one, because 1 is the key to "one."<br />
<br />
===Adding New Values===<br />
<br />
To overwrite a value, we do this.<br />
<br />
myDictionary[1] = "won"<br />
<br />
The value to the key 1 is now "won."<br />
<br />
To add a value, we do the same thing!<br />
<br />
myDictionary[3] = "three"<br />
<br />
This adds a key 3 with a value of "three."<br />
<br />
==Misc Concepts==<br />
<br />
This section will talk about some concepts that we haven't learned yet.<br />
<br />
====Concatenating Strings====<br />
<br />
Concatenating strings is putting them together. For example, "one" concatenated with "two" gives "onetwo."<br />
<br />
The following string,<br />
<br />
"Hello, " + person2 + "! How are you?"<br />
<br />
depends on what person2 was. If person2 was Bob, the string would be:<br />
<br />
"Hello, Bob! How are you?"<br />
<br />
It fits together perfectly!<br />
<br />
You cannot concatenate strings with integers. For example, doing this:<br />
<br />
"2" + 3<br />
<br />
will not work. Instead, to get an answer of "23", you must do this:<br />
<br />
"2" + str(3)<br />
<br />
That turns 3 into a string so it is "3", and the result will be "23".<br />
<br />
====Line Breaks====<br />
<br />
We can use multiple line breaks to make our code more organized. There are some places that you cannot line break. For example, this code will produce an error:<br />
<br />
myList =<br />
[1,2,3]<br />
<br />
This code does not work.<br />
<br />
This code '''does work''':<br />
<br />
myList = [<br />
1,2,3]<br />
<br />
It is accepted when you break a line right after the [. It is also accepted right after a comma. (And right before the ending ].)<br />
<br />
myList = [<br />
1,<br />
2,<br />
3<br />
]<br />
<br />
==Challenge Program==<br />
<br />
In this section, we will attempt the hardest program so far in this article.<br />
<br />
'''Make a conversation generator that will generate random conversations between different people.'''<br />
<br />
First, we will generate the people. We can use a list and generate two random numbers.<br />
<br />
import random<br />
<br />
peopleNames = [<br />
"Bob",<br />
"Kyle",<br />
"James",<br />
"Richard",<br />
"Zachary",<br />
"Olivia",<br />
"Jonathan",<br />
"Will",<br />
"Bobby",<br />
"Kevin"<br />
]<br />
person1 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
peopleNames.remove(person1)<br />
person2 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
<br />
(I made it more organized by separating the long lines of code into multiple lines. It only works when you have a line break right after each item in the list.)<br />
<br />
Here, we use the remove() function to remove person1 from the list to make sure we don't use the same name twice. <br />
<br />
We also used the len() function to find the length of the list (soft-coding!)<br />
<br />
Now, we need to create a list of possible values for the first thing that person1 says (person1 will always be the first one to talk). <br />
<br />
Then, we will print it out.<br />
<br />
import random<br />
<br />
peopleNames = [<br />
"Bob",<br />
"Kyle",<br />
"James",<br />
"Richard",<br />
"Zachary",<br />
"Olivia",<br />
"Jonathan",<br />
"Will",<br />
"Bobby",<br />
"Kevin"<br />
]<br />
person1 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
peopleNames.remove(person1)<br />
person2 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
<br />
first = [<br />
"Hi!",<br />
"Hello!",<br />
"Good morning!",<br />
"Hello, " + person2 + "!",<br />
"Hi.",<br />
"Hi, " + person2 + "!"<br />
]<br />
print(person1 + ": " + first[random.randint(0, (len(first) - 1))])<br />
<br />
If we test out this program, we can confirm that this part indeed does work. This program is already getting long! Now, we will use the same method and create the second message.<br />
<br />
import random<br />
<br />
peopleNames = [<br />
"Bob",<br />
"Kyle",<br />
"James",<br />
"Richard",<br />
"Zachary",<br />
"Olivia",<br />
"Jonathan",<br />
"Will",<br />
"Bobby",<br />
"Kevin"<br />
]<br />
person1 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
peopleNames.remove(person1)<br />
person2 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
<br />
first = [<br />
"Hi!",<br />
"Hello!",<br />
"Good morning!",<br />
"Hello, " + person2 + "!",<br />
"Hi.",<br />
"Hi, " + person2 + "!"<br />
]<br />
print(person1 + ": " + first[random.randint(0, (len(first) - 1))])<br />
<br />
second = [<br />
"Hi! How are you today?",<br />
"Hello! How are you?",<br />
"Good morning! How are you today?",<br />
"Hello, " + person1 + "! How are you?",<br />
"Hi. How are you?",<br />
"Hi, " + person1 + "! How are you today?"<br />
]<br />
print(person2 + ": " + second[random.randint(0, (len(second) - 1))])<br />
<br />
We will repeat this for the rest of the conversation:<br />
<br />
import random<br />
<br />
peopleNames = [<br />
"Bob",<br />
"Kyle",<br />
"James",<br />
"Richard",<br />
"Zachary",<br />
"Olivia",<br />
"Jonathan",<br />
"Will", <br />
"Bobby",<br />
"Kevin"<br />
]<br />
person1 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
peopleNames.remove(person1)<br />
person2 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
<br />
first = [<br />
"Hi!",<br />
"Hello!",<br />
"Good morning!",<br />
"Hello, " + person2 + "!",<br />
"Hi.",<br />
"Hi, " + person2 + "!"<br />
]<br />
print(person1 + ": " + first[random.randint(0, (len(first) - 1))])<br />
<br />
second = [<br />
"Hi! How are you today?",<br />
"Hello! How are you?",<br />
"Good morning! How are you today?",<br />
"Hello, " + person1 + "! How are you?",<br />
"Hi. How are you?",<br />
"Hi, " + person1 + "! How are you today?"<br />
]<br />
print(person2 + ": " + second[random.randint(0, (len(second) - 1))])<br />
<br />
third = [<br />
"I'm feeling awesome! And you?",<br />
"I'm feeling alright! How are you?",<br />
"I'm good, thank you. How are you feeling?",<br />
"I'm fine!" ,<br />
"How are you today?"<br />
]<br />
print(person1 + ": " + third[random.randint(0, (len(third) - 1))])<br />
<br />
fourth = [<br />
"I'm feeling great!",<br />
"I'm awesome!",<br />
"Thanks for asking! I am feeling good today!",<br />
"I'm feeling awesome today! Yippee!"<br />
] <br />
print(person2 + ": " + fourth[random.randint(0, (len(fourth) - 1))])<br />
<br />
fifth = [<br />
"It's so nice out today!",<br />
"Today is such a cloudy day.",<br />
"I hate it when it is so cloudy outside!",<br />
"It's partly cloudy today!"<br />
]<br />
print(person1 + ": " + fifth[random.randint(0, (len(fifth) - 1))])<br />
<br />
sixth = [<br />
"I know, right?",<br />
"I know.",<br />
"Yeah!",<br />
"True."<br />
]<br />
print(person2 + ": " + sixth[random.randint(0, (len(sixth) - 1))])<br />
<br />
seventh = [<br />
"Sorry, I need to leave. Bye!",<br />
"I gotta go. Bye!",<br />
"Sorry, I don't have time to stay and chat. I've got to go somewhere. Bye!"<br />
]<br />
print(person1 + ": " + seventh[random.randint(0, (len(seventh) - 1))])<br />
<br />
eighth = [<br />
"Bye!",<br />
"Good-bye!",<br />
"Bye, " + person1 + "."<br />
]<br />
print(person2 + ": " + eighth[random.randint(0, (len(eighth) - 1))])<br />
<br />
Whew! So long!<br />
<br />
Once we run our program. It works! This program really wasn't that hard.<br />
<br />
Congrats! You've made it so far!</div>Anstarhttps://artofproblemsolving.com/wiki/index.php?title=Basic_Programming_With_Python&diff=130594Basic Programming With Python2020-08-04T19:50:27Z<p>Anstar: /* methords */ spell check</p>
<hr />
<div>'''Important: It is extremely recommended that you read [[Getting Started With Python Programming]] before reading this unless you already know some programming knowledge.'''<br />
<br />
(Note: This is a really long article. To learn the most from this article, you need to read everything in order and skip nothing, unless you are '''absolutely absolutely sure that that content is way too easy for you.''')<br />
<br />
This article will talk about some basic Python programming. If you don't even know how to install Python, look [[Getting Started With Python Programming|here]].<br />
<br />
Note that this article has lots of program examples. It is recommended (but not required) to try these on your own before looking at the solutions.<br />
<br />
==Loops==<br />
<br />
There are two different kinds of loops in Python: the for loop and the while loop.<br />
<br />
===The For Loop===<br />
<br />
The for loop iterates over a list, or an array, of objects. You have probably seen this code before:<br />
<br />
[[File:Capture.PNG|200px]]<br />
<br />
This for loop iterates over the list of integers from 1 to 51, excluding the 51 and including the 1. That means it is a list from 1 to 50, inclusive. On every iteration, Python will print the number that the loop is iterating through. <br />
<br />
For example, in the first iteration, i = 1, so Python prints 1.<br />
<br />
In the second iteration, i = 2, so Python prints 2.<br />
<br />
This continues so on until the number, 50, is reached. Therefore, the last number Python will print out is 50.<br />
<br />
====Program Example====<br />
<br />
'''Find <math>\sum_{n=1}^{50} 2^{n}.</math>'''<br />
<br />
To do this task, we must create a for loop and loop over the integers from 1 to 50 inclusive:<br />
<br />
for i in range(1,51):<br />
<br />
Now what? We must keep a running total and increase it by <math>2^i</math> every time:<br />
<br />
total = 0<br />
for i in range(1,51):<br />
total += 2**i<br />
<br />
We must not forget to print the total at the end!<br />
<br />
total = 0<br />
for i in range(1,51):<br />
total += 2**i<br />
print(total)<br />
<br />
You must exit out of the for loop one you reach the print(total) line by pressing backspace.<br />
<br />
Once you run your program, you should get an answer of <math>\boxed{2,251,799,813,685,246.}</math><br />
<br />
===The While Loop===<br />
<br />
While loops don't loop over a list. They loop over and over and over...'''until'''...a condition becomes false.<br />
<br />
i = 3<br />
total = 0<br />
while i < 1000:<br />
total += i<br />
i += 3<br />
print(total)<br />
<br />
In this code, the while loop loops 333 times, until <math>i</math> becomes greater than or equal to 1000.<br />
<br />
====Program Example====<br />
<br />
'''Find <math>\sum_{n=1}^{50} 2^n</math> using a while loop.'''<br />
<br />
We must create a while loop that will iterate until n is greater than <math>50.</math><br />
<br />
n = 1<br />
total = 0<br />
while n <= 50:<br />
total += 2**n<br />
n += 1<br />
print(total)<br />
<br />
We must not forget to include the n += 1 line at the end of the while loop! <br />
<br />
If we run this, we will get the same answer as last time, <math>2,251,799,813,685,246.</math><br />
<br />
==Functions==<br />
<br />
In this section, we will define new operations and do arithmetic with them in Python.<br />
<br />
===The New Operation===<br />
Let's say that you defined a new binary operation, the <math>\uparrow \downarrow.</math> You want it to be so <math>a \uparrow \downarrow b = a^{b}b^{a}.</math> Therefore, <math>1\uparrow \downarrow 2 = 1^{2}2^{1}=1\cdot 2= 2,</math> and <math>2\uparrow \downarrow 3 = 2^33^2 = 8\cdot 9 = 72.</math> Let's call this operation an '''up down arrow.'''<br />
<br />
===Program Example 1===<br />
<br />
'''Find <math>[2 \uparrow \downarrow (1 \uparrow \downarrow 2)] \uparrow \downarrow 2.</math>'''<br />
<br />
We know this will be a big number, so we should write a program to do it! We certainly don't want to do the exponentiation and multiplication every time we use the operation in our program, and that's where functions come in! Functions can take in parameters (<math>a</math> and <math>b</math>) and return a result depending on the parameters.<br />
<br />
def up_down_arrow(a,b): <br />
return ((a**b) * (b**a))<br />
<br />
Above is the code to define our function. We need to print the final result at the end, so we must put a print statement at the end.<br />
<br />
def up_down_arrow(a,b): <br />
return ((a**b) * (b**a))<br />
print(up_down_arrow(up_down_arrow(2,up_down_arrow(1,2)),2)<br />
<br />
All those nested up_down_arrow's might be confusing at first, but it really isn't that confusing.<br />
If you run your program, you should get your answer: <math>16,777,216.</math> <br />
<br />
You might be surprised that the answer is so big. If you actually start calculating the real answer without a program, you will really quickly find that the final result is <math>16 \uparrow \downarrow 2,</math> which does turn out to be 16,777,216 if you use a calculator.<br />
<br />
Let's make another operation!<br />
<br />
We will define the operation <math>\uparrow \downarrow \leftarrow \rightarrow</math> to be called '''all around.''' <math>a \uparrow \downarrow \leftarrow \rightarrow b = (ab(a \uparrow \downarrow b))^2.</math> That's an operation that will make really big numbers!<br />
<br />
===Program Example 2===<br />
<br />
'''Find 87 all around 132.'''<br />
<br />
The answer is bound to be a huge number, so we must make a program to solve it.<br />
<br />
We will keep our up_down_arrow function because in the definition of our all_around function we will use it. Then, we will define the all_around function.<br />
<br />
def up_down_arrow(a,b):<br />
return ((a**b) * (b**a))<br />
def all_around(a,b):<br />
return ((a * b * up_down_arrow(a,b)) ** 2)<br />
<br />
We must print all_around(87,132) at the end. Once we do that, and we run our program, we get a super huge number that has over 800 digits!<br />
<br />
===Understanding Functions===<br />
<br />
Every single function has a '''return value'''. If a function does not return anything, the return value is '''null'''. Null is a term used in programming as a placeholder that stands for nothing.<br />
<br />
====Simple Program Example 1====<br />
<br />
'''Define a function that adds 1 to an input.'''<br />
<br />
How will the function know what number to add 1 to? We will input a '''parameter''' for the function to add 1 to.<br />
<br />
def add_one(x):<br />
return x + 1<br />
<br />
In this function, <math>x</math> is the parameter.<br />
<br />
def add_one(x):<br />
return x + 1<br />
print(add_one(2))<br />
<br />
In the print statement, we set <math>x</math> as 2, and the function returns <math>2 + 1 = 3,</math> so the program prints <math>3</math>.<br />
<br />
====Simple Program Example 2====<br />
<br />
'''Define a function that prints out an input.'''<br />
<br />
We will use a parameter again.<br />
<br />
def print_function(x):<br />
print(x)<br />
<br />
Uh oh! We have nothing to return! Therefore, we will return nothing (or null), by just writing return.<br />
<br />
def print_function(x):<br />
print(x)<br />
return<br />
print_function("print_function")<br />
<br />
This code prints out print_function. print_function() is said to be '''called''' in the final line of the code. Again, we set <math>x</math>, our parameter, as "print_function."<br />
== Classes ==<br />
Classes are <br />
<br />
===Defining a class===<br />
<br />
===init===<br />
===methods===<br />
<br />
==Flow==<br />
<br />
Flow consists of if statements, elif (else if) statements, and else statements.<br />
<br />
*An if statement checks if a comparison is true.<br />
<br />
*An else statement checks if a comparison is not true. It is used after an if statement (and all elif statements after the if statement) and it shares the same comparison as the if statement.<br />
<br />
*An elif statement checks for two things: if a comparison is true, and if a comparison is not true. It is used right after the if statement.<br />
<br />
===Program Example===<br />
<br />
'''Does the number 10 have the property that when you multiply 10 by 5, you get a two digit number?'''<br />
<br />
This problem is super easy to solve without a program, but let's write a program to solve this anyway. We will use an if statement to check if <math>10\cdot 5</math> is less than 100 and greater than 9.<br />
<br />
if 10*5 > 9:<br />
if 10*5 < 100:<br />
print("Yes")<br />
else:<br />
print("No")<br />
else:<br />
print("No")<br />
<br />
This code means, if 10*5 > 9, then we will check if it is less than 100. If it is not greater than 9, however, we will print No. If it is greater than 9, we check if it is less than 100. If it is, we print Yes. If it isn't we print No.<br />
<br />
These nested if statements can be very confusing. Luckily, there is a faster an easier way to do this.<br />
<br />
if 10*5 > 9 and 10*5 < 100:<br />
print("Yes") <br />
else:<br />
print("No")<br />
<br />
This code checks for the two conditions at the same time. If we run it, we get our answer of Yes.<br />
<br />
==Booleans==<br />
<br />
===Program Example===<br />
<br />
'''Print all two-digit positive integers <math>x</math> such that <math>5x</math> is a two-digit positive integer.'''<br />
<br />
We can create a function with our previous code.<br />
<br />
We will have to slightly modify our function so we can use it in a for loop at the end:<br />
<br />
def check(a):<br />
if a*5 > 9 and a*5 < 100:<br />
return True <br />
else:<br />
return False<br />
<br />
True and False are what are called '''booleans'''. When an if or elif statement receives True, the code inside of the statement happens. When an if or elif statement receives False, the code inside of the statement does not happen. <br />
<br />
We must create a for loop that will iterate through all two digit positive integers. <br />
<br />
def check(a):<br />
if a*5 > 9 and a*5 < 100:<br />
return True <br />
else:<br />
return False<br />
for i in range(10,100):<br />
if check(i):<br />
print(i)<br />
<br />
The final for loop checks if <math>5i</math> is a two digit integer. If it is, the function returns True and the code inside the if statement gets run. If it isn't, the function returns False and the code inside the if statement gets ignored.<br />
<br />
If we run this, we will get the answer.<br />
<br />
All two digit integers from 10 to 19 inclusive work!<br />
<br />
=="Soft Coding" Programs==<br />
<br />
In the next few examples, you will see why hard coding programs is bad. Hard coding programs refers to coding a program that is hard to modify. For example:<br />
<br />
===Program Example 1===<br />
<br />
'''Print all two digit positive integers <math>x</math> such that <math>5x</math> is a three digit positive integer.'''<br />
<br />
We can keep our code and modify some parts of it.<br />
<br />
def check(a, min, max):<br />
if a*5 > min - 1 and a*5 < max + 1:<br />
return True <br />
else:<br />
return False<br />
<br />
def print_check(range_min, range_max, check_min, check_max):<br />
for i in range(range_min, range_max + 1):<br />
if check(i, check_min, check_max):<br />
print(i)<br />
return<br />
<br />
print_check(10, 99, 100, 999)<br />
<br />
Why did we add so many functions?<br />
<br />
Well, if the numbers in a problem change (and the words stay the same), and you need to change a lot of numbers in your program, your program is considered '''hard-coded'''. We want our programs to be as '''soft-coded''' as possible. In our new program, we only need to change 4 numbers (in the print_check() statement) if the numbers in the problem change. Therefore, our program is relatively soft-coded. There are still ways to soft-code this program even more, though.<br />
<br />
If we run our program, we get our answer.<br />
<br />
All numbers from 20 to 99 work!<br />
<br />
===Program Example 2===<br />
<br />
'''Print all three digit positive integers <math>x</math> such that <math>5x</math> is a three digit positive integer.'''<br />
<br />
We can just change the print_check line at the end to<br />
<br />
print_check(100, 999, 100, 999)<br />
<br />
and our program will be ready to be run.<br />
<br />
All numbers from 100 to 199 work.<br />
<br />
===Program Example 3===<br />
<br />
'''Print all two digit positive integers <math>x</math> such that <math>3x</math> is a three digit positive integer.'''<br />
<br />
Uh oh. Only changing the print_check line won't work. We will need to change our functions!<br />
<br />
def check(a, min, max, factor):<br />
if a*factor > min - 1 and a*factor < max + 1:<br />
return True <br />
else:<br />
return False<br />
<br />
def print_check(range_min, range_max, check_min, check_max, check_factor):<br />
for i in range(range_min, range_max + 1):<br />
if check(i, check_min, check_max, check_factor):<br />
print(i)<br />
return<br />
<br />
print_check(10, 99, 100, 999, 3)<br />
<br />
In this step, we added a parameter in both functions. We also soft-coded our program even more! Hooray!<br />
<br />
All integers from 34 to 99 work.<br />
<br />
===Program Example 4===<br />
<br />
'''Print all two digit positive integers <math>x</math> such that <math>12x</math> is a positive integer from 500 to 900.'''<br />
<br />
This problem may look a bit different from the other ones, but it really is the same thing, except that the factor is 12 and check_min and check_max are 500 and 900, respectively.<br />
<br />
Once we change the final print_check() line to satisfy our needs, we can run our program.<br />
<br />
All numbers from 42 to 75 work!<br />
<br />
Congrats! You have written your first programs above 10 lines of code!<br />
<br />
==Random==<br />
<br />
There is a package in Python that allows the use of random numbers.<br />
<br />
===Program Example 1===<br />
<br />
'''Generate a random number from 1 to 6.'''<br />
<br />
Easy peasy. We will just generate a random number from 1 to 6 with the package like this:<br />
<br />
import random<br />
print(random.randint(1,6))<br />
<br />
As you can see, when you run this program, you get a random integer from 1 to 6.<br />
<br />
===Program Example 2===<br />
<br />
'''Simulate the rolling of 1000 dice. Now, count the number of times you roll 6. Print that number out.'''<br />
<br />
We can create a function that returns a random number from 1 to 6. Then, we can make a for loop that rolls the dice 1000 times and check if it is a 6.<br />
<br />
import random<br />
count = 0<br />
<br />
def roll():<br />
return random.randint(1,6)<br />
<br />
for i in range(1, 1001):<br />
if roll() == 6:<br />
count += 1<br />
<br />
print(count)<br />
<br />
If we run this, we will get a number around 170.<br />
<br />
===Program Example 3===<br />
<br />
'''Simulate the rolling of 10,000 dice. Now, count the amount of times you roll 3. Print that amount out.'''<br />
<br />
We can keep our roll function and our code inside the for loop, but we need to change our for loop statement.<br />
<br />
We can actually soft-code our program more. Let's turn the whole for loop into a function!<br />
<br />
import random<br />
<br />
def roll():<br />
return random.randint(1,6)<br />
<br />
def count(amount):<br />
count_ = 0<br />
<br />
for i in range(1, amount+1):<br />
if roll() == 3:<br />
count_ += 1<br />
return count_<br />
<br />
print(count(10000))<br />
<br />
If we run this code, it works.<br />
<br />
===Program Example 4===<br />
<br />
'''One of my friends loves rolling dice. He is going to roll 1 die tomorrow, 2 dice two days from now, 3 dice three days from now, and so on so that he rolls <math>a</math> dice <math>a</math> days from now. He gets tired rolling dice after rolling dice for 365 days (so the last day he rolls 365 dice). In Python, simulate this. How many times does he roll 3 after 365 days of rolling dice?'''<br />
<br />
We can use a for loop that calls a function multiple times.<br />
<br />
import random<br />
<br />
def roll():<br />
return random.randint(1,6)<br />
<br />
def count(amount):<br />
count_ = 0<br />
for i in range(1, amount+1):<br />
if roll() == 3:<br />
count_ += 1<br />
return count_<br />
<br />
total = 0<br />
<br />
for i in range(1, 366):<br />
total += count(i)<br />
<br />
print(total)<br />
<br />
This is a really long program, but the whole program should make sense if you look at it for a while. We defined our count function in the previous example, and now we are using it with a for loop and a running total. <br />
<br />
You should get a number around 11,000 when you run it. Wow, lots of 3's!<br />
<br />
===Program Example 5===<br />
<br />
'''20 of my friends love rolling dice. They are all going to roll 1 die each tomorrow, 2 dice each two days from now, 3 dice each three days from now, and so on so that they roll <math>a</math> dice each <math>a</math> days from now. But, one of my friends gets tired very quickly and he only rolls dice for 1 day and stops. Another friend only will roll dice for 2 days, and another will roll dice for three days only, and so on up to the fact that my last friend will roll dice for 20 days. In Python, simulate this. How many times does someone roll 3 after everything?'''<br />
<br />
We will have to make our for loop into a function again.<br />
<br />
import random<br />
<br />
def roll():<br />
return random.randint(1,6)<br />
<br />
def count(amount):<br />
count_ = 0<br />
for i in range(1, amount+1):<br />
if roll() == 3:<br />
count_ += 1<br />
return count_<br />
<br />
def count2(amount)<br />
total = 0<br />
for i in range(1, amount + 1):<br />
total += count(i)<br />
return total<br />
<br />
def count3(amount)<br />
total = 0<br />
for i in range(1, amount + 1):<br />
total += count2(i)<br />
return total<br />
<br />
print(count3(20))<br />
<br />
(Our program is so long!)<br />
<br />
I also made a new function just in case we needed to turn that into a function later.<br />
<br />
'''Make sure''' you read the code carefully and you fully understand it. If you don't understand every single line of code, then you will get confused later on in this article.<br />
<br />
When you run this program, you might be surprised that the answer isn't so big.<br />
<br />
===Program Example 6===<br />
<br />
'''365 of my friends love rolling dice. They are all going to roll 1 die each tomorrow, 2 dice each two days from now, 3 dice each three days from now, and so on so that they roll <math>a</math> dice each <math>a</math> days from now. But, one of my friends gets tired very quickly and he only rolls dice for 1 day and stops. Another friend only will roll dice for 2 days, and another will roll dice for three days only, and so on up to the fact that my last friend will roll dice for 365 days. In Python, simulate this. How many times does someone roll 3 after everything?'''<br />
<br />
Because we soft-coded our program so much, all we have to do is change the last line so the parameter of count3() is 365.<br />
<br />
If we run it...we get a big answer, as expected. It also takes quite a while!<br />
<br />
You may not have realized that we soft-coded our program at all, but the whole point of functions is to soft-code programs!<br />
<br />
Congrats on writing a program that is around 25 lines long!<br />
<br />
==Very Basic Datatypes==<br />
<br />
An integer is a basic datatype in Python. Basically, all variables with the datatype of '''int''' is an integer.<br />
<br />
A string is another basic datatype, and it is a string of characters enclosed by quotes.<br />
<br />
===Why Are Datatypes So Important?===<br />
<br />
Let's say we wanted to make a program that would add 2 and 3. Some bogus code would be:<br />
<br />
x="2"<br />
y="3"<br />
print(x+y)<br />
<br />
If you ran this code, you would get 23. Why is that?<br />
<br />
Well, here, x and y are strings. When you perform the addition operator to strings in Python, it concatenates the strings, giving 23.<br />
<br />
The real code is:<br />
<br />
x=2<br />
y=3<br />
print(x+y)<br />
<br />
If you run this, you will get <math>5</math>, which is correct.<br />
<br />
Here's another reason datatypes are important. Now, we will introduce the datatype called the '''floating point number''', or '''float'''. A floating-point number is a number with a decimal point.<br />
<br />
Let's go back to the IDLE. Type "0.1*10". The result is 1.0. Notice the decimal point.<br />
<br />
Let's type something different. Type <math>0.1+0.1+0.1+0.1+0.1+0.1+0.1+0.1+0.1+0.1.</math><br />
<br />
'''WHAT!?'''<br />
<br />
You would have expected the answer to be 1, but it isn't 1. What happened?<br />
<br />
'''Float approximation''' happened. Most (almost all) programming languages have a bad float approximation. That means that 1.0 can turn into 0.99999999999999 and 0.5 can turn into 0.49999999999999999993. That only happens with floats, so we should try to use floats as sparingly as possible.<br />
<br />
==Lists==<br />
<br />
A for loop iterates over a '''list'''. A list is a bunch of objects stored in one variable. (Hey! A list is a datatype!) For loops are highly related to lists.<br />
<br />
Let's say we wanted to make a program to print all the items in a list.<br />
<br />
We will first create the list, using the code:<br />
<br />
myList = [1,4,6,8]<br />
<br />
This is a list with four items: 1, 4, 6, and 8.<br />
<br />
We must now print all elements of it with a for loop:<br />
<br />
myList = [1,4,6,8]<br />
for i in myList:<br />
print(i)<br />
<br />
When we run this program, we get the numbers 1, 4, 6, and 8, as expected.<br />
<br />
===Accessing Values===<br />
<br />
Let's say we wanted to print out the second item in a list. We will use '''indexes'''.<br />
<br />
The index of the first item in a list is always 0. The index of the second is 1. The index of the <math>n</math>th is <math>n-1.</math><br />
<br />
To print out the second item, we will use an index of 1, like this:<br />
<br />
myList = [1,4,6,8]<br />
print(myList[1])<br />
<br />
Notice that the index is inside of the square brackets.<br />
<br />
===Adding Values===<br />
<br />
We can use the list.append() function to add an object to the end of a list.<br />
<br />
myList.append(10)<br />
<br />
will add 10 to the list, which makes myList = [1,4,6,8,10].<br />
<br />
===Removing Items From Lists===<br />
<br />
We can use the list.remove() function to remove a specific item in a list.<br />
<br />
For example, consider this code.<br />
<br />
myList = [1,2,3]<br />
myList.remove(3)<br />
<br />
This code will make myList turn into [1,2]. The element, 3, gets removed.<br />
<br />
===len(list)===<br />
<br />
The len(list) function returns the length of a list.<br />
<br />
This code will print 3.<br />
<br />
myList = [1,2,3]<br />
print(len(myList))<br />
<br />
The length of myList is 3, so Python prints 3.<br />
<br />
===All Kinds Of Lists===<br />
<br />
Lists don't have to be only integers!<br />
<br />
myList = [1,"Hi","Hello world", 3.5, 3.14159265358979323]<br />
<br />
If fact, there can be lists inside of lists!<br />
<br />
myList = [[1,2,3], [3,4,5], [5,6,"Hello world"], "BOB", 3.1415926]<br />
<br />
Even this!<br />
<br />
myList = [[1, [1, [1,2,3],3],3], [[[3,["Hello world", 4],5],4,5],4,5], [5,6,7,[1,[1,2,3],3],"Hello world"], "BOB", 3.1415926, True]<br />
<br />
If you look at that list carefully, you will find lists inside of lists inside of lists inside of lists! And, a boolean at the end!<br />
<br />
Like variables, you can have as many lists in a program as you want (a list is a variable)!<br />
<br />
myList = [1,2,3,4]<br />
yourList = [5,6,7,8]<br />
hisList = [9,10,11,12]<br />
herList = [13,14,15,16]<br />
theirList = [17,18,19,20]<br />
ourList = [21,22,23,24]<br />
listsOfLists = [[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16],[17,18,19,20],[21,22,23,24]]<br />
<br />
===Splitting Lists===<br />
Split Operator Basics:<br />
genericList[where to start:where to end:what size steps to take]<br />
The value where to start is inclusive, and denotes the index where your split list begins. It has a default value of 0.<br />
The value where to end is exclusive, and denotes the index where your split list ends. It has a default value of len(genericList).<br />
The value what size steps denotes the size of the steps your split takes(more on that later). It has a default value of 1.<br />
Say you want to split a list and only return certain indices, for example if you wanted to split a list called data and put the first two elements into a list called head and the last two into a list called tail, you would split like this:<br />
data = [1, 3, 4, 23.5, 40, 55]<br />
head = data[:2]<br />
tail = data[-2:] # negative list indices represent the end of a list, so -1 is the last element and -2 is the second-to-last<br />
Step Size:<br />
We will practice writing a few functions that select every other element and will reverse in a list using step size.<br />
A step size of two means skip every other list index, so we can write our first function.<br />
def selectEveryOtherElement(list):<br />
return list[::2]<br />
But which step size will get us our desired reversed list. We could start at the end of the list and iterate backwards, but how would we do that...<br />
Negative Step Size:<br />
A step size that is negative means skip a certain amount of elements, but backwards. If we were to start at 0, with a step size of -1, we would be able to iterate backwards over the list!<br />
def reverse(list):<br />
return list[::-1]<br />
Splitting lists with ratios:<br />
What if we wanted to be able to split a list based upon a ratio. For example, the common 80:20 train to test ratio in machine learning? Here is how you would do it<br />
def eighty-twenty(list):<br />
train = list[:int(len(list) * (4 / 5))] # We must include the int() method to convert to an integer if len(list) % 5 != 0<br />
test = list[int(len(list) * 4 / 5)]<br />
return [train, test] # We then return a list with the train and test lists inside<br />
<br />
==Dictionaries==<br />
<br />
A dictionary (a type of datatype) is a bunch of keys and values. There is a major difference between dictionaries and lists. Lists are ordered; dictionaries are not.<br />
<br />
Here is the '''syntax''' of creating a dictionary:<br />
<br />
myDictionary = {1:"one",2:"two"}<br />
<br />
This dictionary has two key/value pairs. Notice it is surrounded in curly braces. The keys are 1 and 2; the values are "one" and "two."<br />
<br />
How is this useful? Let's make a simple program to test it out.<br />
<br />
myDictionary = {1:"one",2:"two"}<br />
print(myDictionary[1])<br />
print(myDictionary[2])<br />
<br />
===Accessing Values===<br />
<br />
To access a value in a dictionary, you put in the key.<br />
<br />
myDictionary[1]<br />
<br />
returns one, because 1 is the key to "one."<br />
<br />
===Adding New Values===<br />
<br />
To overwrite a value, we do this.<br />
<br />
myDictionary[1] = "won"<br />
<br />
The value to the key 1 is now "won."<br />
<br />
To add a value, we do the same thing!<br />
<br />
myDictionary[3] = "three"<br />
<br />
This adds a key 3 with a value of "three."<br />
<br />
==Misc Concepts==<br />
<br />
This section will talk about some concepts that we haven't learned yet.<br />
<br />
====Concatenating Strings====<br />
<br />
Concatenating strings is putting them together. For example, "one" concatenated with "two" gives "onetwo."<br />
<br />
The following string,<br />
<br />
"Hello, " + person2 + "! How are you?"<br />
<br />
depends on what person2 was. If person2 was Bob, the string would be:<br />
<br />
"Hello, Bob! How are you?"<br />
<br />
It fits together perfectly!<br />
<br />
You cannot concatenate strings with integers. For example, doing this:<br />
<br />
"2" + 3<br />
<br />
will not work. Instead, to get an answer of "23", you must do this:<br />
<br />
"2" + str(3)<br />
<br />
That turns 3 into a string so it is "3", and the result will be "23".<br />
<br />
====Line Breaks====<br />
<br />
We can use multiple line breaks to make our code more organized. There are some places that you cannot line break. For example, this code will produce an error:<br />
<br />
myList =<br />
[1,2,3]<br />
<br />
This code does not work.<br />
<br />
This code '''does work''':<br />
<br />
myList = [<br />
1,2,3]<br />
<br />
It is accepted when you break a line right after the [. It is also accepted right after a comma. (And right before the ending ].)<br />
<br />
myList = [<br />
1,<br />
2,<br />
3<br />
]<br />
<br />
==Challenge Program==<br />
<br />
In this section, we will attempt the hardest program so far in this article.<br />
<br />
'''Make a conversation generator that will generate random conversations between different people.'''<br />
<br />
First, we will generate the people. We can use a list and generate two random numbers.<br />
<br />
import random<br />
<br />
peopleNames = [<br />
"Bob",<br />
"Kyle",<br />
"James",<br />
"Richard",<br />
"Zachary",<br />
"Olivia",<br />
"Jonathan",<br />
"Will",<br />
"Bobby",<br />
"Kevin"<br />
]<br />
person1 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
peopleNames.remove(person1)<br />
person2 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
<br />
(I made it more organized by separating the long lines of code into multiple lines. It only works when you have a line break right after each item in the list.)<br />
<br />
Here, we use the remove() function to remove person1 from the list to make sure we don't use the same name twice. <br />
<br />
We also used the len() function to find the length of the list (soft-coding!)<br />
<br />
Now, we need to create a list of possible values for the first thing that person1 says (person1 will always be the first one to talk). <br />
<br />
Then, we will print it out.<br />
<br />
import random<br />
<br />
peopleNames = [<br />
"Bob",<br />
"Kyle",<br />
"James",<br />
"Richard",<br />
"Zachary",<br />
"Olivia",<br />
"Jonathan",<br />
"Will",<br />
"Bobby",<br />
"Kevin"<br />
]<br />
person1 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
peopleNames.remove(person1)<br />
person2 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
<br />
first = [<br />
"Hi!",<br />
"Hello!",<br />
"Good morning!",<br />
"Hello, " + person2 + "!",<br />
"Hi.",<br />
"Hi, " + person2 + "!"<br />
]<br />
print(person1 + ": " + first[random.randint(0, (len(first) - 1))])<br />
<br />
If we test out this program, we can confirm that this part indeed does work. This program is already getting long! Now, we will use the same method and create the second message.<br />
<br />
import random<br />
<br />
peopleNames = [<br />
"Bob",<br />
"Kyle",<br />
"James",<br />
"Richard",<br />
"Zachary",<br />
"Olivia",<br />
"Jonathan",<br />
"Will",<br />
"Bobby",<br />
"Kevin"<br />
]<br />
person1 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
peopleNames.remove(person1)<br />
person2 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
<br />
first = [<br />
"Hi!",<br />
"Hello!",<br />
"Good morning!",<br />
"Hello, " + person2 + "!",<br />
"Hi.",<br />
"Hi, " + person2 + "!"<br />
]<br />
print(person1 + ": " + first[random.randint(0, (len(first) - 1))])<br />
<br />
second = [<br />
"Hi! How are you today?",<br />
"Hello! How are you?",<br />
"Good morning! How are you today?",<br />
"Hello, " + person1 + "! How are you?",<br />
"Hi. How are you?",<br />
"Hi, " + person1 + "! How are you today?"<br />
]<br />
print(person2 + ": " + second[random.randint(0, (len(second) - 1))])<br />
<br />
We will repeat this for the rest of the conversation:<br />
<br />
import random<br />
<br />
peopleNames = [<br />
"Bob",<br />
"Kyle",<br />
"James",<br />
"Richard",<br />
"Zachary",<br />
"Olivia",<br />
"Jonathan",<br />
"Will", <br />
"Bobby",<br />
"Kevin"<br />
]<br />
person1 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
peopleNames.remove(person1)<br />
person2 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
<br />
first = [<br />
"Hi!",<br />
"Hello!",<br />
"Good morning!",<br />
"Hello, " + person2 + "!",<br />
"Hi.",<br />
"Hi, " + person2 + "!"<br />
]<br />
print(person1 + ": " + first[random.randint(0, (len(first) - 1))])<br />
<br />
second = [<br />
"Hi! How are you today?",<br />
"Hello! How are you?",<br />
"Good morning! How are you today?",<br />
"Hello, " + person1 + "! How are you?",<br />
"Hi. How are you?",<br />
"Hi, " + person1 + "! How are you today?"<br />
]<br />
print(person2 + ": " + second[random.randint(0, (len(second) - 1))])<br />
<br />
third = [<br />
"I'm feeling awesome! And you?",<br />
"I'm feeling alright! How are you?",<br />
"I'm good, thank you. How are you feeling?",<br />
"I'm fine!" ,<br />
"How are you today?"<br />
]<br />
print(person1 + ": " + third[random.randint(0, (len(third) - 1))])<br />
<br />
fourth = [<br />
"I'm feeling great!",<br />
"I'm awesome!",<br />
"Thanks for asking! I am feeling good today!",<br />
"I'm feeling awesome today! Yippee!"<br />
] <br />
print(person2 + ": " + fourth[random.randint(0, (len(fourth) - 1))])<br />
<br />
fifth = [<br />
"It's so nice out today!",<br />
"Today is such a cloudy day.",<br />
"I hate it when it is so cloudy outside!",<br />
"It's partly cloudy today!"<br />
]<br />
print(person1 + ": " + fifth[random.randint(0, (len(fifth) - 1))])<br />
<br />
sixth = [<br />
"I know, right?",<br />
"I know.",<br />
"Yeah!",<br />
"True."<br />
]<br />
print(person2 + ": " + sixth[random.randint(0, (len(sixth) - 1))])<br />
<br />
seventh = [<br />
"Sorry, I need to leave. Bye!",<br />
"I gotta go. Bye!",<br />
"Sorry, I don't have time to stay and chat. I've got to go somewhere. Bye!"<br />
]<br />
print(person1 + ": " + seventh[random.randint(0, (len(seventh) - 1))])<br />
<br />
eighth = [<br />
"Bye!",<br />
"Good-bye!",<br />
"Bye, " + person1 + "."<br />
]<br />
print(person2 + ": " + eighth[random.randint(0, (len(eighth) - 1))])<br />
<br />
Whew! So long!<br />
<br />
Once we run our program. It works! This program really wasn't that hard.<br />
<br />
Congrats! You've made it so far!</div>Anstarhttps://artofproblemsolving.com/wiki/index.php?title=User_talk:Rrusczyk&diff=126085User talk:Rrusczyk2020-06-20T22:16:14Z<p>Anstar: </p>
<hr />
<div>--[[User:Rrusczyk|Rrusczyk]] 18:46, 8 June 2006 (EDT)Sup Biggy R!<br />
<br />
Is this really working? <asy>dot((0,0));</asy></div>Anstarhttps://artofproblemsolving.com/wiki/index.php?title=Abelian_group&diff=125407Abelian group2020-06-14T22:30:26Z<p>Anstar: removed stub</p>
<hr />
<div>An '''abelian group''' is a [[group]] in which the group [[operation]] is [[commutative]]. They are named after Norwegian mathematician Niels Abel. <br />
For a [[group]] to be considered '''abelian''', it must meet several requirements.<br />
<br />
Closure<br />
For all <math>a,b</math> <math>\in</math> <math>S</math>, and for all operations <math>\bullet</math>, <math>a\bullet b \in S</math>.<br />
Associativity <br />
For all <math>a,b,c</math> <math>\in</math> <math>S</math> and all operations <math>\bullet</math>, <math>(a\bullet b)\bullet c=a\bullet(b\bullet c)</math>.<br />
Identity Element<br />
There exists some <math>e \in S</math> such that <math>a \bullet e = e \bullet a = a</math>.<br />
Inverse Element<br />
For all <math>a \in S</math>, there exists some <math>a^{-1}</math> such that <math>a \bullet a^{-1} = e</math><br />
Commutativity<br />
For all <math>a,b \in S</math>, <math>a \bullet b = b \bullet a</math>.<br />
<br />
A simple example of an abelian group is <math>\mathbb{Z}</math> under addition. It is simple to show that it meets all the requirements.<br />
<br />
Closure<br />
For all <math>a,b \in \mathbb{Z} , a+b \in \mathbb{Z}</math>.<br />
Associativity<br />
For all <math>a,b,c \in \mathbb{Z} , (a+b)+c = a+(b+c)</math>.<br />
Identity Element<br />
For all <math>a \in \mathbb{Z} , a+0 = 0+a = a</math>.<br />
Inverse Element<br />
For all <math>a \in \mathbb{Z} , a+ -a = 0</math>.<br />
Commutativity<br />
For all <math>a,b \in \mathbb{Z} , a+b = b+a</math>.<br />
<br />
Seeing as <math>\mathbb{Z}</math> meets all of these requirements under addition, we can say that <math>\mathbb{Z}</math> is abelian under addition.<br />
==Examples==<br />
Notable examples of abelian groups include the integers under addition, the real numbers under addition, the integers modulo <math>n</math> under addition, the multiplicative group of integers modulo <math>n</math>, and the additive group of any ring. Many matrix groups are ''not'' abelian because matrix multiplication is associative and not commutative. The smallest finite non-abelian group is the dihedral group of order 6. <br />
<br />
<br />
[[Category:Definition]]<br />
[[Category:Group theory]]</div>Anstarhttps://artofproblemsolving.com/wiki/index.php?title=User:Anstar&diff=125406User:Anstar2020-06-14T22:26:56Z<p>Anstar: </p>
<hr />
<div>Anstar lives in CA, USA and likes doing math.<br />
[[Category:Gmass Hater]]</div>Anstarhttps://artofproblemsolving.com/wiki/index.php?title=User:Anstar&diff=122662User:Anstar2020-05-20T03:42:44Z<p>Anstar: </p>
<hr />
<div>Anstar lives in CA, USA and likes doing math.</div>Anstarhttps://artofproblemsolving.com/wiki/index.php?title=Basic_Programming_With_Python&diff=121736Basic Programming With Python2020-04-27T05:10:40Z<p>Anstar: /* methords= */</p>
<hr />
<div>'''Important: It is extremely recommended that you read [[Getting Started With Python Programming]] before reading this unless you already know some programming knowledge.'''<br />
<br />
(Note: This is a really long article. To learn the most from this article, you need to read everything in order and skip nothing, unless you are '''absolutely absolutely sure that that content is way too easy for you.''')<br />
<br />
This article will talk about some basic Python programming. If you don't even know how to install Python, look [[Getting Started With Python Programming|here]].<br />
<br />
Note that this article has lots of program examples. It is recommended (but not required) to try these on your own before looking at the solutions.<br />
<br />
==Loops==<br />
<br />
There are two different kinds of loops in Python: the for loop and the while loop.<br />
<br />
===The For Loop===<br />
<br />
The for loop iterates over a list, or an array, of objects. You have probably seen this code before:<br />
<br />
[[File:Capture.PNG|200px]]<br />
<br />
This for loop iterates over the list of integers from 1 to 51, excluding the 51 and including the 1. That means it is a list from 1 to 50, inclusive. On every iteration, Python will print the number that the loop is iterating through. <br />
<br />
For example, in the first iteration, i = 1, so Python prints 1.<br />
<br />
In the second iteration, i = 2, so Python prints 2.<br />
<br />
This continues so on until the number, 50, is reached. Therefore, the last number Python will print out is 50.<br />
<br />
====Program Example====<br />
<br />
'''Find <math>\sum_{n=1}^{50} 2^{n}.</math>'''<br />
<br />
To do this task, we must create a for loop and loop over the integers from 1 to 50 inclusive:<br />
<br />
for i in range(1,51):<br />
<br />
Now what? We must keep a running total and increase it by <math>2^i</math> every time:<br />
<br />
total = 0<br />
for i in range(1,51):<br />
total += 2**i<br />
<br />
We must not forget to print the total at the end!<br />
<br />
total = 0<br />
for i in range(1,51):<br />
total += 2**i<br />
print(total)<br />
<br />
You must exit out of the for loop one you reach the print(total) line by pressing backspace.<br />
<br />
Once you run your program, you should get an answer of <math>\boxed{2,251,799,813,685,246.}</math><br />
<br />
===The While Loop===<br />
<br />
While loops don't loop over a list. They loop over and over and over...'''until'''...a condition becomes false.<br />
<br />
i = 3<br />
total = 0<br />
while i < 1000:<br />
total += i<br />
i += 3<br />
print(total)<br />
<br />
In this code, the while loop loops 333 times, until <math>i</math> becomes greater than or equal to 1000.<br />
<br />
====Program Example====<br />
<br />
'''Find <math>\sum_{n=1}^{50} 2^n</math> using a while loop.'''<br />
<br />
We must create a while loop that will iterate until n is greater than <math>50.</math><br />
<br />
n = 1<br />
total = 0<br />
while n <= 50:<br />
total += 2**n<br />
n += 1<br />
print(total)<br />
<br />
We must not forget to include the n += 1 line at the end of the while loop! <br />
<br />
If we run this, we will get the same answer as last time, <math>2,251,799,813,685,246.</math><br />
<br />
==Functions==<br />
<br />
In this section, we will define new operations and do arithmetic with them in Python.<br />
<br />
===The New Operation===<br />
Let's say that you defined a new binary operation, the <math>\uparrow \downarrow.</math> You want it to be so <math>a \uparrow \downarrow b = a^{b}b^{a}.</math> Therefore, <math>1\uparrow \downarrow 2 = 1^{2}2^{1}=1\cdot 2= 2,</math> and <math>2\uparrow \downarrow 3 = 2^33^2 = 8\cdot 9 = 72.</math> Let's call this operation an '''up down arrow.'''<br />
<br />
===Program Example 1===<br />
<br />
'''Find <math>[2 \uparrow \downarrow (1 \uparrow \downarrow 2)] \uparrow \downarrow 2.</math>'''<br />
<br />
We know this will be a big number, so we should write a program to do it! We certainly don't want to do the exponentiation and multiplication every time we use the operation in our program, and that's where functions come in! Functions can take in parameters (<math>a</math> and <math>b</math>) and return a result depending on the parameters.<br />
<br />
def up_down_arrow(a,b): <br />
return ((a**b) * (b**a))<br />
<br />
Above is the code to define our function. We need to print the final result at the end, so we must put a print statement at the end.<br />
<br />
def up_down_arrow(a,b): <br />
return ((a**b) * (b**a))<br />
print(up_down_arrow(up_down_arrow(2,up_down_arrow(1,2)),2)<br />
<br />
All those nested up_down_arrow's might be confusing at first, but it really isn't that confusing.<br />
If you run your program, you should get your answer: <math>16,777,216.</math> <br />
<br />
You might be surprised that the answer is so big. If you actually start calculating the real answer without a program, you will really quickly find that the final result is <math>16 \uparrow \downarrow 2,</math> which does turn out to be 16,777,216 if you use a calculator.<br />
<br />
Let's make another operation!<br />
<br />
We will define the operation <math>\uparrow \downarrow \leftarrow \rightarrow</math> to be called '''all around.''' <math>a \uparrow \downarrow \leftarrow \rightarrow b = (ab(a \uparrow \downarrow b))^2.</math> That's an operation that will make really big numbers!<br />
<br />
===Program Example 2===<br />
<br />
'''Find 87 all around 132.'''<br />
<br />
The answer is bound to be a huge number, so we must make a program to solve it.<br />
<br />
We will keep our up_down_arrow function because in the definition of our all_around function we will use it. Then, we will define the all_around function.<br />
<br />
def up_down_arrow(a,b):<br />
return ((a**b) * (b**a))<br />
def all_around(a,b):<br />
return ((a * b * up_down_arrow(a,b)) ** 2)<br />
<br />
We must print all_around(87,132) at the end. Once we do that, and we run our program, we get a super huge number that has over 800 digits!<br />
<br />
===Understanding Functions===<br />
<br />
Every single function has a '''return value'''. If a function does not return anything, the return value is '''null'''. Null is a term used in programming as a placeholder that stands for nothing.<br />
<br />
====Simple Program Example 1====<br />
<br />
'''Define a function that adds 1 to an input.'''<br />
<br />
How will the function know what number to add 1 to? We will input a '''parameter''' for the function to add 1 to.<br />
<br />
def add_one(x):<br />
return x + 1<br />
<br />
In this function, <math>x</math> is the parameter.<br />
<br />
def add_one(x):<br />
return x + 1<br />
print(add_one(2))<br />
<br />
In the print statement, we set <math>x</math> as 2, and the function returns <math>2 + 1 = 3,</math> so the program prints <math>3</math>.<br />
<br />
====Simple Program Example 2====<br />
<br />
'''Define a function that prints out an input.'''<br />
<br />
We will use a parameter again.<br />
<br />
def print_function(x):<br />
print(x)<br />
<br />
Uh oh! We have nothing to return! Therefore, we will return nothing (or null), by just writing return.<br />
<br />
def print_function(x):<br />
print(x)<br />
return<br />
print_function("print_function")<br />
<br />
This code prints out print_function. print_function() is said to be '''called''' in the final line of the code. Again, we set <math>x</math>, our parameter, as "print_function."<br />
== Classes ==<br />
Classes are <br />
<br />
===Defining a class===<br />
<br />
===init===<br />
===methords===<br />
<br />
==Flow==<br />
<br />
Flow consists of if statements, elif (else if) statements, and else statements.<br />
<br />
*An if statement checks if a comparison is true.<br />
<br />
*An else statement checks if a comparison is not true. It is used after an if statement (and all elif statements after the if statement) and it shares the same comparison as the if statement.<br />
<br />
*An elif statement checks for two things: if a comparison is true, and if a comparison is not true. It is used right after the if statement.<br />
<br />
===Program Example===<br />
<br />
'''Does the number 10 have the property that when you multiply 10 by 5, you get a two digit number?'''<br />
<br />
This problem is super easy to solve without a program, but let's write a program to solve this anyway. We will use an if statement to check if <math>10\cdot 5</math> is less than 100 and greater than 9.<br />
<br />
if 10*5 > 9:<br />
if 10*5 < 100:<br />
print("Yes")<br />
else:<br />
print("No")<br />
else:<br />
print("No")<br />
<br />
This code means, if 10*5 > 9, then we will check if it is less than 100. If it is not greater than 9, however, we will print No. If it is greater than 9, we check if it is less than 100. If it is, we print Yes. If it isn't we print No.<br />
<br />
These nested if statements can be very confusing. Luckily, there is a faster an easier way to do this.<br />
<br />
if 10*5 > 9 and 10*5 < 100:<br />
print("Yes") <br />
else:<br />
print("No")<br />
<br />
This code checks for the two conditions at the same time. If we run it, we get our answer of Yes.<br />
<br />
==Booleans==<br />
<br />
===Program Example===<br />
<br />
'''Print all two-digit positive integers <math>x</math> such that <math>5x</math> is a two-digit positive integer.'''<br />
<br />
We can create a function with our previous code.<br />
<br />
We will have to slightly modify our function so we can use it in a for loop at the end:<br />
<br />
def check(a):<br />
if a*5 > 9 and a*5 < 100:<br />
return True <br />
else:<br />
return False<br />
<br />
True and False are what are called '''booleans'''. When an if or elif statement receives True, the code inside of the statement happens. When an if or elif statement receives False, the code inside of the statement does not happen. <br />
<br />
We must create a for loop that will iterate through all two digit positive integers. <br />
<br />
def check(a):<br />
if a*5 > 9 and a*5 < 100:<br />
return True <br />
else:<br />
return False<br />
for i in range(10,100):<br />
if check(i):<br />
print(i)<br />
<br />
The final for loop checks if <math>5i</math> is a two digit integer. If it is, the function returns True and the code inside the if statement gets run. If it isn't, the function returns False and the code inside the if statement gets ignored.<br />
<br />
If we run this, we will get the answer.<br />
<br />
All two digit integers from 10 to 19 inclusive work!<br />
<br />
=="Soft Coding" Programs==<br />
<br />
In the next few examples, you will see why hard coding programs is bad. Hard coding programs refers to coding a program that is hard to modify. For example:<br />
<br />
===Program Example 1===<br />
<br />
'''Print all two digit positive integers <math>x</math> such that <math>5x</math> is a three digit positive integer.'''<br />
<br />
We can keep our code and modify some parts of it.<br />
<br />
def check(a, min, max):<br />
if a*5 > min - 1 and a*5 < max + 1:<br />
return True <br />
else:<br />
return False<br />
<br />
def print_check(range_min, range_max, check_min, check_max):<br />
for i in range(range_min, range_max + 1):<br />
if check(i, check_min, check_max):<br />
print(i)<br />
return<br />
<br />
print_check(10, 99, 100, 999)<br />
<br />
Why did we add so many functions?<br />
<br />
Well, if the numbers in a problem change (and the words stay the same), and you need to change a lot of numbers in your program, your program is considered '''hard-coded'''. We want our programs to be as '''soft-coded''' as possible. In our new program, we only need to change 4 numbers (in the print_check() statement) if the numbers in the problem change. Therefore, our program is relatively soft-coded. There are still ways to soft-code this program even more, though.<br />
<br />
If we run our program, we get our answer.<br />
<br />
All numbers from 20 to 99 work!<br />
<br />
===Program Example 2===<br />
<br />
'''Print all three digit positive integers <math>x</math> such that <math>5x</math> is a three digit positive integer.'''<br />
<br />
We can just change the print_check line at the end to<br />
<br />
print_check(100, 999, 100, 999)<br />
<br />
and our program will be ready to be run.<br />
<br />
All numbers from 100 to 199 work.<br />
<br />
===Program Example 3===<br />
<br />
'''Print all two digit positive integers <math>x</math> such that <math>3x</math> is a three digit positive integer.'''<br />
<br />
Uh oh. Only changing the print_check line won't work. We will need to change our functions!<br />
<br />
def check(a, min, max, factor):<br />
if a*factor > min - 1 and a*factor < max + 1:<br />
return True <br />
else:<br />
return False<br />
<br />
def print_check(range_min, range_max, check_min, check_max, check_factor):<br />
for i in range(range_min, range_max + 1):<br />
if check(i, check_min, check_max, check_factor):<br />
print(i)<br />
return<br />
<br />
print_check(10, 99, 100, 999, 3)<br />
<br />
In this step, we added a parameter in both functions. We also soft-coded our program even more! Hooray!<br />
<br />
All integers from 34 to 99 work.<br />
<br />
===Program Example 4===<br />
<br />
'''Print all two digit positive integers <math>x</math> such that <math>12x</math> is a positive integer from 500 to 900.'''<br />
<br />
This problem may look a bit different from the other ones, but it really is the same thing, except that the factor is 12 and check_min and check_max are 500 and 900, respectively.<br />
<br />
Once we change the final print_check() line to satisfy our needs, we can run our program.<br />
<br />
All numbers from 42 to 75 work!<br />
<br />
Congrats! You have written your first programs above 10 lines of code!<br />
<br />
==Random==<br />
<br />
There is a package in Python that allows the use of random numbers.<br />
<br />
===Program Example 1===<br />
<br />
'''Generate a random number from 1 to 6.'''<br />
<br />
Easy peasy. We will just generate a random number from 1 to 6 with the package like this:<br />
<br />
import random<br />
print(random.randint(1,6))<br />
<br />
As you can see, when you run this program, you get a random number from 1 to 6.<br />
<br />
===Program Example 2===<br />
<br />
'''Simulate the rolling of 1000 dice. Now, count the number of times you roll 6. Print that number out.'''<br />
<br />
We can create a function that returns a random number from 1 to 6. Then, we can make a for loop that rolls the dice 1000 times and check if it is a 6.<br />
<br />
import random<br />
count = 0<br />
<br />
def roll():<br />
return random.randint(1,6)<br />
<br />
for i in range(1, 1001):<br />
if roll() == 6:<br />
count += 1<br />
<br />
print(count)<br />
<br />
If we run this, we will get a number around 170.<br />
<br />
===Program Example 3===<br />
<br />
'''Simulate the rolling of 10,000 dice. Now, count the amount of times you roll 3. Print that amount out.'''<br />
<br />
We can keep our roll function and our code inside the for loop, but we need to change our for loop statement.<br />
<br />
We can actually soft-code our program more. Let's turn the whole for loop into a function!<br />
<br />
import random<br />
<br />
def roll():<br />
return random.randint(1,6)<br />
<br />
def count(amount):<br />
count_ = 0<br />
<br />
for i in range(1, amount+1):<br />
if roll() == 3:<br />
count_ += 1<br />
return count_<br />
<br />
print(count(10000))<br />
<br />
If we run this code, it works.<br />
<br />
===Program Example 4===<br />
<br />
'''One of my friends loves rolling dice. He is going to roll 1 die tomorrow, 2 dice two days from now, 3 dice three days from now, and so on so that he rolls <math>a</math> dice <math>a</math> days from now. He gets tired rolling dice after rolling dice for 365 days (so the last day he rolls 365 dice). In Python, simulate this. How many times does he roll 3 after 365 days of rolling dice?'''<br />
<br />
We can use a for loop that calls a function multiple times.<br />
<br />
import random<br />
<br />
def roll():<br />
return random.randint(1,6)<br />
<br />
def count(amount):<br />
count_ = 0<br />
for i in range(1, amount+1):<br />
if roll() == 3:<br />
count_ += 1<br />
return count_<br />
<br />
total = 0<br />
<br />
for i in range(1, 366):<br />
total += count(i)<br />
<br />
print(total)<br />
<br />
This is a really long program, but the whole program should make sense if you look at it for a while. We defined our count function in the previous example, and now we are using it with a for loop and a running total. <br />
<br />
You should get a number around 11,000 when you run it. Wow, lots of 3's!<br />
<br />
===Program Example 5===<br />
<br />
'''20 of my friends love rolling dice. They are all going to roll 1 die each tomorrow, 2 dice each two days from now, 3 dice each three days from now, and so on so that they roll <math>a</math> dice each <math>a</math> days from now. But, one of my friends gets tired very quickly and he only rolls dice for 1 day and stops. Another friend only will roll dice for 2 days, and another will roll dice for three days only, and so on up to the fact that my last friend will roll dice for 20 days. In Python, simulate this. How many times does someone roll 3 after everything?'''<br />
<br />
We will have to make our for loop into a function again.<br />
<br />
import random<br />
<br />
def roll():<br />
return random.randint(1,6)<br />
<br />
def count(amount):<br />
count_ = 0<br />
for i in range(1, amount+1):<br />
if roll() == 3:<br />
count_ += 1<br />
return count_<br />
<br />
def count2(amount)<br />
total = 0<br />
for i in range(1, amount + 1):<br />
total += count(i)<br />
return total<br />
<br />
def count3(amount)<br />
total = 0<br />
for i in range(1, amount + 1):<br />
total += count2(i)<br />
return total<br />
<br />
print(count3(20))<br />
<br />
(Our program is so long!)<br />
<br />
I also made a new function just in case we needed to turn that into a function later.<br />
<br />
'''Make sure''' you read the code carefully and you fully understand it. If you don't understand every single line of code, then you will get confused later on in this article.<br />
<br />
When you run this program, you might be surprised that the answer isn't so big.<br />
<br />
===Program Example 6===<br />
<br />
'''365 of my friends love rolling dice. They are all going to roll 1 die each tomorrow, 2 dice each two days from now, 3 dice each three days from now, and so on so that they roll <math>a</math> dice each <math>a</math> days from now. But, one of my friends gets tired very quickly and he only rolls dice for 1 day and stops. Another friend only will roll dice for 2 days, and another will roll dice for three days only, and so on up to the fact that my last friend will roll dice for 365 days. In Python, simulate this. How many times does someone roll 3 after everything?'''<br />
<br />
Because we soft-coded our program so much, all we have to do is change the last line so the parameter of count3() is 365.<br />
<br />
If we run it...we get a big answer, as expected. It also takes quite a while!<br />
<br />
You may not have realized that we soft-coded our program at all, but the whole point of functions is to soft-code programs!<br />
<br />
Congrats on writing a program that is around 25 lines long!<br />
<br />
==Very Basic Datatypes==<br />
<br />
An integer is a basic datatype in Python. Basically, all variables with the datatype of '''int''' is an integer.<br />
<br />
A string is another basic datatype, and it is a string of characters enclosed by quotes.<br />
<br />
===Why Are Datatypes So Important?===<br />
<br />
Let's say we wanted to make a program that would add 2 and 3. Some bogus code would be:<br />
<br />
x="2"<br />
y="3"<br />
print(x+y)<br />
<br />
If you ran this code, you would get 23. Why is that?<br />
<br />
Well, here, x and y are strings. When you perform the addition operator to strings in Python, it concatenates the strings, giving 23.<br />
<br />
The real code is:<br />
<br />
x=2<br />
y=3<br />
print(x+y)<br />
<br />
If you run this, you will get <math>5</math>, which is correct.<br />
<br />
Here's another reason datatypes are important. Now, we will introduce the datatype called the '''floating point number''', or '''float'''. A floating-point number is a number with a decimal point.<br />
<br />
Let's go back to the IDLE. Type "0.1*10". The result is 1.0. Notice the decimal point.<br />
<br />
Let's type something different. Type <math>0.1+0.1+0.1+0.1+0.1+0.1+0.1+0.1+0.1+0.1.</math><br />
<br />
'''WHAT!?'''<br />
<br />
You would have expected the answer to be 1, but it isn't 1. What happened?<br />
<br />
'''Float approximation''' happened. Most (almost all) programming languages have a bad float approximation. That means that 1.0 can turn into 0.99999999999999 and 0.5 can turn into 0.49999999999999999993. That only happens with floats, so we should try to use floats as sparingly as possible.<br />
<br />
==Lists==<br />
<br />
A for loop iterates over a '''list'''. A list is a bunch of objects stored in one variable. (Hey! A list is a datatype!) For loops are highly related to lists.<br />
<br />
Let's say we wanted to make a program to print all the items in a list.<br />
<br />
We will first create the list, using the code:<br />
<br />
myList = [1,4,6,8]<br />
<br />
This is a list with four items: 1, 4, 6, and 8.<br />
<br />
We must now print all elements of it with a for loop:<br />
<br />
myList = [1,4,6,8]<br />
for i in myList:<br />
print(i)<br />
<br />
When we run this program, we get the numbers 1, 4, 6, and 8, as expected.<br />
<br />
===Accessing Values===<br />
<br />
Let's say we wanted to print out the second item in a list. We will use '''indexes'''.<br />
<br />
The index of the first item in a list is always 0. The index of the second is 1. The index of the <math>n</math>th is <math>n-1.</math><br />
<br />
To print out the second item, we will use an index of 1, like this:<br />
<br />
myList = [1,4,6,8]<br />
print(myList[1])<br />
<br />
Notice that the index is inside of the square brackets.<br />
<br />
===Adding Values===<br />
<br />
We can use the list.append() function to add an object to the end of a list.<br />
<br />
myList.append(10)<br />
<br />
will add 10 to the list, which makes myList = [1,4,6,8,10].<br />
<br />
===Removing Items From Lists===<br />
<br />
We can use the list.remove() function to remove a specific item in a list.<br />
<br />
For example, consider this code.<br />
<br />
myList = [1,2,3]<br />
myList.remove(3)<br />
<br />
This code will make myList turn into [1,2]. The element, 3, gets removed.<br />
<br />
===len(list)===<br />
<br />
The len(list) function returns the length of a list.<br />
<br />
This code will print 3.<br />
<br />
myList = [1,2,3]<br />
print(len(myList))<br />
<br />
The length of myList is 3, so Python prints 3.<br />
<br />
===All Kinds Of Lists===<br />
<br />
Lists don't have to be only integers!<br />
<br />
myList = [1,"Hi","Hello world", 3.5, 3.14159265358979323]<br />
<br />
If fact, there can be lists inside of lists!<br />
<br />
myList = [[1,2,3], [3,4,5], [5,6,"Hello world"], "BOB", 3.1415926]<br />
<br />
Even this!<br />
<br />
myList = [[1, [1, [1,2,3],3],3], [[[3,["Hello world", 4],5],4,5],4,5], [5,6,7,[1,[1,2,3],3],"Hello world"], "BOB", 3.1415926, True]<br />
<br />
If you look at that list carefully, you will find lists inside of lists inside of lists inside of lists! And, a boolean at the end!<br />
<br />
Like variables, you can have as many lists in a program as you want (a list is a variable)!<br />
<br />
myList = [1,2,3,4]<br />
yourList = [5,6,7,8]<br />
hisList = [9,10,11,12]<br />
herList = [13,14,15,16]<br />
theirList = [17,18,19,20]<br />
ourList = [21,22,23,24]<br />
listsOfLists = [[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16],[17,18,19,20],[21,22,23,24]]<br />
<br />
==Dictionaries==<br />
<br />
A dictionary (a type of datatype) is a bunch of keys and values. There is a major difference between dictionaries and lists. Lists are ordered; dictionaries are not.<br />
<br />
Here is the '''syntax''' of creating a dictionary:<br />
<br />
myDictionary = {1:"one",2:"two"}<br />
<br />
This dictionary has two key/value pairs. Notice it is surrounded in curly braces. The keys are 1 and 2; the values are "one" and "two."<br />
<br />
How is this useful? Let's make a simple program to test it out.<br />
<br />
myDictionary = {1:"one",2:"two"}<br />
print(myDictionary[1])<br />
print(myDictionary[2])<br />
<br />
===Accessing Values===<br />
<br />
To access a value in a dictionary, you put in the key.<br />
<br />
myDictionary[1]<br />
<br />
returns one, because 1 is the key to "one."<br />
<br />
===Adding New Values===<br />
<br />
To overwrite a value, we do this.<br />
<br />
myDictionary[1] = "won"<br />
<br />
The value to the key 1 is now "won."<br />
<br />
To add a value, we do the same thing!<br />
<br />
myDictionary[3] = "three"<br />
<br />
This adds a key 3 with a value of "three."<br />
<br />
==Misc Concepts==<br />
<br />
This section will talk about some concepts that we haven't learned yet.<br />
<br />
====Concatenating Strings====<br />
<br />
Concatenating strings is putting them together. For example, "one" concatenated with "two" gives "onetwo."<br />
<br />
The following string,<br />
<br />
"Hello, " + person2 + "! How are you?"<br />
<br />
depends on what person2 was. If person2 was Bob, the string would be:<br />
<br />
"Hello, Bob! How are you?"<br />
<br />
It fits together perfectly!<br />
<br />
You cannot concatenate strings with integers. For example, doing this:<br />
<br />
"2" + 3<br />
<br />
will not work. Instead, to get an answer of "23", you must do this:<br />
<br />
"2" + str(3)<br />
<br />
That turns 3 into a string so it is "3", and the result will be "23".<br />
<br />
====Line Breaks====<br />
<br />
We can use multiple line breaks to make our code more organized. There are some places that you cannot line break. For example, this code will produce an error:<br />
<br />
myList =<br />
[1,2,3]<br />
<br />
This code does not work.<br />
<br />
This code '''does work''':<br />
<br />
myList = [<br />
1,2,3]<br />
<br />
It is accepted when you break a line right after the [. It is also accepted right after a comma. (And right before the ending ].)<br />
<br />
myList = [<br />
1,<br />
2,<br />
3<br />
]<br />
<br />
==Challenge Program==<br />
<br />
In this section, we will attempt the hardest program so far in this article.<br />
<br />
'''Make a conversation generator that will generate random conversations between different people.'''<br />
<br />
First, we will generate the people. We can use a list and generate two random numbers.<br />
<br />
import random<br />
<br />
peopleNames = [<br />
"Bob",<br />
"Kyle",<br />
"James",<br />
"Richard",<br />
"Zachary",<br />
"Olivia",<br />
"Jonathan",<br />
"Will",<br />
"Bobby",<br />
"Kevin"<br />
]<br />
person1 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
peopleNames.remove(person1)<br />
person2 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
<br />
(I made it more organized by separating the long lines of code into multiple lines. It only works when you have a line break right after each item in the list.)<br />
<br />
Here, we use the remove() function to remove person1 from the list to make sure we don't use the same name twice. <br />
<br />
We also used the len() function to find the length of the list (soft-coding!)<br />
<br />
Now, we need to create a list of possible values for the first thing that person1 says (person1 will always be the first one to talk). <br />
<br />
Then, we will print it out.<br />
<br />
import random<br />
<br />
peopleNames = [<br />
"Bob",<br />
"Kyle",<br />
"James",<br />
"Richard",<br />
"Zachary",<br />
"Olivia",<br />
"Jonathan",<br />
"Will",<br />
"Bobby",<br />
"Kevin"<br />
]<br />
person1 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
peopleNames.remove(person1)<br />
person2 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
<br />
first = [<br />
"Hi!",<br />
"Hello!",<br />
"Good morning!",<br />
"Hello, " + person2 + "!",<br />
"Hi.",<br />
"Hi, " + person2 + "!"<br />
]<br />
print(person1 + ": " + first[random.randint(0, (len(first) - 1))])<br />
<br />
If we test out this program, we can confirm that this part indeed does work. This program is already getting long! Now, we will use the same method and create the second message.<br />
<br />
import random<br />
<br />
peopleNames = [<br />
"Bob",<br />
"Kyle",<br />
"James",<br />
"Richard",<br />
"Zachary",<br />
"Olivia",<br />
"Jonathan",<br />
"Will",<br />
"Bobby",<br />
"Kevin"<br />
]<br />
person1 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
peopleNames.remove(person1)<br />
person2 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
<br />
first = [<br />
"Hi!",<br />
"Hello!",<br />
"Good morning!",<br />
"Hello, " + person2 + "!",<br />
"Hi.",<br />
"Hi, " + person2 + "!"<br />
]<br />
print(person1 + ": " + first[random.randint(0, (len(first) - 1))])<br />
<br />
second = [<br />
"Hi! How are you today?",<br />
"Hello! How are you?",<br />
"Good morning! How are you today?",<br />
"Hello, " + person1 + "! How are you?",<br />
"Hi. How are you?",<br />
"Hi, " + person1 + "! How are you today?"<br />
]<br />
print(person2 + ": " + second[random.randint(0, (len(second) - 1))])<br />
<br />
We will repeat this for the rest of the conversation:<br />
<br />
import random<br />
<br />
peopleNames = [<br />
"Bob",<br />
"Kyle",<br />
"James",<br />
"Richard",<br />
"Zachary",<br />
"Olivia",<br />
"Jonathan",<br />
"Will", <br />
"Bobby",<br />
"Kevin"<br />
]<br />
person1 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
peopleNames.remove(person1)<br />
person2 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
<br />
first = [<br />
"Hi!",<br />
"Hello!",<br />
"Good morning!",<br />
"Hello, " + person2 + "!",<br />
"Hi.",<br />
"Hi, " + person2 + "!"<br />
]<br />
print(person1 + ": " + first[random.randint(0, (len(first) - 1))])<br />
<br />
second = [<br />
"Hi! How are you today?",<br />
"Hello! How are you?",<br />
"Good morning! How are you today?",<br />
"Hello, " + person1 + "! How are you?",<br />
"Hi. How are you?",<br />
"Hi, " + person1 + "! How are you today?"<br />
]<br />
print(person2 + ": " + second[random.randint(0, (len(second) - 1))])<br />
<br />
third = [<br />
"I'm feeling awesome! And you?",<br />
"I'm feeling alright! How are you?",<br />
"I'm good, thank you. How are you feeling?",<br />
"I'm fine!" ,<br />
"How are you today?"<br />
]<br />
print(person1 + ": " + third[random.randint(0, (len(third) - 1))])<br />
<br />
fourth = [<br />
"I'm feeling great!",<br />
"I'm awesome!",<br />
"Thanks for asking! I am feeling good today!",<br />
"I'm feeling awesome today! Yippee!"<br />
] <br />
print(person2 + ": " + fourth[random.randint(0, (len(fourth) - 1))])<br />
<br />
fifth = [<br />
"It's so nice out today!",<br />
"Today is such a cloudy day.",<br />
"I hate it when it is so cloudy outside!",<br />
"It's partly cloudy today!"<br />
]<br />
print(person1 + ": " + fifth[random.randint(0, (len(fifth) - 1))])<br />
<br />
sixth = [<br />
"I know, right?",<br />
"I know.",<br />
"Yeah!",<br />
"True."<br />
]<br />
print(person2 + ": " + sixth[random.randint(0, (len(sixth) - 1))])<br />
<br />
seventh = [<br />
"Sorry, I need to leave. Bye!",<br />
"I gotta go. Bye!",<br />
"Sorry, I don't have time to stay and chat. I've got to go somewhere. Bye!"<br />
]<br />
print(person1 + ": " + seventh[random.randint(0, (len(seventh) - 1))])<br />
<br />
eighth = [<br />
"Bye!",<br />
"Good-bye!",<br />
"Bye, " + person1 + "."<br />
]<br />
print(person2 + ": " + eighth[random.randint(0, (len(eighth) - 1))])<br />
<br />
Whew! So long!<br />
<br />
Once we run our program. It works! This program really wasn't that hard.<br />
<br />
Congrats! You've made it so far!</div>Anstarhttps://artofproblemsolving.com/wiki/index.php?title=Basic_Programming_With_Python&diff=121735Basic Programming With Python2020-04-27T05:10:27Z<p>Anstar: /* Classes */</p>
<hr />
<div>'''Important: It is extremely recommended that you read [[Getting Started With Python Programming]] before reading this unless you already know some programming knowledge.'''<br />
<br />
(Note: This is a really long article. To learn the most from this article, you need to read everything in order and skip nothing, unless you are '''absolutely absolutely sure that that content is way too easy for you.''')<br />
<br />
This article will talk about some basic Python programming. If you don't even know how to install Python, look [[Getting Started With Python Programming|here]].<br />
<br />
Note that this article has lots of program examples. It is recommended (but not required) to try these on your own before looking at the solutions.<br />
<br />
==Loops==<br />
<br />
There are two different kinds of loops in Python: the for loop and the while loop.<br />
<br />
===The For Loop===<br />
<br />
The for loop iterates over a list, or an array, of objects. You have probably seen this code before:<br />
<br />
[[File:Capture.PNG|200px]]<br />
<br />
This for loop iterates over the list of integers from 1 to 51, excluding the 51 and including the 1. That means it is a list from 1 to 50, inclusive. On every iteration, Python will print the number that the loop is iterating through. <br />
<br />
For example, in the first iteration, i = 1, so Python prints 1.<br />
<br />
In the second iteration, i = 2, so Python prints 2.<br />
<br />
This continues so on until the number, 50, is reached. Therefore, the last number Python will print out is 50.<br />
<br />
====Program Example====<br />
<br />
'''Find <math>\sum_{n=1}^{50} 2^{n}.</math>'''<br />
<br />
To do this task, we must create a for loop and loop over the integers from 1 to 50 inclusive:<br />
<br />
for i in range(1,51):<br />
<br />
Now what? We must keep a running total and increase it by <math>2^i</math> every time:<br />
<br />
total = 0<br />
for i in range(1,51):<br />
total += 2**i<br />
<br />
We must not forget to print the total at the end!<br />
<br />
total = 0<br />
for i in range(1,51):<br />
total += 2**i<br />
print(total)<br />
<br />
You must exit out of the for loop one you reach the print(total) line by pressing backspace.<br />
<br />
Once you run your program, you should get an answer of <math>\boxed{2,251,799,813,685,246.}</math><br />
<br />
===The While Loop===<br />
<br />
While loops don't loop over a list. They loop over and over and over...'''until'''...a condition becomes false.<br />
<br />
i = 3<br />
total = 0<br />
while i < 1000:<br />
total += i<br />
i += 3<br />
print(total)<br />
<br />
In this code, the while loop loops 333 times, until <math>i</math> becomes greater than or equal to 1000.<br />
<br />
====Program Example====<br />
<br />
'''Find <math>\sum_{n=1}^{50} 2^n</math> using a while loop.'''<br />
<br />
We must create a while loop that will iterate until n is greater than <math>50.</math><br />
<br />
n = 1<br />
total = 0<br />
while n <= 50:<br />
total += 2**n<br />
n += 1<br />
print(total)<br />
<br />
We must not forget to include the n += 1 line at the end of the while loop! <br />
<br />
If we run this, we will get the same answer as last time, <math>2,251,799,813,685,246.</math><br />
<br />
==Functions==<br />
<br />
In this section, we will define new operations and do arithmetic with them in Python.<br />
<br />
===The New Operation===<br />
Let's say that you defined a new binary operation, the <math>\uparrow \downarrow.</math> You want it to be so <math>a \uparrow \downarrow b = a^{b}b^{a}.</math> Therefore, <math>1\uparrow \downarrow 2 = 1^{2}2^{1}=1\cdot 2= 2,</math> and <math>2\uparrow \downarrow 3 = 2^33^2 = 8\cdot 9 = 72.</math> Let's call this operation an '''up down arrow.'''<br />
<br />
===Program Example 1===<br />
<br />
'''Find <math>[2 \uparrow \downarrow (1 \uparrow \downarrow 2)] \uparrow \downarrow 2.</math>'''<br />
<br />
We know this will be a big number, so we should write a program to do it! We certainly don't want to do the exponentiation and multiplication every time we use the operation in our program, and that's where functions come in! Functions can take in parameters (<math>a</math> and <math>b</math>) and return a result depending on the parameters.<br />
<br />
def up_down_arrow(a,b): <br />
return ((a**b) * (b**a))<br />
<br />
Above is the code to define our function. We need to print the final result at the end, so we must put a print statement at the end.<br />
<br />
def up_down_arrow(a,b): <br />
return ((a**b) * (b**a))<br />
print(up_down_arrow(up_down_arrow(2,up_down_arrow(1,2)),2)<br />
<br />
All those nested up_down_arrow's might be confusing at first, but it really isn't that confusing.<br />
If you run your program, you should get your answer: <math>16,777,216.</math> <br />
<br />
You might be surprised that the answer is so big. If you actually start calculating the real answer without a program, you will really quickly find that the final result is <math>16 \uparrow \downarrow 2,</math> which does turn out to be 16,777,216 if you use a calculator.<br />
<br />
Let's make another operation!<br />
<br />
We will define the operation <math>\uparrow \downarrow \leftarrow \rightarrow</math> to be called '''all around.''' <math>a \uparrow \downarrow \leftarrow \rightarrow b = (ab(a \uparrow \downarrow b))^2.</math> That's an operation that will make really big numbers!<br />
<br />
===Program Example 2===<br />
<br />
'''Find 87 all around 132.'''<br />
<br />
The answer is bound to be a huge number, so we must make a program to solve it.<br />
<br />
We will keep our up_down_arrow function because in the definition of our all_around function we will use it. Then, we will define the all_around function.<br />
<br />
def up_down_arrow(a,b):<br />
return ((a**b) * (b**a))<br />
def all_around(a,b):<br />
return ((a * b * up_down_arrow(a,b)) ** 2)<br />
<br />
We must print all_around(87,132) at the end. Once we do that, and we run our program, we get a super huge number that has over 800 digits!<br />
<br />
===Understanding Functions===<br />
<br />
Every single function has a '''return value'''. If a function does not return anything, the return value is '''null'''. Null is a term used in programming as a placeholder that stands for nothing.<br />
<br />
====Simple Program Example 1====<br />
<br />
'''Define a function that adds 1 to an input.'''<br />
<br />
How will the function know what number to add 1 to? We will input a '''parameter''' for the function to add 1 to.<br />
<br />
def add_one(x):<br />
return x + 1<br />
<br />
In this function, <math>x</math> is the parameter.<br />
<br />
def add_one(x):<br />
return x + 1<br />
print(add_one(2))<br />
<br />
In the print statement, we set <math>x</math> as 2, and the function returns <math>2 + 1 = 3,</math> so the program prints <math>3</math>.<br />
<br />
====Simple Program Example 2====<br />
<br />
'''Define a function that prints out an input.'''<br />
<br />
We will use a parameter again.<br />
<br />
def print_function(x):<br />
print(x)<br />
<br />
Uh oh! We have nothing to return! Therefore, we will return nothing (or null), by just writing return.<br />
<br />
def print_function(x):<br />
print(x)<br />
return<br />
print_function("print_function")<br />
<br />
This code prints out print_function. print_function() is said to be '''called''' in the final line of the code. Again, we set <math>x</math>, our parameter, as "print_function."<br />
== Classes ==<br />
Classes are <br />
<br />
===Defining a class===<br />
<br />
===init===<br />
===methords====<br />
<br />
==Flow==<br />
<br />
Flow consists of if statements, elif (else if) statements, and else statements.<br />
<br />
*An if statement checks if a comparison is true.<br />
<br />
*An else statement checks if a comparison is not true. It is used after an if statement (and all elif statements after the if statement) and it shares the same comparison as the if statement.<br />
<br />
*An elif statement checks for two things: if a comparison is true, and if a comparison is not true. It is used right after the if statement.<br />
<br />
===Program Example===<br />
<br />
'''Does the number 10 have the property that when you multiply 10 by 5, you get a two digit number?'''<br />
<br />
This problem is super easy to solve without a program, but let's write a program to solve this anyway. We will use an if statement to check if <math>10\cdot 5</math> is less than 100 and greater than 9.<br />
<br />
if 10*5 > 9:<br />
if 10*5 < 100:<br />
print("Yes")<br />
else:<br />
print("No")<br />
else:<br />
print("No")<br />
<br />
This code means, if 10*5 > 9, then we will check if it is less than 100. If it is not greater than 9, however, we will print No. If it is greater than 9, we check if it is less than 100. If it is, we print Yes. If it isn't we print No.<br />
<br />
These nested if statements can be very confusing. Luckily, there is a faster an easier way to do this.<br />
<br />
if 10*5 > 9 and 10*5 < 100:<br />
print("Yes") <br />
else:<br />
print("No")<br />
<br />
This code checks for the two conditions at the same time. If we run it, we get our answer of Yes.<br />
<br />
==Booleans==<br />
<br />
===Program Example===<br />
<br />
'''Print all two-digit positive integers <math>x</math> such that <math>5x</math> is a two-digit positive integer.'''<br />
<br />
We can create a function with our previous code.<br />
<br />
We will have to slightly modify our function so we can use it in a for loop at the end:<br />
<br />
def check(a):<br />
if a*5 > 9 and a*5 < 100:<br />
return True <br />
else:<br />
return False<br />
<br />
True and False are what are called '''booleans'''. When an if or elif statement receives True, the code inside of the statement happens. When an if or elif statement receives False, the code inside of the statement does not happen. <br />
<br />
We must create a for loop that will iterate through all two digit positive integers. <br />
<br />
def check(a):<br />
if a*5 > 9 and a*5 < 100:<br />
return True <br />
else:<br />
return False<br />
for i in range(10,100):<br />
if check(i):<br />
print(i)<br />
<br />
The final for loop checks if <math>5i</math> is a two digit integer. If it is, the function returns True and the code inside the if statement gets run. If it isn't, the function returns False and the code inside the if statement gets ignored.<br />
<br />
If we run this, we will get the answer.<br />
<br />
All two digit integers from 10 to 19 inclusive work!<br />
<br />
=="Soft Coding" Programs==<br />
<br />
In the next few examples, you will see why hard coding programs is bad. Hard coding programs refers to coding a program that is hard to modify. For example:<br />
<br />
===Program Example 1===<br />
<br />
'''Print all two digit positive integers <math>x</math> such that <math>5x</math> is a three digit positive integer.'''<br />
<br />
We can keep our code and modify some parts of it.<br />
<br />
def check(a, min, max):<br />
if a*5 > min - 1 and a*5 < max + 1:<br />
return True <br />
else:<br />
return False<br />
<br />
def print_check(range_min, range_max, check_min, check_max):<br />
for i in range(range_min, range_max + 1):<br />
if check(i, check_min, check_max):<br />
print(i)<br />
return<br />
<br />
print_check(10, 99, 100, 999)<br />
<br />
Why did we add so many functions?<br />
<br />
Well, if the numbers in a problem change (and the words stay the same), and you need to change a lot of numbers in your program, your program is considered '''hard-coded'''. We want our programs to be as '''soft-coded''' as possible. In our new program, we only need to change 4 numbers (in the print_check() statement) if the numbers in the problem change. Therefore, our program is relatively soft-coded. There are still ways to soft-code this program even more, though.<br />
<br />
If we run our program, we get our answer.<br />
<br />
All numbers from 20 to 99 work!<br />
<br />
===Program Example 2===<br />
<br />
'''Print all three digit positive integers <math>x</math> such that <math>5x</math> is a three digit positive integer.'''<br />
<br />
We can just change the print_check line at the end to<br />
<br />
print_check(100, 999, 100, 999)<br />
<br />
and our program will be ready to be run.<br />
<br />
All numbers from 100 to 199 work.<br />
<br />
===Program Example 3===<br />
<br />
'''Print all two digit positive integers <math>x</math> such that <math>3x</math> is a three digit positive integer.'''<br />
<br />
Uh oh. Only changing the print_check line won't work. We will need to change our functions!<br />
<br />
def check(a, min, max, factor):<br />
if a*factor > min - 1 and a*factor < max + 1:<br />
return True <br />
else:<br />
return False<br />
<br />
def print_check(range_min, range_max, check_min, check_max, check_factor):<br />
for i in range(range_min, range_max + 1):<br />
if check(i, check_min, check_max, check_factor):<br />
print(i)<br />
return<br />
<br />
print_check(10, 99, 100, 999, 3)<br />
<br />
In this step, we added a parameter in both functions. We also soft-coded our program even more! Hooray!<br />
<br />
All integers from 34 to 99 work.<br />
<br />
===Program Example 4===<br />
<br />
'''Print all two digit positive integers <math>x</math> such that <math>12x</math> is a positive integer from 500 to 900.'''<br />
<br />
This problem may look a bit different from the other ones, but it really is the same thing, except that the factor is 12 and check_min and check_max are 500 and 900, respectively.<br />
<br />
Once we change the final print_check() line to satisfy our needs, we can run our program.<br />
<br />
All numbers from 42 to 75 work!<br />
<br />
Congrats! You have written your first programs above 10 lines of code!<br />
<br />
==Random==<br />
<br />
There is a package in Python that allows the use of random numbers.<br />
<br />
===Program Example 1===<br />
<br />
'''Generate a random number from 1 to 6.'''<br />
<br />
Easy peasy. We will just generate a random number from 1 to 6 with the package like this:<br />
<br />
import random<br />
print(random.randint(1,6))<br />
<br />
As you can see, when you run this program, you get a random number from 1 to 6.<br />
<br />
===Program Example 2===<br />
<br />
'''Simulate the rolling of 1000 dice. Now, count the number of times you roll 6. Print that number out.'''<br />
<br />
We can create a function that returns a random number from 1 to 6. Then, we can make a for loop that rolls the dice 1000 times and check if it is a 6.<br />
<br />
import random<br />
count = 0<br />
<br />
def roll():<br />
return random.randint(1,6)<br />
<br />
for i in range(1, 1001):<br />
if roll() == 6:<br />
count += 1<br />
<br />
print(count)<br />
<br />
If we run this, we will get a number around 170.<br />
<br />
===Program Example 3===<br />
<br />
'''Simulate the rolling of 10,000 dice. Now, count the amount of times you roll 3. Print that amount out.'''<br />
<br />
We can keep our roll function and our code inside the for loop, but we need to change our for loop statement.<br />
<br />
We can actually soft-code our program more. Let's turn the whole for loop into a function!<br />
<br />
import random<br />
<br />
def roll():<br />
return random.randint(1,6)<br />
<br />
def count(amount):<br />
count_ = 0<br />
<br />
for i in range(1, amount+1):<br />
if roll() == 3:<br />
count_ += 1<br />
return count_<br />
<br />
print(count(10000))<br />
<br />
If we run this code, it works.<br />
<br />
===Program Example 4===<br />
<br />
'''One of my friends loves rolling dice. He is going to roll 1 die tomorrow, 2 dice two days from now, 3 dice three days from now, and so on so that he rolls <math>a</math> dice <math>a</math> days from now. He gets tired rolling dice after rolling dice for 365 days (so the last day he rolls 365 dice). In Python, simulate this. How many times does he roll 3 after 365 days of rolling dice?'''<br />
<br />
We can use a for loop that calls a function multiple times.<br />
<br />
import random<br />
<br />
def roll():<br />
return random.randint(1,6)<br />
<br />
def count(amount):<br />
count_ = 0<br />
for i in range(1, amount+1):<br />
if roll() == 3:<br />
count_ += 1<br />
return count_<br />
<br />
total = 0<br />
<br />
for i in range(1, 366):<br />
total += count(i)<br />
<br />
print(total)<br />
<br />
This is a really long program, but the whole program should make sense if you look at it for a while. We defined our count function in the previous example, and now we are using it with a for loop and a running total. <br />
<br />
You should get a number around 11,000 when you run it. Wow, lots of 3's!<br />
<br />
===Program Example 5===<br />
<br />
'''20 of my friends love rolling dice. They are all going to roll 1 die each tomorrow, 2 dice each two days from now, 3 dice each three days from now, and so on so that they roll <math>a</math> dice each <math>a</math> days from now. But, one of my friends gets tired very quickly and he only rolls dice for 1 day and stops. Another friend only will roll dice for 2 days, and another will roll dice for three days only, and so on up to the fact that my last friend will roll dice for 20 days. In Python, simulate this. How many times does someone roll 3 after everything?'''<br />
<br />
We will have to make our for loop into a function again.<br />
<br />
import random<br />
<br />
def roll():<br />
return random.randint(1,6)<br />
<br />
def count(amount):<br />
count_ = 0<br />
for i in range(1, amount+1):<br />
if roll() == 3:<br />
count_ += 1<br />
return count_<br />
<br />
def count2(amount)<br />
total = 0<br />
for i in range(1, amount + 1):<br />
total += count(i)<br />
return total<br />
<br />
def count3(amount)<br />
total = 0<br />
for i in range(1, amount + 1):<br />
total += count2(i)<br />
return total<br />
<br />
print(count3(20))<br />
<br />
(Our program is so long!)<br />
<br />
I also made a new function just in case we needed to turn that into a function later.<br />
<br />
'''Make sure''' you read the code carefully and you fully understand it. If you don't understand every single line of code, then you will get confused later on in this article.<br />
<br />
When you run this program, you might be surprised that the answer isn't so big.<br />
<br />
===Program Example 6===<br />
<br />
'''365 of my friends love rolling dice. They are all going to roll 1 die each tomorrow, 2 dice each two days from now, 3 dice each three days from now, and so on so that they roll <math>a</math> dice each <math>a</math> days from now. But, one of my friends gets tired very quickly and he only rolls dice for 1 day and stops. Another friend only will roll dice for 2 days, and another will roll dice for three days only, and so on up to the fact that my last friend will roll dice for 365 days. In Python, simulate this. How many times does someone roll 3 after everything?'''<br />
<br />
Because we soft-coded our program so much, all we have to do is change the last line so the parameter of count3() is 365.<br />
<br />
If we run it...we get a big answer, as expected. It also takes quite a while!<br />
<br />
You may not have realized that we soft-coded our program at all, but the whole point of functions is to soft-code programs!<br />
<br />
Congrats on writing a program that is around 25 lines long!<br />
<br />
==Very Basic Datatypes==<br />
<br />
An integer is a basic datatype in Python. Basically, all variables with the datatype of '''int''' is an integer.<br />
<br />
A string is another basic datatype, and it is a string of characters enclosed by quotes.<br />
<br />
===Why Are Datatypes So Important?===<br />
<br />
Let's say we wanted to make a program that would add 2 and 3. Some bogus code would be:<br />
<br />
x="2"<br />
y="3"<br />
print(x+y)<br />
<br />
If you ran this code, you would get 23. Why is that?<br />
<br />
Well, here, x and y are strings. When you perform the addition operator to strings in Python, it concatenates the strings, giving 23.<br />
<br />
The real code is:<br />
<br />
x=2<br />
y=3<br />
print(x+y)<br />
<br />
If you run this, you will get <math>5</math>, which is correct.<br />
<br />
Here's another reason datatypes are important. Now, we will introduce the datatype called the '''floating point number''', or '''float'''. A floating-point number is a number with a decimal point.<br />
<br />
Let's go back to the IDLE. Type "0.1*10". The result is 1.0. Notice the decimal point.<br />
<br />
Let's type something different. Type <math>0.1+0.1+0.1+0.1+0.1+0.1+0.1+0.1+0.1+0.1.</math><br />
<br />
'''WHAT!?'''<br />
<br />
You would have expected the answer to be 1, but it isn't 1. What happened?<br />
<br />
'''Float approximation''' happened. Most (almost all) programming languages have a bad float approximation. That means that 1.0 can turn into 0.99999999999999 and 0.5 can turn into 0.49999999999999999993. That only happens with floats, so we should try to use floats as sparingly as possible.<br />
<br />
==Lists==<br />
<br />
A for loop iterates over a '''list'''. A list is a bunch of objects stored in one variable. (Hey! A list is a datatype!) For loops are highly related to lists.<br />
<br />
Let's say we wanted to make a program to print all the items in a list.<br />
<br />
We will first create the list, using the code:<br />
<br />
myList = [1,4,6,8]<br />
<br />
This is a list with four items: 1, 4, 6, and 8.<br />
<br />
We must now print all elements of it with a for loop:<br />
<br />
myList = [1,4,6,8]<br />
for i in myList:<br />
print(i)<br />
<br />
When we run this program, we get the numbers 1, 4, 6, and 8, as expected.<br />
<br />
===Accessing Values===<br />
<br />
Let's say we wanted to print out the second item in a list. We will use '''indexes'''.<br />
<br />
The index of the first item in a list is always 0. The index of the second is 1. The index of the <math>n</math>th is <math>n-1.</math><br />
<br />
To print out the second item, we will use an index of 1, like this:<br />
<br />
myList = [1,4,6,8]<br />
print(myList[1])<br />
<br />
Notice that the index is inside of the square brackets.<br />
<br />
===Adding Values===<br />
<br />
We can use the list.append() function to add an object to the end of a list.<br />
<br />
myList.append(10)<br />
<br />
will add 10 to the list, which makes myList = [1,4,6,8,10].<br />
<br />
===Removing Items From Lists===<br />
<br />
We can use the list.remove() function to remove a specific item in a list.<br />
<br />
For example, consider this code.<br />
<br />
myList = [1,2,3]<br />
myList.remove(3)<br />
<br />
This code will make myList turn into [1,2]. The element, 3, gets removed.<br />
<br />
===len(list)===<br />
<br />
The len(list) function returns the length of a list.<br />
<br />
This code will print 3.<br />
<br />
myList = [1,2,3]<br />
print(len(myList))<br />
<br />
The length of myList is 3, so Python prints 3.<br />
<br />
===All Kinds Of Lists===<br />
<br />
Lists don't have to be only integers!<br />
<br />
myList = [1,"Hi","Hello world", 3.5, 3.14159265358979323]<br />
<br />
If fact, there can be lists inside of lists!<br />
<br />
myList = [[1,2,3], [3,4,5], [5,6,"Hello world"], "BOB", 3.1415926]<br />
<br />
Even this!<br />
<br />
myList = [[1, [1, [1,2,3],3],3], [[[3,["Hello world", 4],5],4,5],4,5], [5,6,7,[1,[1,2,3],3],"Hello world"], "BOB", 3.1415926, True]<br />
<br />
If you look at that list carefully, you will find lists inside of lists inside of lists inside of lists! And, a boolean at the end!<br />
<br />
Like variables, you can have as many lists in a program as you want (a list is a variable)!<br />
<br />
myList = [1,2,3,4]<br />
yourList = [5,6,7,8]<br />
hisList = [9,10,11,12]<br />
herList = [13,14,15,16]<br />
theirList = [17,18,19,20]<br />
ourList = [21,22,23,24]<br />
listsOfLists = [[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16],[17,18,19,20],[21,22,23,24]]<br />
<br />
==Dictionaries==<br />
<br />
A dictionary (a type of datatype) is a bunch of keys and values. There is a major difference between dictionaries and lists. Lists are ordered; dictionaries are not.<br />
<br />
Here is the '''syntax''' of creating a dictionary:<br />
<br />
myDictionary = {1:"one",2:"two"}<br />
<br />
This dictionary has two key/value pairs. Notice it is surrounded in curly braces. The keys are 1 and 2; the values are "one" and "two."<br />
<br />
How is this useful? Let's make a simple program to test it out.<br />
<br />
myDictionary = {1:"one",2:"two"}<br />
print(myDictionary[1])<br />
print(myDictionary[2])<br />
<br />
===Accessing Values===<br />
<br />
To access a value in a dictionary, you put in the key.<br />
<br />
myDictionary[1]<br />
<br />
returns one, because 1 is the key to "one."<br />
<br />
===Adding New Values===<br />
<br />
To overwrite a value, we do this.<br />
<br />
myDictionary[1] = "won"<br />
<br />
The value to the key 1 is now "won."<br />
<br />
To add a value, we do the same thing!<br />
<br />
myDictionary[3] = "three"<br />
<br />
This adds a key 3 with a value of "three."<br />
<br />
==Misc Concepts==<br />
<br />
This section will talk about some concepts that we haven't learned yet.<br />
<br />
====Concatenating Strings====<br />
<br />
Concatenating strings is putting them together. For example, "one" concatenated with "two" gives "onetwo."<br />
<br />
The following string,<br />
<br />
"Hello, " + person2 + "! How are you?"<br />
<br />
depends on what person2 was. If person2 was Bob, the string would be:<br />
<br />
"Hello, Bob! How are you?"<br />
<br />
It fits together perfectly!<br />
<br />
You cannot concatenate strings with integers. For example, doing this:<br />
<br />
"2" + 3<br />
<br />
will not work. Instead, to get an answer of "23", you must do this:<br />
<br />
"2" + str(3)<br />
<br />
That turns 3 into a string so it is "3", and the result will be "23".<br />
<br />
====Line Breaks====<br />
<br />
We can use multiple line breaks to make our code more organized. There are some places that you cannot line break. For example, this code will produce an error:<br />
<br />
myList =<br />
[1,2,3]<br />
<br />
This code does not work.<br />
<br />
This code '''does work''':<br />
<br />
myList = [<br />
1,2,3]<br />
<br />
It is accepted when you break a line right after the [. It is also accepted right after a comma. (And right before the ending ].)<br />
<br />
myList = [<br />
1,<br />
2,<br />
3<br />
]<br />
<br />
==Challenge Program==<br />
<br />
In this section, we will attempt the hardest program so far in this article.<br />
<br />
'''Make a conversation generator that will generate random conversations between different people.'''<br />
<br />
First, we will generate the people. We can use a list and generate two random numbers.<br />
<br />
import random<br />
<br />
peopleNames = [<br />
"Bob",<br />
"Kyle",<br />
"James",<br />
"Richard",<br />
"Zachary",<br />
"Olivia",<br />
"Jonathan",<br />
"Will",<br />
"Bobby",<br />
"Kevin"<br />
]<br />
person1 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
peopleNames.remove(person1)<br />
person2 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
<br />
(I made it more organized by separating the long lines of code into multiple lines. It only works when you have a line break right after each item in the list.)<br />
<br />
Here, we use the remove() function to remove person1 from the list to make sure we don't use the same name twice. <br />
<br />
We also used the len() function to find the length of the list (soft-coding!)<br />
<br />
Now, we need to create a list of possible values for the first thing that person1 says (person1 will always be the first one to talk). <br />
<br />
Then, we will print it out.<br />
<br />
import random<br />
<br />
peopleNames = [<br />
"Bob",<br />
"Kyle",<br />
"James",<br />
"Richard",<br />
"Zachary",<br />
"Olivia",<br />
"Jonathan",<br />
"Will",<br />
"Bobby",<br />
"Kevin"<br />
]<br />
person1 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
peopleNames.remove(person1)<br />
person2 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
<br />
first = [<br />
"Hi!",<br />
"Hello!",<br />
"Good morning!",<br />
"Hello, " + person2 + "!",<br />
"Hi.",<br />
"Hi, " + person2 + "!"<br />
]<br />
print(person1 + ": " + first[random.randint(0, (len(first) - 1))])<br />
<br />
If we test out this program, we can confirm that this part indeed does work. This program is already getting long! Now, we will use the same method and create the second message.<br />
<br />
import random<br />
<br />
peopleNames = [<br />
"Bob",<br />
"Kyle",<br />
"James",<br />
"Richard",<br />
"Zachary",<br />
"Olivia",<br />
"Jonathan",<br />
"Will",<br />
"Bobby",<br />
"Kevin"<br />
]<br />
person1 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
peopleNames.remove(person1)<br />
person2 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
<br />
first = [<br />
"Hi!",<br />
"Hello!",<br />
"Good morning!",<br />
"Hello, " + person2 + "!",<br />
"Hi.",<br />
"Hi, " + person2 + "!"<br />
]<br />
print(person1 + ": " + first[random.randint(0, (len(first) - 1))])<br />
<br />
second = [<br />
"Hi! How are you today?",<br />
"Hello! How are you?",<br />
"Good morning! How are you today?",<br />
"Hello, " + person1 + "! How are you?",<br />
"Hi. How are you?",<br />
"Hi, " + person1 + "! How are you today?"<br />
]<br />
print(person2 + ": " + second[random.randint(0, (len(second) - 1))])<br />
<br />
We will repeat this for the rest of the conversation:<br />
<br />
import random<br />
<br />
peopleNames = [<br />
"Bob",<br />
"Kyle",<br />
"James",<br />
"Richard",<br />
"Zachary",<br />
"Olivia",<br />
"Jonathan",<br />
"Will", <br />
"Bobby",<br />
"Kevin"<br />
]<br />
person1 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
peopleNames.remove(person1)<br />
person2 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
<br />
first = [<br />
"Hi!",<br />
"Hello!",<br />
"Good morning!",<br />
"Hello, " + person2 + "!",<br />
"Hi.",<br />
"Hi, " + person2 + "!"<br />
]<br />
print(person1 + ": " + first[random.randint(0, (len(first) - 1))])<br />
<br />
second = [<br />
"Hi! How are you today?",<br />
"Hello! How are you?",<br />
"Good morning! How are you today?",<br />
"Hello, " + person1 + "! How are you?",<br />
"Hi. How are you?",<br />
"Hi, " + person1 + "! How are you today?"<br />
]<br />
print(person2 + ": " + second[random.randint(0, (len(second) - 1))])<br />
<br />
third = [<br />
"I'm feeling awesome! And you?",<br />
"I'm feeling alright! How are you?",<br />
"I'm good, thank you. How are you feeling?",<br />
"I'm fine!" ,<br />
"How are you today?"<br />
]<br />
print(person1 + ": " + third[random.randint(0, (len(third) - 1))])<br />
<br />
fourth = [<br />
"I'm feeling great!",<br />
"I'm awesome!",<br />
"Thanks for asking! I am feeling good today!",<br />
"I'm feeling awesome today! Yippee!"<br />
] <br />
print(person2 + ": " + fourth[random.randint(0, (len(fourth) - 1))])<br />
<br />
fifth = [<br />
"It's so nice out today!",<br />
"Today is such a cloudy day.",<br />
"I hate it when it is so cloudy outside!",<br />
"It's partly cloudy today!"<br />
]<br />
print(person1 + ": " + fifth[random.randint(0, (len(fifth) - 1))])<br />
<br />
sixth = [<br />
"I know, right?",<br />
"I know.",<br />
"Yeah!",<br />
"True."<br />
]<br />
print(person2 + ": " + sixth[random.randint(0, (len(sixth) - 1))])<br />
<br />
seventh = [<br />
"Sorry, I need to leave. Bye!",<br />
"I gotta go. Bye!",<br />
"Sorry, I don't have time to stay and chat. I've got to go somewhere. Bye!"<br />
]<br />
print(person1 + ": " + seventh[random.randint(0, (len(seventh) - 1))])<br />
<br />
eighth = [<br />
"Bye!",<br />
"Good-bye!",<br />
"Bye, " + person1 + "."<br />
]<br />
print(person2 + ": " + eighth[random.randint(0, (len(eighth) - 1))])<br />
<br />
Whew! So long!<br />
<br />
Once we run our program. It works! This program really wasn't that hard.<br />
<br />
Congrats! You've made it so far!</div>Anstarhttps://artofproblemsolving.com/wiki/index.php?title=Basic_Programming_With_Python&diff=121734Basic Programming With Python2020-04-27T05:07:47Z<p>Anstar: /* Functions */</p>
<hr />
<div>'''Important: It is extremely recommended that you read [[Getting Started With Python Programming]] before reading this unless you already know some programming knowledge.'''<br />
<br />
(Note: This is a really long article. To learn the most from this article, you need to read everything in order and skip nothing, unless you are '''absolutely absolutely sure that that content is way too easy for you.''')<br />
<br />
This article will talk about some basic Python programming. If you don't even know how to install Python, look [[Getting Started With Python Programming|here]].<br />
<br />
Note that this article has lots of program examples. It is recommended (but not required) to try these on your own before looking at the solutions.<br />
<br />
==Loops==<br />
<br />
There are two different kinds of loops in Python: the for loop and the while loop.<br />
<br />
===The For Loop===<br />
<br />
The for loop iterates over a list, or an array, of objects. You have probably seen this code before:<br />
<br />
[[File:Capture.PNG|200px]]<br />
<br />
This for loop iterates over the list of integers from 1 to 51, excluding the 51 and including the 1. That means it is a list from 1 to 50, inclusive. On every iteration, Python will print the number that the loop is iterating through. <br />
<br />
For example, in the first iteration, i = 1, so Python prints 1.<br />
<br />
In the second iteration, i = 2, so Python prints 2.<br />
<br />
This continues so on until the number, 50, is reached. Therefore, the last number Python will print out is 50.<br />
<br />
====Program Example====<br />
<br />
'''Find <math>\sum_{n=1}^{50} 2^{n}.</math>'''<br />
<br />
To do this task, we must create a for loop and loop over the integers from 1 to 50 inclusive:<br />
<br />
for i in range(1,51):<br />
<br />
Now what? We must keep a running total and increase it by <math>2^i</math> every time:<br />
<br />
total = 0<br />
for i in range(1,51):<br />
total += 2**i<br />
<br />
We must not forget to print the total at the end!<br />
<br />
total = 0<br />
for i in range(1,51):<br />
total += 2**i<br />
print(total)<br />
<br />
You must exit out of the for loop one you reach the print(total) line by pressing backspace.<br />
<br />
Once you run your program, you should get an answer of <math>\boxed{2,251,799,813,685,246.}</math><br />
<br />
===The While Loop===<br />
<br />
While loops don't loop over a list. They loop over and over and over...'''until'''...a condition becomes false.<br />
<br />
i = 3<br />
total = 0<br />
while i < 1000:<br />
total += i<br />
i += 3<br />
print(total)<br />
<br />
In this code, the while loop loops 333 times, until <math>i</math> becomes greater than or equal to 1000.<br />
<br />
====Program Example====<br />
<br />
'''Find <math>\sum_{n=1}^{50} 2^n</math> using a while loop.'''<br />
<br />
We must create a while loop that will iterate until n is greater than <math>50.</math><br />
<br />
n = 1<br />
total = 0<br />
while n <= 50:<br />
total += 2**n<br />
n += 1<br />
print(total)<br />
<br />
We must not forget to include the n += 1 line at the end of the while loop! <br />
<br />
If we run this, we will get the same answer as last time, <math>2,251,799,813,685,246.</math><br />
<br />
==Functions==<br />
<br />
In this section, we will define new operations and do arithmetic with them in Python.<br />
<br />
===The New Operation===<br />
Let's say that you defined a new binary operation, the <math>\uparrow \downarrow.</math> You want it to be so <math>a \uparrow \downarrow b = a^{b}b^{a}.</math> Therefore, <math>1\uparrow \downarrow 2 = 1^{2}2^{1}=1\cdot 2= 2,</math> and <math>2\uparrow \downarrow 3 = 2^33^2 = 8\cdot 9 = 72.</math> Let's call this operation an '''up down arrow.'''<br />
<br />
===Program Example 1===<br />
<br />
'''Find <math>[2 \uparrow \downarrow (1 \uparrow \downarrow 2)] \uparrow \downarrow 2.</math>'''<br />
<br />
We know this will be a big number, so we should write a program to do it! We certainly don't want to do the exponentiation and multiplication every time we use the operation in our program, and that's where functions come in! Functions can take in parameters (<math>a</math> and <math>b</math>) and return a result depending on the parameters.<br />
<br />
def up_down_arrow(a,b): <br />
return ((a**b) * (b**a))<br />
<br />
Above is the code to define our function. We need to print the final result at the end, so we must put a print statement at the end.<br />
<br />
def up_down_arrow(a,b): <br />
return ((a**b) * (b**a))<br />
print(up_down_arrow(up_down_arrow(2,up_down_arrow(1,2)),2)<br />
<br />
All those nested up_down_arrow's might be confusing at first, but it really isn't that confusing.<br />
If you run your program, you should get your answer: <math>16,777,216.</math> <br />
<br />
You might be surprised that the answer is so big. If you actually start calculating the real answer without a program, you will really quickly find that the final result is <math>16 \uparrow \downarrow 2,</math> which does turn out to be 16,777,216 if you use a calculator.<br />
<br />
Let's make another operation!<br />
<br />
We will define the operation <math>\uparrow \downarrow \leftarrow \rightarrow</math> to be called '''all around.''' <math>a \uparrow \downarrow \leftarrow \rightarrow b = (ab(a \uparrow \downarrow b))^2.</math> That's an operation that will make really big numbers!<br />
<br />
===Program Example 2===<br />
<br />
'''Find 87 all around 132.'''<br />
<br />
The answer is bound to be a huge number, so we must make a program to solve it.<br />
<br />
We will keep our up_down_arrow function because in the definition of our all_around function we will use it. Then, we will define the all_around function.<br />
<br />
def up_down_arrow(a,b):<br />
return ((a**b) * (b**a))<br />
def all_around(a,b):<br />
return ((a * b * up_down_arrow(a,b)) ** 2)<br />
<br />
We must print all_around(87,132) at the end. Once we do that, and we run our program, we get a super huge number that has over 800 digits!<br />
<br />
===Understanding Functions===<br />
<br />
Every single function has a '''return value'''. If a function does not return anything, the return value is '''null'''. Null is a term used in programming as a placeholder that stands for nothing.<br />
<br />
====Simple Program Example 1====<br />
<br />
'''Define a function that adds 1 to an input.'''<br />
<br />
How will the function know what number to add 1 to? We will input a '''parameter''' for the function to add 1 to.<br />
<br />
def add_one(x):<br />
return x + 1<br />
<br />
In this function, <math>x</math> is the parameter.<br />
<br />
def add_one(x):<br />
return x + 1<br />
print(add_one(2))<br />
<br />
In the print statement, we set <math>x</math> as 2, and the function returns <math>2 + 1 = 3,</math> so the program prints <math>3</math>.<br />
<br />
====Simple Program Example 2====<br />
<br />
'''Define a function that prints out an input.'''<br />
<br />
We will use a parameter again.<br />
<br />
def print_function(x):<br />
print(x)<br />
<br />
Uh oh! We have nothing to return! Therefore, we will return nothing (or null), by just writing return.<br />
<br />
def print_function(x):<br />
print(x)<br />
return<br />
print_function("print_function")<br />
<br />
This code prints out print_function. print_function() is said to be '''called''' in the final line of the code. Again, we set <math>x</math>, our parameter, as "print_function."<br />
== Classes ==<br />
Classes<br />
<br />
==Flow==<br />
<br />
Flow consists of if statements, elif (else if) statements, and else statements.<br />
<br />
*An if statement checks if a comparison is true.<br />
<br />
*An else statement checks if a comparison is not true. It is used after an if statement (and all elif statements after the if statement) and it shares the same comparison as the if statement.<br />
<br />
*An elif statement checks for two things: if a comparison is true, and if a comparison is not true. It is used right after the if statement.<br />
<br />
===Program Example===<br />
<br />
'''Does the number 10 have the property that when you multiply 10 by 5, you get a two digit number?'''<br />
<br />
This problem is super easy to solve without a program, but let's write a program to solve this anyway. We will use an if statement to check if <math>10\cdot 5</math> is less than 100 and greater than 9.<br />
<br />
if 10*5 > 9:<br />
if 10*5 < 100:<br />
print("Yes")<br />
else:<br />
print("No")<br />
else:<br />
print("No")<br />
<br />
This code means, if 10*5 > 9, then we will check if it is less than 100. If it is not greater than 9, however, we will print No. If it is greater than 9, we check if it is less than 100. If it is, we print Yes. If it isn't we print No.<br />
<br />
These nested if statements can be very confusing. Luckily, there is a faster an easier way to do this.<br />
<br />
if 10*5 > 9 and 10*5 < 100:<br />
print("Yes") <br />
else:<br />
print("No")<br />
<br />
This code checks for the two conditions at the same time. If we run it, we get our answer of Yes.<br />
<br />
==Booleans==<br />
<br />
===Program Example===<br />
<br />
'''Print all two-digit positive integers <math>x</math> such that <math>5x</math> is a two-digit positive integer.'''<br />
<br />
We can create a function with our previous code.<br />
<br />
We will have to slightly modify our function so we can use it in a for loop at the end:<br />
<br />
def check(a):<br />
if a*5 > 9 and a*5 < 100:<br />
return True <br />
else:<br />
return False<br />
<br />
True and False are what are called '''booleans'''. When an if or elif statement receives True, the code inside of the statement happens. When an if or elif statement receives False, the code inside of the statement does not happen. <br />
<br />
We must create a for loop that will iterate through all two digit positive integers. <br />
<br />
def check(a):<br />
if a*5 > 9 and a*5 < 100:<br />
return True <br />
else:<br />
return False<br />
for i in range(10,100):<br />
if check(i):<br />
print(i)<br />
<br />
The final for loop checks if <math>5i</math> is a two digit integer. If it is, the function returns True and the code inside the if statement gets run. If it isn't, the function returns False and the code inside the if statement gets ignored.<br />
<br />
If we run this, we will get the answer.<br />
<br />
All two digit integers from 10 to 19 inclusive work!<br />
<br />
=="Soft Coding" Programs==<br />
<br />
In the next few examples, you will see why hard coding programs is bad. Hard coding programs refers to coding a program that is hard to modify. For example:<br />
<br />
===Program Example 1===<br />
<br />
'''Print all two digit positive integers <math>x</math> such that <math>5x</math> is a three digit positive integer.'''<br />
<br />
We can keep our code and modify some parts of it.<br />
<br />
def check(a, min, max):<br />
if a*5 > min - 1 and a*5 < max + 1:<br />
return True <br />
else:<br />
return False<br />
<br />
def print_check(range_min, range_max, check_min, check_max):<br />
for i in range(range_min, range_max + 1):<br />
if check(i, check_min, check_max):<br />
print(i)<br />
return<br />
<br />
print_check(10, 99, 100, 999)<br />
<br />
Why did we add so many functions?<br />
<br />
Well, if the numbers in a problem change (and the words stay the same), and you need to change a lot of numbers in your program, your program is considered '''hard-coded'''. We want our programs to be as '''soft-coded''' as possible. In our new program, we only need to change 4 numbers (in the print_check() statement) if the numbers in the problem change. Therefore, our program is relatively soft-coded. There are still ways to soft-code this program even more, though.<br />
<br />
If we run our program, we get our answer.<br />
<br />
All numbers from 20 to 99 work!<br />
<br />
===Program Example 2===<br />
<br />
'''Print all three digit positive integers <math>x</math> such that <math>5x</math> is a three digit positive integer.'''<br />
<br />
We can just change the print_check line at the end to<br />
<br />
print_check(100, 999, 100, 999)<br />
<br />
and our program will be ready to be run.<br />
<br />
All numbers from 100 to 199 work.<br />
<br />
===Program Example 3===<br />
<br />
'''Print all two digit positive integers <math>x</math> such that <math>3x</math> is a three digit positive integer.'''<br />
<br />
Uh oh. Only changing the print_check line won't work. We will need to change our functions!<br />
<br />
def check(a, min, max, factor):<br />
if a*factor > min - 1 and a*factor < max + 1:<br />
return True <br />
else:<br />
return False<br />
<br />
def print_check(range_min, range_max, check_min, check_max, check_factor):<br />
for i in range(range_min, range_max + 1):<br />
if check(i, check_min, check_max, check_factor):<br />
print(i)<br />
return<br />
<br />
print_check(10, 99, 100, 999, 3)<br />
<br />
In this step, we added a parameter in both functions. We also soft-coded our program even more! Hooray!<br />
<br />
All integers from 34 to 99 work.<br />
<br />
===Program Example 4===<br />
<br />
'''Print all two digit positive integers <math>x</math> such that <math>12x</math> is a positive integer from 500 to 900.'''<br />
<br />
This problem may look a bit different from the other ones, but it really is the same thing, except that the factor is 12 and check_min and check_max are 500 and 900, respectively.<br />
<br />
Once we change the final print_check() line to satisfy our needs, we can run our program.<br />
<br />
All numbers from 42 to 75 work!<br />
<br />
Congrats! You have written your first programs above 10 lines of code!<br />
<br />
==Random==<br />
<br />
There is a package in Python that allows the use of random numbers.<br />
<br />
===Program Example 1===<br />
<br />
'''Generate a random number from 1 to 6.'''<br />
<br />
Easy peasy. We will just generate a random number from 1 to 6 with the package like this:<br />
<br />
import random<br />
print(random.randint(1,6))<br />
<br />
As you can see, when you run this program, you get a random number from 1 to 6.<br />
<br />
===Program Example 2===<br />
<br />
'''Simulate the rolling of 1000 dice. Now, count the number of times you roll 6. Print that number out.'''<br />
<br />
We can create a function that returns a random number from 1 to 6. Then, we can make a for loop that rolls the dice 1000 times and check if it is a 6.<br />
<br />
import random<br />
count = 0<br />
<br />
def roll():<br />
return random.randint(1,6)<br />
<br />
for i in range(1, 1001):<br />
if roll() == 6:<br />
count += 1<br />
<br />
print(count)<br />
<br />
If we run this, we will get a number around 170.<br />
<br />
===Program Example 3===<br />
<br />
'''Simulate the rolling of 10,000 dice. Now, count the amount of times you roll 3. Print that amount out.'''<br />
<br />
We can keep our roll function and our code inside the for loop, but we need to change our for loop statement.<br />
<br />
We can actually soft-code our program more. Let's turn the whole for loop into a function!<br />
<br />
import random<br />
<br />
def roll():<br />
return random.randint(1,6)<br />
<br />
def count(amount):<br />
count_ = 0<br />
<br />
for i in range(1, amount+1):<br />
if roll() == 3:<br />
count_ += 1<br />
return count_<br />
<br />
print(count(10000))<br />
<br />
If we run this code, it works.<br />
<br />
===Program Example 4===<br />
<br />
'''One of my friends loves rolling dice. He is going to roll 1 die tomorrow, 2 dice two days from now, 3 dice three days from now, and so on so that he rolls <math>a</math> dice <math>a</math> days from now. He gets tired rolling dice after rolling dice for 365 days (so the last day he rolls 365 dice). In Python, simulate this. How many times does he roll 3 after 365 days of rolling dice?'''<br />
<br />
We can use a for loop that calls a function multiple times.<br />
<br />
import random<br />
<br />
def roll():<br />
return random.randint(1,6)<br />
<br />
def count(amount):<br />
count_ = 0<br />
for i in range(1, amount+1):<br />
if roll() == 3:<br />
count_ += 1<br />
return count_<br />
<br />
total = 0<br />
<br />
for i in range(1, 366):<br />
total += count(i)<br />
<br />
print(total)<br />
<br />
This is a really long program, but the whole program should make sense if you look at it for a while. We defined our count function in the previous example, and now we are using it with a for loop and a running total. <br />
<br />
You should get a number around 11,000 when you run it. Wow, lots of 3's!<br />
<br />
===Program Example 5===<br />
<br />
'''20 of my friends love rolling dice. They are all going to roll 1 die each tomorrow, 2 dice each two days from now, 3 dice each three days from now, and so on so that they roll <math>a</math> dice each <math>a</math> days from now. But, one of my friends gets tired very quickly and he only rolls dice for 1 day and stops. Another friend only will roll dice for 2 days, and another will roll dice for three days only, and so on up to the fact that my last friend will roll dice for 20 days. In Python, simulate this. How many times does someone roll 3 after everything?'''<br />
<br />
We will have to make our for loop into a function again.<br />
<br />
import random<br />
<br />
def roll():<br />
return random.randint(1,6)<br />
<br />
def count(amount):<br />
count_ = 0<br />
for i in range(1, amount+1):<br />
if roll() == 3:<br />
count_ += 1<br />
return count_<br />
<br />
def count2(amount)<br />
total = 0<br />
for i in range(1, amount + 1):<br />
total += count(i)<br />
return total<br />
<br />
def count3(amount)<br />
total = 0<br />
for i in range(1, amount + 1):<br />
total += count2(i)<br />
return total<br />
<br />
print(count3(20))<br />
<br />
(Our program is so long!)<br />
<br />
I also made a new function just in case we needed to turn that into a function later.<br />
<br />
'''Make sure''' you read the code carefully and you fully understand it. If you don't understand every single line of code, then you will get confused later on in this article.<br />
<br />
When you run this program, you might be surprised that the answer isn't so big.<br />
<br />
===Program Example 6===<br />
<br />
'''365 of my friends love rolling dice. They are all going to roll 1 die each tomorrow, 2 dice each two days from now, 3 dice each three days from now, and so on so that they roll <math>a</math> dice each <math>a</math> days from now. But, one of my friends gets tired very quickly and he only rolls dice for 1 day and stops. Another friend only will roll dice for 2 days, and another will roll dice for three days only, and so on up to the fact that my last friend will roll dice for 365 days. In Python, simulate this. How many times does someone roll 3 after everything?'''<br />
<br />
Because we soft-coded our program so much, all we have to do is change the last line so the parameter of count3() is 365.<br />
<br />
If we run it...we get a big answer, as expected. It also takes quite a while!<br />
<br />
You may not have realized that we soft-coded our program at all, but the whole point of functions is to soft-code programs!<br />
<br />
Congrats on writing a program that is around 25 lines long!<br />
<br />
==Very Basic Datatypes==<br />
<br />
An integer is a basic datatype in Python. Basically, all variables with the datatype of '''int''' is an integer.<br />
<br />
A string is another basic datatype, and it is a string of characters enclosed by quotes.<br />
<br />
===Why Are Datatypes So Important?===<br />
<br />
Let's say we wanted to make a program that would add 2 and 3. Some bogus code would be:<br />
<br />
x="2"<br />
y="3"<br />
print(x+y)<br />
<br />
If you ran this code, you would get 23. Why is that?<br />
<br />
Well, here, x and y are strings. When you perform the addition operator to strings in Python, it concatenates the strings, giving 23.<br />
<br />
The real code is:<br />
<br />
x=2<br />
y=3<br />
print(x+y)<br />
<br />
If you run this, you will get <math>5</math>, which is correct.<br />
<br />
Here's another reason datatypes are important. Now, we will introduce the datatype called the '''floating point number''', or '''float'''. A floating-point number is a number with a decimal point.<br />
<br />
Let's go back to the IDLE. Type "0.1*10". The result is 1.0. Notice the decimal point.<br />
<br />
Let's type something different. Type <math>0.1+0.1+0.1+0.1+0.1+0.1+0.1+0.1+0.1+0.1.</math><br />
<br />
'''WHAT!?'''<br />
<br />
You would have expected the answer to be 1, but it isn't 1. What happened?<br />
<br />
'''Float approximation''' happened. Most (almost all) programming languages have a bad float approximation. That means that 1.0 can turn into 0.99999999999999 and 0.5 can turn into 0.49999999999999999993. That only happens with floats, so we should try to use floats as sparingly as possible.<br />
<br />
==Lists==<br />
<br />
A for loop iterates over a '''list'''. A list is a bunch of objects stored in one variable. (Hey! A list is a datatype!) For loops are highly related to lists.<br />
<br />
Let's say we wanted to make a program to print all the items in a list.<br />
<br />
We will first create the list, using the code:<br />
<br />
myList = [1,4,6,8]<br />
<br />
This is a list with four items: 1, 4, 6, and 8.<br />
<br />
We must now print all elements of it with a for loop:<br />
<br />
myList = [1,4,6,8]<br />
for i in myList:<br />
print(i)<br />
<br />
When we run this program, we get the numbers 1, 4, 6, and 8, as expected.<br />
<br />
===Accessing Values===<br />
<br />
Let's say we wanted to print out the second item in a list. We will use '''indexes'''.<br />
<br />
The index of the first item in a list is always 0. The index of the second is 1. The index of the <math>n</math>th is <math>n-1.</math><br />
<br />
To print out the second item, we will use an index of 1, like this:<br />
<br />
myList = [1,4,6,8]<br />
print(myList[1])<br />
<br />
Notice that the index is inside of the square brackets.<br />
<br />
===Adding Values===<br />
<br />
We can use the list.append() function to add an object to the end of a list.<br />
<br />
myList.append(10)<br />
<br />
will add 10 to the list, which makes myList = [1,4,6,8,10].<br />
<br />
===Removing Items From Lists===<br />
<br />
We can use the list.remove() function to remove a specific item in a list.<br />
<br />
For example, consider this code.<br />
<br />
myList = [1,2,3]<br />
myList.remove(3)<br />
<br />
This code will make myList turn into [1,2]. The element, 3, gets removed.<br />
<br />
===len(list)===<br />
<br />
The len(list) function returns the length of a list.<br />
<br />
This code will print 3.<br />
<br />
myList = [1,2,3]<br />
print(len(myList))<br />
<br />
The length of myList is 3, so Python prints 3.<br />
<br />
===All Kinds Of Lists===<br />
<br />
Lists don't have to be only integers!<br />
<br />
myList = [1,"Hi","Hello world", 3.5, 3.14159265358979323]<br />
<br />
If fact, there can be lists inside of lists!<br />
<br />
myList = [[1,2,3], [3,4,5], [5,6,"Hello world"], "BOB", 3.1415926]<br />
<br />
Even this!<br />
<br />
myList = [[1, [1, [1,2,3],3],3], [[[3,["Hello world", 4],5],4,5],4,5], [5,6,7,[1,[1,2,3],3],"Hello world"], "BOB", 3.1415926, True]<br />
<br />
If you look at that list carefully, you will find lists inside of lists inside of lists inside of lists! And, a boolean at the end!<br />
<br />
Like variables, you can have as many lists in a program as you want (a list is a variable)!<br />
<br />
myList = [1,2,3,4]<br />
yourList = [5,6,7,8]<br />
hisList = [9,10,11,12]<br />
herList = [13,14,15,16]<br />
theirList = [17,18,19,20]<br />
ourList = [21,22,23,24]<br />
listsOfLists = [[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16],[17,18,19,20],[21,22,23,24]]<br />
<br />
==Dictionaries==<br />
<br />
A dictionary (a type of datatype) is a bunch of keys and values. There is a major difference between dictionaries and lists. Lists are ordered; dictionaries are not.<br />
<br />
Here is the '''syntax''' of creating a dictionary:<br />
<br />
myDictionary = {1:"one",2:"two"}<br />
<br />
This dictionary has two key/value pairs. Notice it is surrounded in curly braces. The keys are 1 and 2; the values are "one" and "two."<br />
<br />
How is this useful? Let's make a simple program to test it out.<br />
<br />
myDictionary = {1:"one",2:"two"}<br />
print(myDictionary[1])<br />
print(myDictionary[2])<br />
<br />
===Accessing Values===<br />
<br />
To access a value in a dictionary, you put in the key.<br />
<br />
myDictionary[1]<br />
<br />
returns one, because 1 is the key to "one."<br />
<br />
===Adding New Values===<br />
<br />
To overwrite a value, we do this.<br />
<br />
myDictionary[1] = "won"<br />
<br />
The value to the key 1 is now "won."<br />
<br />
To add a value, we do the same thing!<br />
<br />
myDictionary[3] = "three"<br />
<br />
This adds a key 3 with a value of "three."<br />
<br />
==Misc Concepts==<br />
<br />
This section will talk about some concepts that we haven't learned yet.<br />
<br />
====Concatenating Strings====<br />
<br />
Concatenating strings is putting them together. For example, "one" concatenated with "two" gives "onetwo."<br />
<br />
The following string,<br />
<br />
"Hello, " + person2 + "! How are you?"<br />
<br />
depends on what person2 was. If person2 was Bob, the string would be:<br />
<br />
"Hello, Bob! How are you?"<br />
<br />
It fits together perfectly!<br />
<br />
You cannot concatenate strings with integers. For example, doing this:<br />
<br />
"2" + 3<br />
<br />
will not work. Instead, to get an answer of "23", you must do this:<br />
<br />
"2" + str(3)<br />
<br />
That turns 3 into a string so it is "3", and the result will be "23".<br />
<br />
====Line Breaks====<br />
<br />
We can use multiple line breaks to make our code more organized. There are some places that you cannot line break. For example, this code will produce an error:<br />
<br />
myList =<br />
[1,2,3]<br />
<br />
This code does not work.<br />
<br />
This code '''does work''':<br />
<br />
myList = [<br />
1,2,3]<br />
<br />
It is accepted when you break a line right after the [. It is also accepted right after a comma. (And right before the ending ].)<br />
<br />
myList = [<br />
1,<br />
2,<br />
3<br />
]<br />
<br />
==Challenge Program==<br />
<br />
In this section, we will attempt the hardest program so far in this article.<br />
<br />
'''Make a conversation generator that will generate random conversations between different people.'''<br />
<br />
First, we will generate the people. We can use a list and generate two random numbers.<br />
<br />
import random<br />
<br />
peopleNames = [<br />
"Bob",<br />
"Kyle",<br />
"James",<br />
"Richard",<br />
"Zachary",<br />
"Olivia",<br />
"Jonathan",<br />
"Will",<br />
"Bobby",<br />
"Kevin"<br />
]<br />
person1 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
peopleNames.remove(person1)<br />
person2 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
<br />
(I made it more organized by separating the long lines of code into multiple lines. It only works when you have a line break right after each item in the list.)<br />
<br />
Here, we use the remove() function to remove person1 from the list to make sure we don't use the same name twice. <br />
<br />
We also used the len() function to find the length of the list (soft-coding!)<br />
<br />
Now, we need to create a list of possible values for the first thing that person1 says (person1 will always be the first one to talk). <br />
<br />
Then, we will print it out.<br />
<br />
import random<br />
<br />
peopleNames = [<br />
"Bob",<br />
"Kyle",<br />
"James",<br />
"Richard",<br />
"Zachary",<br />
"Olivia",<br />
"Jonathan",<br />
"Will",<br />
"Bobby",<br />
"Kevin"<br />
]<br />
person1 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
peopleNames.remove(person1)<br />
person2 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
<br />
first = [<br />
"Hi!",<br />
"Hello!",<br />
"Good morning!",<br />
"Hello, " + person2 + "!",<br />
"Hi.",<br />
"Hi, " + person2 + "!"<br />
]<br />
print(person1 + ": " + first[random.randint(0, (len(first) - 1))])<br />
<br />
If we test out this program, we can confirm that this part indeed does work. This program is already getting long! Now, we will use the same method and create the second message.<br />
<br />
import random<br />
<br />
peopleNames = [<br />
"Bob",<br />
"Kyle",<br />
"James",<br />
"Richard",<br />
"Zachary",<br />
"Olivia",<br />
"Jonathan",<br />
"Will",<br />
"Bobby",<br />
"Kevin"<br />
]<br />
person1 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
peopleNames.remove(person1)<br />
person2 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
<br />
first = [<br />
"Hi!",<br />
"Hello!",<br />
"Good morning!",<br />
"Hello, " + person2 + "!",<br />
"Hi.",<br />
"Hi, " + person2 + "!"<br />
]<br />
print(person1 + ": " + first[random.randint(0, (len(first) - 1))])<br />
<br />
second = [<br />
"Hi! How are you today?",<br />
"Hello! How are you?",<br />
"Good morning! How are you today?",<br />
"Hello, " + person1 + "! How are you?",<br />
"Hi. How are you?",<br />
"Hi, " + person1 + "! How are you today?"<br />
]<br />
print(person2 + ": " + second[random.randint(0, (len(second) - 1))])<br />
<br />
We will repeat this for the rest of the conversation:<br />
<br />
import random<br />
<br />
peopleNames = [<br />
"Bob",<br />
"Kyle",<br />
"James",<br />
"Richard",<br />
"Zachary",<br />
"Olivia",<br />
"Jonathan",<br />
"Will", <br />
"Bobby",<br />
"Kevin"<br />
]<br />
person1 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
peopleNames.remove(person1)<br />
person2 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
<br />
first = [<br />
"Hi!",<br />
"Hello!",<br />
"Good morning!",<br />
"Hello, " + person2 + "!",<br />
"Hi.",<br />
"Hi, " + person2 + "!"<br />
]<br />
print(person1 + ": " + first[random.randint(0, (len(first) - 1))])<br />
<br />
second = [<br />
"Hi! How are you today?",<br />
"Hello! How are you?",<br />
"Good morning! How are you today?",<br />
"Hello, " + person1 + "! How are you?",<br />
"Hi. How are you?",<br />
"Hi, " + person1 + "! How are you today?"<br />
]<br />
print(person2 + ": " + second[random.randint(0, (len(second) - 1))])<br />
<br />
third = [<br />
"I'm feeling awesome! And you?",<br />
"I'm feeling alright! How are you?",<br />
"I'm good, thank you. How are you feeling?",<br />
"I'm fine!" ,<br />
"How are you today?"<br />
]<br />
print(person1 + ": " + third[random.randint(0, (len(third) - 1))])<br />
<br />
fourth = [<br />
"I'm feeling great!",<br />
"I'm awesome!",<br />
"Thanks for asking! I am feeling good today!",<br />
"I'm feeling awesome today! Yippee!"<br />
] <br />
print(person2 + ": " + fourth[random.randint(0, (len(fourth) - 1))])<br />
<br />
fifth = [<br />
"It's so nice out today!",<br />
"Today is such a cloudy day.",<br />
"I hate it when it is so cloudy outside!",<br />
"It's partly cloudy today!"<br />
]<br />
print(person1 + ": " + fifth[random.randint(0, (len(fifth) - 1))])<br />
<br />
sixth = [<br />
"I know, right?",<br />
"I know.",<br />
"Yeah!",<br />
"True."<br />
]<br />
print(person2 + ": " + sixth[random.randint(0, (len(sixth) - 1))])<br />
<br />
seventh = [<br />
"Sorry, I need to leave. Bye!",<br />
"I gotta go. Bye!",<br />
"Sorry, I don't have time to stay and chat. I've got to go somewhere. Bye!"<br />
]<br />
print(person1 + ": " + seventh[random.randint(0, (len(seventh) - 1))])<br />
<br />
eighth = [<br />
"Bye!",<br />
"Good-bye!",<br />
"Bye, " + person1 + "."<br />
]<br />
print(person2 + ": " + eighth[random.randint(0, (len(eighth) - 1))])<br />
<br />
Whew! So long!<br />
<br />
Once we run our program. It works! This program really wasn't that hard.<br />
<br />
Congrats! You've made it so far!</div>Anstarhttps://artofproblemsolving.com/wiki/index.php?title=Basic_Programming_With_Python&diff=121733Basic Programming With Python2020-04-27T05:06:09Z<p>Anstar: Grammatical changes</p>
<hr />
<div>'''Important: It is extremely recommended that you read [[Getting Started With Python Programming]] before reading this unless you already know some programming knowledge.'''<br />
<br />
(Note: This is a really long article. To learn the most from this article, you need to read everything in order and skip nothing, unless you are '''absolutely absolutely sure that that content is way too easy for you.''')<br />
<br />
This article will talk about some basic Python programming. If you don't even know how to install Python, look [[Getting Started With Python Programming|here]].<br />
<br />
Note that this article has lots of program examples. It is recommended (but not required) to try these on your own before looking at the solutions.<br />
<br />
==Loops==<br />
<br />
There are two different kinds of loops in Python: the for loop and the while loop.<br />
<br />
===The For Loop===<br />
<br />
The for loop iterates over a list, or an array, of objects. You have probably seen this code before:<br />
<br />
[[File:Capture.PNG|200px]]<br />
<br />
This for loop iterates over the list of integers from 1 to 51, excluding the 51 and including the 1. That means it is a list from 1 to 50, inclusive. On every iteration, Python will print the number that the loop is iterating through. <br />
<br />
For example, in the first iteration, i = 1, so Python prints 1.<br />
<br />
In the second iteration, i = 2, so Python prints 2.<br />
<br />
This continues so on until the number, 50, is reached. Therefore, the last number Python will print out is 50.<br />
<br />
====Program Example====<br />
<br />
'''Find <math>\sum_{n=1}^{50} 2^{n}.</math>'''<br />
<br />
To do this task, we must create a for loop and loop over the integers from 1 to 50 inclusive:<br />
<br />
for i in range(1,51):<br />
<br />
Now what? We must keep a running total and increase it by <math>2^i</math> every time:<br />
<br />
total = 0<br />
for i in range(1,51):<br />
total += 2**i<br />
<br />
We must not forget to print the total at the end!<br />
<br />
total = 0<br />
for i in range(1,51):<br />
total += 2**i<br />
print(total)<br />
<br />
You must exit out of the for loop one you reach the print(total) line by pressing backspace.<br />
<br />
Once you run your program, you should get an answer of <math>\boxed{2,251,799,813,685,246.}</math><br />
<br />
===The While Loop===<br />
<br />
While loops don't loop over a list. They loop over and over and over...'''until'''...a condition becomes false.<br />
<br />
i = 3<br />
total = 0<br />
while i < 1000:<br />
total += i<br />
i += 3<br />
print(total)<br />
<br />
In this code, the while loop loops 333 times, until <math>i</math> becomes greater than or equal to 1000.<br />
<br />
====Program Example====<br />
<br />
'''Find <math>\sum_{n=1}^{50} 2^n</math> using a while loop.'''<br />
<br />
We must create a while loop that will iterate until n is greater than <math>50.</math><br />
<br />
n = 1<br />
total = 0<br />
while n <= 50:<br />
total += 2**n<br />
n += 1<br />
print(total)<br />
<br />
We must not forget to include the n += 1 line at the end of the while loop! <br />
<br />
If we run this, we will get the same answer as last time, <math>2,251,799,813,685,246.</math><br />
<br />
==Functions==<br />
<br />
In this section, we will define new operations and do arithmetic with them in Python.<br />
<br />
===The New Operation===<br />
Let's say that you defined a new binary operation, the <math>\uparrow \downarrow.</math> You want it to be so <math>a \uparrow \downarrow b = a^{b}b^{a}.</math> Therefore, <math>1\uparrow \downarrow 2 = 1^{2}2^{1}=1\cdot 2= 2,</math> and <math>2\uparrow \downarrow 3 = 2^33^2 = 8\cdot 9 = 72.</math> Let's call this operation an '''up down arrow.'''<br />
<br />
===Program Example 1===<br />
<br />
'''Find <math>[2 \uparrow \downarrow (1 \uparrow \downarrow 2)] \uparrow \downarrow 2.</math>'''<br />
<br />
We know this will be a big number, so we should write a program to do it! We certainly don't want to do the exponentiation and multiplication every time we use the operation in our program, and that's where functions come in! Functions can take in parameters (<math>a</math> and <math>b</math>) and return a result depending on the parameters.<br />
<br />
def up_down_arrow(a,b): <br />
return ((a**b) * (b**a))<br />
<br />
Above is the code to define our function. We need to print the final result at the end, so we must put a print statement at the end.<br />
<br />
def up_down_arrow(a,b): <br />
return ((a**b) * (b**a))<br />
print(up_down_arrow(up_down_arrow(2,up_down_arrow(1,2)),2)<br />
<br />
All those nested up_down_arrow's might be confusing at first, but it really isn't that confusing.<br />
If you run your program, you should get your answer: <math>16,777,216.</math> <br />
<br />
You might be surprised that the answer is so big. If you actually start calculating the real answer without a program, you will really quickly find that the final result is <math>16 \uparrow \downarrow 2,</math> which does turn out to be 16,777,216 if you use a calculator.<br />
<br />
Let's make another operation!<br />
<br />
We will define the operation <math>\uparrow \downarrow \leftarrow \rightarrow</math> to be called '''all around.''' <math>a \uparrow \downarrow \leftarrow \rightarrow b = (ab(a \uparrow \downarrow b))^2.</math> That's an operation that will make really big numbers!<br />
<br />
===Program Example 2===<br />
<br />
'''Find 87 all around 132.'''<br />
<br />
The answer is bound to be a huge number, so we must make a program to solve it.<br />
<br />
We will keep our up_down_arrow function because in the definition of our all_around function we will use it. Then, we will define the all_around function.<br />
<br />
def up_down_arrow(a,b):<br />
return ((a**b) * (b**a))<br />
def all_around(a,b):<br />
return ((a * b * up_down_arrow(a,b)) ** 2)<br />
<br />
We must print all_around(87,132) at the end. Once we do that, and we run our program, we get a super huge number that has over 800 digits!<br />
<br />
===Understanding Functions===<br />
<br />
Every single function has a '''return value'''. If a function does not return anything, the return value is '''null'''. Null is a term used in programming as a placeholder that stands for nothing.<br />
<br />
====Simple Program Example 1====<br />
<br />
'''Define a function that adds 1 to an input.'''<br />
<br />
How will the function know what number to add 1 to? We will input a '''parameter''' for the function to add 1 to.<br />
<br />
def add_one(x):<br />
return x + 1<br />
<br />
In this function, <math>x</math> is the parameter.<br />
<br />
def add_one(x):<br />
return x + 1<br />
print(add_one(2))<br />
<br />
In the print statement, we set <math>x</math> as 2, and the function returns <math>2 + 1 = 3,</math> so the program prints <math>3</math>.<br />
<br />
====Simple Program Example 2====<br />
<br />
'''Define a function that prints out an input.'''<br />
<br />
We will use a parameter again.<br />
<br />
def print_function(x):<br />
print(x)<br />
<br />
Uh oh! We have nothing to return! Therefore, we will return nothing (or null), by just writing return.<br />
<br />
def print_function(x):<br />
print(x)<br />
return<br />
print_function("print_function")<br />
<br />
This code prints out print_function. print_function() is said to be '''called''' in the final line of the code. Again, we set <math>x</math>, our parameter, as "print_function."<br />
<br />
==Flow==<br />
<br />
Flow consists of if statements, elif (else if) statements, and else statements.<br />
<br />
*An if statement checks if a comparison is true.<br />
<br />
*An else statement checks if a comparison is not true. It is used after an if statement (and all elif statements after the if statement) and it shares the same comparison as the if statement.<br />
<br />
*An elif statement checks for two things: if a comparison is true, and if a comparison is not true. It is used right after the if statement.<br />
<br />
===Program Example===<br />
<br />
'''Does the number 10 have the property that when you multiply 10 by 5, you get a two digit number?'''<br />
<br />
This problem is super easy to solve without a program, but let's write a program to solve this anyway. We will use an if statement to check if <math>10\cdot 5</math> is less than 100 and greater than 9.<br />
<br />
if 10*5 > 9:<br />
if 10*5 < 100:<br />
print("Yes")<br />
else:<br />
print("No")<br />
else:<br />
print("No")<br />
<br />
This code means, if 10*5 > 9, then we will check if it is less than 100. If it is not greater than 9, however, we will print No. If it is greater than 9, we check if it is less than 100. If it is, we print Yes. If it isn't we print No.<br />
<br />
These nested if statements can be very confusing. Luckily, there is a faster an easier way to do this.<br />
<br />
if 10*5 > 9 and 10*5 < 100:<br />
print("Yes") <br />
else:<br />
print("No")<br />
<br />
This code checks for the two conditions at the same time. If we run it, we get our answer of Yes.<br />
<br />
==Booleans==<br />
<br />
===Program Example===<br />
<br />
'''Print all two-digit positive integers <math>x</math> such that <math>5x</math> is a two-digit positive integer.'''<br />
<br />
We can create a function with our previous code.<br />
<br />
We will have to slightly modify our function so we can use it in a for loop at the end:<br />
<br />
def check(a):<br />
if a*5 > 9 and a*5 < 100:<br />
return True <br />
else:<br />
return False<br />
<br />
True and False are what are called '''booleans'''. When an if or elif statement receives True, the code inside of the statement happens. When an if or elif statement receives False, the code inside of the statement does not happen. <br />
<br />
We must create a for loop that will iterate through all two digit positive integers. <br />
<br />
def check(a):<br />
if a*5 > 9 and a*5 < 100:<br />
return True <br />
else:<br />
return False<br />
for i in range(10,100):<br />
if check(i):<br />
print(i)<br />
<br />
The final for loop checks if <math>5i</math> is a two digit integer. If it is, the function returns True and the code inside the if statement gets run. If it isn't, the function returns False and the code inside the if statement gets ignored.<br />
<br />
If we run this, we will get the answer.<br />
<br />
All two digit integers from 10 to 19 inclusive work!<br />
<br />
=="Soft Coding" Programs==<br />
<br />
In the next few examples, you will see why hard coding programs is bad. Hard coding programs refers to coding a program that is hard to modify. For example:<br />
<br />
===Program Example 1===<br />
<br />
'''Print all two digit positive integers <math>x</math> such that <math>5x</math> is a three digit positive integer.'''<br />
<br />
We can keep our code and modify some parts of it.<br />
<br />
def check(a, min, max):<br />
if a*5 > min - 1 and a*5 < max + 1:<br />
return True <br />
else:<br />
return False<br />
<br />
def print_check(range_min, range_max, check_min, check_max):<br />
for i in range(range_min, range_max + 1):<br />
if check(i, check_min, check_max):<br />
print(i)<br />
return<br />
<br />
print_check(10, 99, 100, 999)<br />
<br />
Why did we add so many functions?<br />
<br />
Well, if the numbers in a problem change (and the words stay the same), and you need to change a lot of numbers in your program, your program is considered '''hard-coded'''. We want our programs to be as '''soft-coded''' as possible. In our new program, we only need to change 4 numbers (in the print_check() statement) if the numbers in the problem change. Therefore, our program is relatively soft-coded. There are still ways to soft-code this program even more, though.<br />
<br />
If we run our program, we get our answer.<br />
<br />
All numbers from 20 to 99 work!<br />
<br />
===Program Example 2===<br />
<br />
'''Print all three digit positive integers <math>x</math> such that <math>5x</math> is a three digit positive integer.'''<br />
<br />
We can just change the print_check line at the end to<br />
<br />
print_check(100, 999, 100, 999)<br />
<br />
and our program will be ready to be run.<br />
<br />
All numbers from 100 to 199 work.<br />
<br />
===Program Example 3===<br />
<br />
'''Print all two digit positive integers <math>x</math> such that <math>3x</math> is a three digit positive integer.'''<br />
<br />
Uh oh. Only changing the print_check line won't work. We will need to change our functions!<br />
<br />
def check(a, min, max, factor):<br />
if a*factor > min - 1 and a*factor < max + 1:<br />
return True <br />
else:<br />
return False<br />
<br />
def print_check(range_min, range_max, check_min, check_max, check_factor):<br />
for i in range(range_min, range_max + 1):<br />
if check(i, check_min, check_max, check_factor):<br />
print(i)<br />
return<br />
<br />
print_check(10, 99, 100, 999, 3)<br />
<br />
In this step, we added a parameter in both functions. We also soft-coded our program even more! Hooray!<br />
<br />
All integers from 34 to 99 work.<br />
<br />
===Program Example 4===<br />
<br />
'''Print all two digit positive integers <math>x</math> such that <math>12x</math> is a positive integer from 500 to 900.'''<br />
<br />
This problem may look a bit different from the other ones, but it really is the same thing, except that the factor is 12 and check_min and check_max are 500 and 900, respectively.<br />
<br />
Once we change the final print_check() line to satisfy our needs, we can run our program.<br />
<br />
All numbers from 42 to 75 work!<br />
<br />
Congrats! You have written your first programs above 10 lines of code!<br />
<br />
==Random==<br />
<br />
There is a package in Python that allows the use of random numbers.<br />
<br />
===Program Example 1===<br />
<br />
'''Generate a random number from 1 to 6.'''<br />
<br />
Easy peasy. We will just generate a random number from 1 to 6 with the package like this:<br />
<br />
import random<br />
print(random.randint(1,6))<br />
<br />
As you can see, when you run this program, you get a random number from 1 to 6.<br />
<br />
===Program Example 2===<br />
<br />
'''Simulate the rolling of 1000 dice. Now, count the number of times you roll 6. Print that number out.'''<br />
<br />
We can create a function that returns a random number from 1 to 6. Then, we can make a for loop that rolls the dice 1000 times and check if it is a 6.<br />
<br />
import random<br />
count = 0<br />
<br />
def roll():<br />
return random.randint(1,6)<br />
<br />
for i in range(1, 1001):<br />
if roll() == 6:<br />
count += 1<br />
<br />
print(count)<br />
<br />
If we run this, we will get a number around 170.<br />
<br />
===Program Example 3===<br />
<br />
'''Simulate the rolling of 10,000 dice. Now, count the amount of times you roll 3. Print that amount out.'''<br />
<br />
We can keep our roll function and our code inside the for loop, but we need to change our for loop statement.<br />
<br />
We can actually soft-code our program more. Let's turn the whole for loop into a function!<br />
<br />
import random<br />
<br />
def roll():<br />
return random.randint(1,6)<br />
<br />
def count(amount):<br />
count_ = 0<br />
<br />
for i in range(1, amount+1):<br />
if roll() == 3:<br />
count_ += 1<br />
return count_<br />
<br />
print(count(10000))<br />
<br />
If we run this code, it works.<br />
<br />
===Program Example 4===<br />
<br />
'''One of my friends loves rolling dice. He is going to roll 1 die tomorrow, 2 dice two days from now, 3 dice three days from now, and so on so that he rolls <math>a</math> dice <math>a</math> days from now. He gets tired rolling dice after rolling dice for 365 days (so the last day he rolls 365 dice). In Python, simulate this. How many times does he roll 3 after 365 days of rolling dice?'''<br />
<br />
We can use a for loop that calls a function multiple times.<br />
<br />
import random<br />
<br />
def roll():<br />
return random.randint(1,6)<br />
<br />
def count(amount):<br />
count_ = 0<br />
for i in range(1, amount+1):<br />
if roll() == 3:<br />
count_ += 1<br />
return count_<br />
<br />
total = 0<br />
<br />
for i in range(1, 366):<br />
total += count(i)<br />
<br />
print(total)<br />
<br />
This is a really long program, but the whole program should make sense if you look at it for a while. We defined our count function in the previous example, and now we are using it with a for loop and a running total. <br />
<br />
You should get a number around 11,000 when you run it. Wow, lots of 3's!<br />
<br />
===Program Example 5===<br />
<br />
'''20 of my friends love rolling dice. They are all going to roll 1 die each tomorrow, 2 dice each two days from now, 3 dice each three days from now, and so on so that they roll <math>a</math> dice each <math>a</math> days from now. But, one of my friends gets tired very quickly and he only rolls dice for 1 day and stops. Another friend only will roll dice for 2 days, and another will roll dice for three days only, and so on up to the fact that my last friend will roll dice for 20 days. In Python, simulate this. How many times does someone roll 3 after everything?'''<br />
<br />
We will have to make our for loop into a function again.<br />
<br />
import random<br />
<br />
def roll():<br />
return random.randint(1,6)<br />
<br />
def count(amount):<br />
count_ = 0<br />
for i in range(1, amount+1):<br />
if roll() == 3:<br />
count_ += 1<br />
return count_<br />
<br />
def count2(amount)<br />
total = 0<br />
for i in range(1, amount + 1):<br />
total += count(i)<br />
return total<br />
<br />
def count3(amount)<br />
total = 0<br />
for i in range(1, amount + 1):<br />
total += count2(i)<br />
return total<br />
<br />
print(count3(20))<br />
<br />
(Our program is so long!)<br />
<br />
I also made a new function just in case we needed to turn that into a function later.<br />
<br />
'''Make sure''' you read the code carefully and you fully understand it. If you don't understand every single line of code, then you will get confused later on in this article.<br />
<br />
When you run this program, you might be surprised that the answer isn't so big.<br />
<br />
===Program Example 6===<br />
<br />
'''365 of my friends love rolling dice. They are all going to roll 1 die each tomorrow, 2 dice each two days from now, 3 dice each three days from now, and so on so that they roll <math>a</math> dice each <math>a</math> days from now. But, one of my friends gets tired very quickly and he only rolls dice for 1 day and stops. Another friend only will roll dice for 2 days, and another will roll dice for three days only, and so on up to the fact that my last friend will roll dice for 365 days. In Python, simulate this. How many times does someone roll 3 after everything?'''<br />
<br />
Because we soft-coded our program so much, all we have to do is change the last line so the parameter of count3() is 365.<br />
<br />
If we run it...we get a big answer, as expected. It also takes quite a while!<br />
<br />
You may not have realized that we soft-coded our program at all, but the whole point of functions is to soft-code programs!<br />
<br />
Congrats on writing a program that is around 25 lines long!<br />
<br />
==Very Basic Datatypes==<br />
<br />
An integer is a basic datatype in Python. Basically, all variables with the datatype of '''int''' is an integer.<br />
<br />
A string is another basic datatype, and it is a string of characters enclosed by quotes.<br />
<br />
===Why Are Datatypes So Important?===<br />
<br />
Let's say we wanted to make a program that would add 2 and 3. Some bogus code would be:<br />
<br />
x="2"<br />
y="3"<br />
print(x+y)<br />
<br />
If you ran this code, you would get 23. Why is that?<br />
<br />
Well, here, x and y are strings. When you perform the addition operator to strings in Python, it concatenates the strings, giving 23.<br />
<br />
The real code is:<br />
<br />
x=2<br />
y=3<br />
print(x+y)<br />
<br />
If you run this, you will get <math>5</math>, which is correct.<br />
<br />
Here's another reason datatypes are important. Now, we will introduce the datatype called the '''floating point number''', or '''float'''. A floating-point number is a number with a decimal point.<br />
<br />
Let's go back to the IDLE. Type "0.1*10". The result is 1.0. Notice the decimal point.<br />
<br />
Let's type something different. Type <math>0.1+0.1+0.1+0.1+0.1+0.1+0.1+0.1+0.1+0.1.</math><br />
<br />
'''WHAT!?'''<br />
<br />
You would have expected the answer to be 1, but it isn't 1. What happened?<br />
<br />
'''Float approximation''' happened. Most (almost all) programming languages have a bad float approximation. That means that 1.0 can turn into 0.99999999999999 and 0.5 can turn into 0.49999999999999999993. That only happens with floats, so we should try to use floats as sparingly as possible.<br />
<br />
==Lists==<br />
<br />
A for loop iterates over a '''list'''. A list is a bunch of objects stored in one variable. (Hey! A list is a datatype!) For loops are highly related to lists.<br />
<br />
Let's say we wanted to make a program to print all the items in a list.<br />
<br />
We will first create the list, using the code:<br />
<br />
myList = [1,4,6,8]<br />
<br />
This is a list with four items: 1, 4, 6, and 8.<br />
<br />
We must now print all elements of it with a for loop:<br />
<br />
myList = [1,4,6,8]<br />
for i in myList:<br />
print(i)<br />
<br />
When we run this program, we get the numbers 1, 4, 6, and 8, as expected.<br />
<br />
===Accessing Values===<br />
<br />
Let's say we wanted to print out the second item in a list. We will use '''indexes'''.<br />
<br />
The index of the first item in a list is always 0. The index of the second is 1. The index of the <math>n</math>th is <math>n-1.</math><br />
<br />
To print out the second item, we will use an index of 1, like this:<br />
<br />
myList = [1,4,6,8]<br />
print(myList[1])<br />
<br />
Notice that the index is inside of the square brackets.<br />
<br />
===Adding Values===<br />
<br />
We can use the list.append() function to add an object to the end of a list.<br />
<br />
myList.append(10)<br />
<br />
will add 10 to the list, which makes myList = [1,4,6,8,10].<br />
<br />
===Removing Items From Lists===<br />
<br />
We can use the list.remove() function to remove a specific item in a list.<br />
<br />
For example, consider this code.<br />
<br />
myList = [1,2,3]<br />
myList.remove(3)<br />
<br />
This code will make myList turn into [1,2]. The element, 3, gets removed.<br />
<br />
===len(list)===<br />
<br />
The len(list) function returns the length of a list.<br />
<br />
This code will print 3.<br />
<br />
myList = [1,2,3]<br />
print(len(myList))<br />
<br />
The length of myList is 3, so Python prints 3.<br />
<br />
===All Kinds Of Lists===<br />
<br />
Lists don't have to be only integers!<br />
<br />
myList = [1,"Hi","Hello world", 3.5, 3.14159265358979323]<br />
<br />
If fact, there can be lists inside of lists!<br />
<br />
myList = [[1,2,3], [3,4,5], [5,6,"Hello world"], "BOB", 3.1415926]<br />
<br />
Even this!<br />
<br />
myList = [[1, [1, [1,2,3],3],3], [[[3,["Hello world", 4],5],4,5],4,5], [5,6,7,[1,[1,2,3],3],"Hello world"], "BOB", 3.1415926, True]<br />
<br />
If you look at that list carefully, you will find lists inside of lists inside of lists inside of lists! And, a boolean at the end!<br />
<br />
Like variables, you can have as many lists in a program as you want (a list is a variable)!<br />
<br />
myList = [1,2,3,4]<br />
yourList = [5,6,7,8]<br />
hisList = [9,10,11,12]<br />
herList = [13,14,15,16]<br />
theirList = [17,18,19,20]<br />
ourList = [21,22,23,24]<br />
listsOfLists = [[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16],[17,18,19,20],[21,22,23,24]]<br />
<br />
==Dictionaries==<br />
<br />
A dictionary (a type of datatype) is a bunch of keys and values. There is a major difference between dictionaries and lists. Lists are ordered; dictionaries are not.<br />
<br />
Here is the '''syntax''' of creating a dictionary:<br />
<br />
myDictionary = {1:"one",2:"two"}<br />
<br />
This dictionary has two key/value pairs. Notice it is surrounded in curly braces. The keys are 1 and 2; the values are "one" and "two."<br />
<br />
How is this useful? Let's make a simple program to test it out.<br />
<br />
myDictionary = {1:"one",2:"two"}<br />
print(myDictionary[1])<br />
print(myDictionary[2])<br />
<br />
===Accessing Values===<br />
<br />
To access a value in a dictionary, you put in the key.<br />
<br />
myDictionary[1]<br />
<br />
returns one, because 1 is the key to "one."<br />
<br />
===Adding New Values===<br />
<br />
To overwrite a value, we do this.<br />
<br />
myDictionary[1] = "won"<br />
<br />
The value to the key 1 is now "won."<br />
<br />
To add a value, we do the same thing!<br />
<br />
myDictionary[3] = "three"<br />
<br />
This adds a key 3 with a value of "three."<br />
<br />
==Misc Concepts==<br />
<br />
This section will talk about some concepts that we haven't learned yet.<br />
<br />
====Concatenating Strings====<br />
<br />
Concatenating strings is putting them together. For example, "one" concatenated with "two" gives "onetwo."<br />
<br />
The following string,<br />
<br />
"Hello, " + person2 + "! How are you?"<br />
<br />
depends on what person2 was. If person2 was Bob, the string would be:<br />
<br />
"Hello, Bob! How are you?"<br />
<br />
It fits together perfectly!<br />
<br />
You cannot concatenate strings with integers. For example, doing this:<br />
<br />
"2" + 3<br />
<br />
will not work. Instead, to get an answer of "23", you must do this:<br />
<br />
"2" + str(3)<br />
<br />
That turns 3 into a string so it is "3", and the result will be "23".<br />
<br />
====Line Breaks====<br />
<br />
We can use multiple line breaks to make our code more organized. There are some places that you cannot line break. For example, this code will produce an error:<br />
<br />
myList =<br />
[1,2,3]<br />
<br />
This code does not work.<br />
<br />
This code '''does work''':<br />
<br />
myList = [<br />
1,2,3]<br />
<br />
It is accepted when you break a line right after the [. It is also accepted right after a comma. (And right before the ending ].)<br />
<br />
myList = [<br />
1,<br />
2,<br />
3<br />
]<br />
<br />
==Challenge Program==<br />
<br />
In this section, we will attempt the hardest program so far in this article.<br />
<br />
'''Make a conversation generator that will generate random conversations between different people.'''<br />
<br />
First, we will generate the people. We can use a list and generate two random numbers.<br />
<br />
import random<br />
<br />
peopleNames = [<br />
"Bob",<br />
"Kyle",<br />
"James",<br />
"Richard",<br />
"Zachary",<br />
"Olivia",<br />
"Jonathan",<br />
"Will",<br />
"Bobby",<br />
"Kevin"<br />
]<br />
person1 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
peopleNames.remove(person1)<br />
person2 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
<br />
(I made it more organized by separating the long lines of code into multiple lines. It only works when you have a line break right after each item in the list.)<br />
<br />
Here, we use the remove() function to remove person1 from the list to make sure we don't use the same name twice. <br />
<br />
We also used the len() function to find the length of the list (soft-coding!)<br />
<br />
Now, we need to create a list of possible values for the first thing that person1 says (person1 will always be the first one to talk). <br />
<br />
Then, we will print it out.<br />
<br />
import random<br />
<br />
peopleNames = [<br />
"Bob",<br />
"Kyle",<br />
"James",<br />
"Richard",<br />
"Zachary",<br />
"Olivia",<br />
"Jonathan",<br />
"Will",<br />
"Bobby",<br />
"Kevin"<br />
]<br />
person1 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
peopleNames.remove(person1)<br />
person2 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
<br />
first = [<br />
"Hi!",<br />
"Hello!",<br />
"Good morning!",<br />
"Hello, " + person2 + "!",<br />
"Hi.",<br />
"Hi, " + person2 + "!"<br />
]<br />
print(person1 + ": " + first[random.randint(0, (len(first) - 1))])<br />
<br />
If we test out this program, we can confirm that this part indeed does work. This program is already getting long! Now, we will use the same method and create the second message.<br />
<br />
import random<br />
<br />
peopleNames = [<br />
"Bob",<br />
"Kyle",<br />
"James",<br />
"Richard",<br />
"Zachary",<br />
"Olivia",<br />
"Jonathan",<br />
"Will",<br />
"Bobby",<br />
"Kevin"<br />
]<br />
person1 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
peopleNames.remove(person1)<br />
person2 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
<br />
first = [<br />
"Hi!",<br />
"Hello!",<br />
"Good morning!",<br />
"Hello, " + person2 + "!",<br />
"Hi.",<br />
"Hi, " + person2 + "!"<br />
]<br />
print(person1 + ": " + first[random.randint(0, (len(first) - 1))])<br />
<br />
second = [<br />
"Hi! How are you today?",<br />
"Hello! How are you?",<br />
"Good morning! How are you today?",<br />
"Hello, " + person1 + "! How are you?",<br />
"Hi. How are you?",<br />
"Hi, " + person1 + "! How are you today?"<br />
]<br />
print(person2 + ": " + second[random.randint(0, (len(second) - 1))])<br />
<br />
We will repeat this for the rest of the conversation:<br />
<br />
import random<br />
<br />
peopleNames = [<br />
"Bob",<br />
"Kyle",<br />
"James",<br />
"Richard",<br />
"Zachary",<br />
"Olivia",<br />
"Jonathan",<br />
"Will", <br />
"Bobby",<br />
"Kevin"<br />
]<br />
person1 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
peopleNames.remove(person1)<br />
person2 = peopleNames[random.randint(0, (len(peopleNames) - 1))]<br />
<br />
first = [<br />
"Hi!",<br />
"Hello!",<br />
"Good morning!",<br />
"Hello, " + person2 + "!",<br />
"Hi.",<br />
"Hi, " + person2 + "!"<br />
]<br />
print(person1 + ": " + first[random.randint(0, (len(first) - 1))])<br />
<br />
second = [<br />
"Hi! How are you today?",<br />
"Hello! How are you?",<br />
"Good morning! How are you today?",<br />
"Hello, " + person1 + "! How are you?",<br />
"Hi. How are you?",<br />
"Hi, " + person1 + "! How are you today?"<br />
]<br />
print(person2 + ": " + second[random.randint(0, (len(second) - 1))])<br />
<br />
third = [<br />
"I'm feeling awesome! And you?",<br />
"I'm feeling alright! How are you?",<br />
"I'm good, thank you. How are you feeling?",<br />
"I'm fine!" ,<br />
"How are you today?"<br />
]<br />
print(person1 + ": " + third[random.randint(0, (len(third) - 1))])<br />
<br />
fourth = [<br />
"I'm feeling great!",<br />
"I'm awesome!",<br />
"Thanks for asking! I am feeling good today!",<br />
"I'm feeling awesome today! Yippee!"<br />
] <br />
print(person2 + ": " + fourth[random.randint(0, (len(fourth) - 1))])<br />
<br />
fifth = [<br />
"It's so nice out today!",<br />
"Today is such a cloudy day.",<br />
"I hate it when it is so cloudy outside!",<br />
"It's partly cloudy today!"<br />
]<br />
print(person1 + ": " + fifth[random.randint(0, (len(fifth) - 1))])<br />
<br />
sixth = [<br />
"I know, right?",<br />
"I know.",<br />
"Yeah!",<br />
"True."<br />
]<br />
print(person2 + ": " + sixth[random.randint(0, (len(sixth) - 1))])<br />
<br />
seventh = [<br />
"Sorry, I need to leave. Bye!",<br />
"I gotta go. Bye!",<br />
"Sorry, I don't have time to stay and chat. I've got to go somewhere. Bye!"<br />
]<br />
print(person1 + ": " + seventh[random.randint(0, (len(seventh) - 1))])<br />
<br />
eighth = [<br />
"Bye!",<br />
"Good-bye!",<br />
"Bye, " + person1 + "."<br />
]<br />
print(person2 + ": " + eighth[random.randint(0, (len(eighth) - 1))])<br />
<br />
Whew! So long!<br />
<br />
Once we run our program. It works! This program really wasn't that hard.<br />
<br />
Congrats! You've made it so far!</div>Anstarhttps://artofproblemsolving.com/wiki/index.php?title=Pycharm&diff=117325Pycharm2020-02-08T04:57:04Z<p>Anstar: /* Starting pycharm */</p>
<hr />
<div>== Overview ==<br />
Pycharm is a software that helps you program and has many extra packages. It can find your bugs, give formatting tips, and is downloadable. It has upgrades every once in a while.<br />
== Installation ==<br />
To install pycharm make sure you have the python shell installed if not read the page [[Getting Started With Python Programming]]. Then install pycharm at:<br />
https://www.jetbrains.com/pycharm/download/#section=mac for macs, <br />
https://www.jetbrains.com/pycharm/download/#section=windows for windows, and https://www.jetbrains.com/pycharm/download/#section=linux for Linux. Please have parental guidance when installing.<br />
<br />
== See also ==<br />
* [[Basic Programming With Python]]<br />
*[[Getting Started With Python Programming]]<br />
<br />
{{stub}}</div>Anstarhttps://artofproblemsolving.com/wiki/index.php?title=AoPSWiki:Copyright&diff=117317AoPSWiki:Copyright2020-02-08T04:52:05Z<p>Anstar: </p>
<hr />
<div><cmath> </cmath></div>Anstarhttps://artofproblemsolving.com/wiki/index.php?title=Chemistry&diff=117314Chemistry2020-02-08T04:51:30Z<p>Anstar: </p>
<hr />
<div>== Overview ==<br />
'''Chemistry''' is the study of interactions between [[atom]]s at a macroscopic or microscopic (molecular) level.<br />
===Organic Chemistry===<br />
Organic chemistry is a branch of chemistry that focuses on molecules that contain carbon. Although most of organic chemistry is nonliving, organic chemistry is the basis of life.<br />
== Stoichiometry ==<br />
Stoichiometry is about calculating the amount of certain substances in a chemical reaction<br />
== See also ==<br />
<br />
{{stub}}</div>Anstarhttps://artofproblemsolving.com/wiki/index.php?title=Chemistry&diff=117309Chemistry2020-02-08T04:49:05Z<p>Anstar: /* See also */</p>
<hr />
<div>== Overview ==<br />
'''Chemistry''' is the study of interactions between [[atom]]s at a macroscopic or microscopic (molecular) level.<br />
===Organic Chemistry===<br />
Organic chemistry is a branch of chemistry that focuses on molecules that contain carbon. Although most of organic chemistry is non living, organic chemistry is the basis of life.<br />
== See also ==<br />
<br />
{{stub}}</div>Anstarhttps://artofproblemsolving.com/wiki/index.php?title=Chemistry&diff=117308Chemistry2020-02-08T04:48:48Z<p>Anstar: /* Non Organic Chemistry */</p>
<hr />
<div>== Overview ==<br />
'''Chemistry''' is the study of interactions between [[atom]]s at a macroscopic or microscopic (molecular) level.<br />
===Organic Chemistry===<br />
Organic chemistry is a branch of chemistry that focuses on molecules that contain carbon. Although most of organic chemistry is non living, organic chemistry is the basis of life.<br />
== See also ==<br />
* [[AoPSWiki:Table of Contents|Table of Contents]]<br />
<br />
{{stub}}</div>Anstarhttps://artofproblemsolving.com/wiki/index.php?title=Art_of_Problem_Solving&diff=117307Art of Problem Solving2020-02-08T04:46:45Z<p>Anstar: /* AoPSWiki */</p>
<hr />
<div>'''Art of Problem Solving''' ('''AoPS''') is an educational resources company founded by [[Richard Rusczyk]] in 2003. <br />
<br />
<br />
=== Tradition of Excellence ===<br />
The accomplishments of every student are unique, and there is no way to measure that success. However, we try to record and celebrate [[AoPS Community Awards | achievements of AoPS students, faculty, and community members]].<br />
<br />
== Resources on AoPS ==<br />
=== AoPSWiki ===<br />
You're in the [[AoPS Wiki:Table of Contents]] now!<br />
<br />
* [[AoPSWiki:Table of Contents]] -- a basic guide to AoPSWiki content<br />
* [[Academic competitions]] including a huge [[List of mathematics competitions]]<br />
* [[Math books]]<br />
* [[Academic scholarships]] including a large list of [[Mathematics scholarships]]<br />
<br />
=== AoPS Books ===<br />
<br />
==== Subject textbooks ====<br />
AoPS subject texts provide instruction to excellent students of mathematics. This modern curriculum is both comprehensive and challenging enough for brilliant young mathematical minds.<br />
* [http://www.artofproblemsolving.com/Books/AoPS_B_Item.php?item_id=200 Introduction to Algebra]<br />
* [http://www.artofproblemsolving.com/Books/AoPS_B_Item.php?item_id=202 Introduction to Counting & Probability]<br />
* [http://www.artofproblemsolving.com/Books/AoPS_B_Item.php?item_id=204 Introduction to Geometry]<br />
* [http://www.artofproblemsolving.com/Books/AoPS_B_Item.php?item_id=206 Introduction to Number Theory]<br />
* [http://www.artofproblemsolving.com/Store/viewitem.php?item=interm:algebra Intermediate Algebra]<br />
* [http://www.artofproblemsolving.com/Books/AoPS_B_Item.php?item_id=302 Intermediate Counting & Probability]<br />
* [http://www.artofproblemsolving.com/Store/viewitem.php?item=precalc Precalculus]<br />
* [http://www.artofproblemsolving.com/Store/viewitem.php?item=calculus Calculus]<br />
<br />
==== Problem solving books ====<br />
The original Art of Problem Solving books cover a variety of topics of interest to top students of mathematics.<br />
* [http://www.artofproblemsolving.com/Books/AoPS_B_Item.php?page_id=1 Art of Problem Solving Volume 1]<br />
* [http://www.artofproblemsolving.com/Books/AoPS_B_Item.php?page_id=2 Art of Problem Solving Volume 2]<br />
<br />
==== Other math books ====<br />
AoPS sells numerous other math books at the [http://www.artofproblemsolving.com/Books/AoPS_B_About.php AoPS Bookstore]. Many of these books focus on competitions such as the [[AMC]], the [[Mandelbrot Competition]], [[Mathcounts]], or [[MOEMS]].<br />
<br />
=== AoPS Online School ===<br />
The [[AoPS Online School]] hosts math classes primarily for bright middle and high school students. Students of the online math school include winners of nearly every major mathematics competition in the U.S.<br />
<br />
<br />
=== AoPS Forums ===<br />
The [http://www.artofproblemsolving.com/Forum/index.php AoPS Forums] are a place where students and problem solvers of all ages can discuss mathematics and problem solving. Visit [[AoPSWiki:AoPS forums]] for more details.<br />
<br />
=== AoPS For The Win ===<br />
[http://www.artofproblemsolving.com/Edutainment/g1/index.php For The Win] is an online interactive game for students to participate in activities similar to Countdown Round in [[MathCounts]].<br />
<br />
=== TeX/LaTeX Resources ===<br />
The [http://www.artofproblemsolving.com/community AoPS Forums] are [[LaTeX]]-enabled, allowing users to post nice mathematics.<br />
<br />
=== Math contest problem database ===<br />
<br />
AoPS members help organize a large and well-organized <url>resources.php list of problems and solutions</url> from [[mathematics competitions]] all over the world.<br />
<br />
=== Articles ===<br />
<br />
AoPS resources include [http://artofproblemsolving.com/articles numerous very good articles] for students, parents, and teachers.<br />
<br />
== Philanthropy ==<br />
Many of the features of the Art of Problem Solving website are made available for free so that every student interested in mathematics can use them.<br />
<br />
Additionally, AoPS instructors provide hundreds of hours of teaching and support time for the [[San Diego Math Circle]].<br />
<br />
The [[Art of Problem Solving Foundation]] is a nonprofit corporation founded by AoPS CEO [[Richard Rusczyk]] with largely the same fundamental mission as AoPS itself, but with greater focus on providing educational resources where they are lacking. AoPS donates a portion of its book and class sales to the foundation. A link can be found [http://www.artofproblemsolving.org here]. Make sure it is .org if you want to see the foundation website, otherwise, you'll see the homepage of the current website you're on. <br />
<br />
<br />
<br />
[[Category:Art of Problem Solving]]</div>Anstarhttps://artofproblemsolving.com/wiki/index.php?title=Real_Gmaas&diff=114481Real Gmaas2020-01-08T03:14:40Z<p>Anstar: </p>
<hr />
<div><br />
==GMAAS only exists in your imagination. Do not follow GMAAS. ==<br />
==Important==<br />
Put you Username here if you are not with Gmaas:<br />
*PI.FERMET<br />
*richpianist<br />
*Everyone in the universe</div>Anstarhttps://artofproblemsolving.com/wiki/index.php?title=Real_Gmaas&diff=114480Real Gmaas2020-01-08T03:14:33Z<p>Anstar: </p>
<hr />
<div><br />
==GMAAS only exists in your imagination. Do not follow GMAAS. ==<br />
==Important==<br />
Put you Username here if you are not with Gmaas:<br />
*anstar<br />
*PI.FERMET<br />
*richpianist<br />
*Everyone in the universe</div>Anstarhttps://artofproblemsolving.com/wiki/index.php?title=Talk:Gmaas&diff=114479Talk:Gmaas2020-01-08T03:13:47Z<p>Anstar: Blanked the page</p>
<hr />
<div></div>Anstarhttps://artofproblemsolving.com/wiki/index.php?title=Talk:Gmaas&diff=113398Talk:Gmaas2019-12-25T01:54:55Z<p>Anstar: Blanked the page</p>
<hr />
<div></div>Anstarhttps://artofproblemsolving.com/wiki/index.php?title=Gmaas&diff=113059Gmaas2019-12-18T21:59:13Z<p>Anstar: </p>
<hr />
<div>{{delete|There are too many spam pages there should be none}}<br />
== Hacked by Gmaas Who thinks this article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==</div>Anstarhttps://artofproblemsolving.com/wiki/index.php?title=Gmaas%27s_followers&diff=113058Gmaas's followers2019-12-18T21:58:50Z<p>Anstar: </p>
<hr />
<div>{{delete|There are too many spam pages there should be none}}</div>Anstarhttps://artofproblemsolving.com/wiki/index.php?title=AoPSWiki:Deletion_policy&diff=113057AoPSWiki:Deletion policy2019-12-18T21:57:26Z<p>Anstar: Blanked the page</p>
<hr />
<div></div>Anstarhttps://artofproblemsolving.com/wiki/index.php?title=GMAAS&diff=113056GMAAS2019-12-18T21:56:11Z<p>Anstar: </p>
<hr />
<div>== Hacked by Gmaas Who thinks this article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==</div>Anstarhttps://artofproblemsolving.com/wiki/index.php?title=Talk:Gmaas&diff=113055Talk:Gmaas2019-12-18T21:55:17Z<p>Anstar: </p>
<hr />
<div>== Hacked by Gmaas Who thinks this article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is spam ==<br />
== This article is sp