Starting Point
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/.metadata/
|
||||
17
Pass1/.project
Normal file
17
Pass1/.project
Normal file
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>Pass1</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.python.pydev.PyDevBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.python.pydev.pythonNature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
8
Pass1/.pydevproject
Normal file
8
Pass1/.pydevproject
Normal file
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<?eclipse-pydev version="1.0"?><pydev_project>
|
||||
<pydev_pathproperty name="org.python.pydev.PROJECT_SOURCE_PATH">
|
||||
<path>/${PROJECT_DIR_NAME}</path>
|
||||
</pydev_pathproperty>
|
||||
<pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python interpreter</pydev_property>
|
||||
<pydev_property name="org.python.pydev.PYTHON_PROJECT_INTERPRETER">Default</pydev_property>
|
||||
</pydev_project>
|
||||
21
Pass1/Datatypes.py
Executable file
21
Pass1/Datatypes.py
Executable file
@@ -0,0 +1,21 @@
|
||||
#Python is a dynamically typed language. Python uses values not variables :)
|
||||
a = 100
|
||||
b = "foo"
|
||||
c = True
|
||||
d = 10.95
|
||||
e = "bar"
|
||||
# b is changed from string to integer dynamically
|
||||
b = 4
|
||||
|
||||
print(a)
|
||||
print(b)
|
||||
print(c)
|
||||
print(d)
|
||||
print(a+d)
|
||||
|
||||
#bunch of different ways to concatenate different datatypes, format is recommended I believe
|
||||
print(str(a)+e)
|
||||
print(a,e)
|
||||
print("Concatenate: {} {}".format(a,e))
|
||||
print("Concatenate: {} {}".format(a,c))
|
||||
print("Concatenate: %d %s " % (a,e))
|
||||
14
Pass1/Functions.py
Executable file
14
Pass1/Functions.py
Executable file
@@ -0,0 +1,14 @@
|
||||
# Define 3 functions
|
||||
def my_function():
|
||||
print("Hello From My Function!")
|
||||
|
||||
def my_function_with_args(username, greeting):
|
||||
print("Hello,{}, From My Function!, I wish you {}".format(username, greeting))
|
||||
|
||||
def sum_two_numbers(a, b):
|
||||
return a + b
|
||||
|
||||
my_function()
|
||||
my_function_with_args("Elvis Presley", "left the building!")
|
||||
x = sum_two_numbers(5, 15)
|
||||
print(x)
|
||||
2
Pass1/Hello World.py
Executable file
2
Pass1/Hello World.py
Executable file
@@ -0,0 +1,2 @@
|
||||
print("Hello World!")
|
||||
|
||||
3
Pass1/Inputs.py
Executable file
3
Pass1/Inputs.py
Executable file
@@ -0,0 +1,3 @@
|
||||
#simple code to accept values from command line. Easiest to test in IDLE
|
||||
input_var = input("Enter something: ")
|
||||
print ("you entered " + input_var)
|
||||
18
Pass1/Iteration.py
Executable file
18
Pass1/Iteration.py
Executable file
@@ -0,0 +1,18 @@
|
||||
#sneak in a little example of importing a library:)
|
||||
import os
|
||||
|
||||
list2 = ["foo","man","chu","Elvis"]
|
||||
|
||||
#iterating through a list
|
||||
for i in list2:
|
||||
print(i)
|
||||
|
||||
#iterating through a dictionary
|
||||
for j, k in os.environ.items():
|
||||
print("%s=%s" % (j,k))
|
||||
|
||||
launch = 10
|
||||
while launch > 0:
|
||||
print(launch)
|
||||
launch -= 1
|
||||
print("Blastoff!")
|
||||
36
Pass1/Lists.py
Executable file
36
Pass1/Lists.py
Executable file
@@ -0,0 +1,36 @@
|
||||
empty_list = []
|
||||
list1 = [1, 2, 3, 4, 5]
|
||||
list2 = ["foo","man","chu","Elvis"]
|
||||
list3 = [100, "Foobar", 3.14]
|
||||
|
||||
#nested list/multidimensional array
|
||||
list4 = ["Python", [8, 4, 6], ['a','b','c']]
|
||||
|
||||
#stuff with list 1 functions
|
||||
print(list1)
|
||||
list1.pop(1) #removes from list
|
||||
print(list1)
|
||||
print(list1[1])
|
||||
|
||||
#stuff with list2
|
||||
print(list2)
|
||||
list2.extend([6,7]) #adds to list as part of original array
|
||||
print(list2)
|
||||
list2.append([6,7]) #adds as a list
|
||||
print(list2)
|
||||
print(list2[2])
|
||||
|
||||
#stuff with list 4 and 5
|
||||
print(list3)
|
||||
print(list4[0][1])
|
||||
print(list4[1][2])
|
||||
print("Length of list3: ", len(list3))
|
||||
|
||||
#tuples, immutable lists. Used for constant set of values that you want to iterate
|
||||
tuple1 = (1,2,3,4)
|
||||
print(tuple1)
|
||||
|
||||
#There are even dictionaries with key/value pairing
|
||||
movies = {'Pacific Rim': '5 stars', 'Black Panther': '5 stars', "Zombie Beavers":"0 stars"}
|
||||
for i, j in movies.items():
|
||||
print(i,j)
|
||||
10
Pass1/Selection.py
Executable file
10
Pass1/Selection.py
Executable file
@@ -0,0 +1,10 @@
|
||||
import random
|
||||
random_number = random.randrange(1,100)
|
||||
|
||||
if random_number < 50:
|
||||
print("The %d < 50" % random_number)
|
||||
elif random_number == 50:
|
||||
print("The %d = 50" % random_number)
|
||||
else:
|
||||
print("The %d > 50 " % random_number)
|
||||
|
||||
25
Pass1/Strings.py
Executable file
25
Pass1/Strings.py
Executable file
@@ -0,0 +1,25 @@
|
||||
my_string = "Hello Python!"
|
||||
print(my_string)
|
||||
|
||||
for i in my_string:
|
||||
print(i)
|
||||
|
||||
#strings are immutable i.e. can't change them but you can replace them
|
||||
#code below causes error
|
||||
#my_string[5] = "z"
|
||||
my_string = "Whole new string"
|
||||
print(my_string)
|
||||
|
||||
string1 ="Howdy"
|
||||
string2 ="Python!!"
|
||||
print("String1 + String2 =", string1 + string2)
|
||||
print('String1 * 5 =', string1 * 5)
|
||||
|
||||
string3="GoSa WiTh PyThOn!"
|
||||
bacon_ipsum="Bacon ipsum dolor amet prosciutto rump short ribs pork chop venison sausage"
|
||||
print(string3.upper())
|
||||
print(string3.lower())
|
||||
print(bacon_ipsum.split())
|
||||
print(" ".join(['Bacon', 'ipsum', 'dolor', 'amet', 'prosciutto', 'rump', 'short', 'ribs', 'pork', 'chop', 'venison', 'sausage']))
|
||||
print(bacon_ipsum.find("venison"))
|
||||
print(bacon_ipsum.replace("Bacon","Python"))
|
||||
9
Pass1/Syntax.py
Executable file
9
Pass1/Syntax.py
Executable file
@@ -0,0 +1,9 @@
|
||||
#This is a single line comment
|
||||
"""This is
|
||||
a multiline
|
||||
comment"""
|
||||
|
||||
#Python uses whitespaces for flow control
|
||||
#Python does not use {} or ;
|
||||
|
||||
print("Hello world again")
|
||||
1
Pass1/hello.py
Normal file
1
Pass1/hello.py
Normal file
@@ -0,0 +1 @@
|
||||
print("Hello World")
|
||||
Reference in New Issue
Block a user