diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..fba7091 Binary files /dev/null and b/.DS_Store differ diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e10e727 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/.metadata/ diff --git a/Pass1/.project b/Pass1/.project new file mode 100644 index 0000000..59a41cc --- /dev/null +++ b/Pass1/.project @@ -0,0 +1,17 @@ + + + Pass1 + + + + + + org.python.pydev.PyDevBuilder + + + + + + org.python.pydev.pythonNature + + diff --git a/Pass1/.pydevproject b/Pass1/.pydevproject new file mode 100644 index 0000000..ad74947 --- /dev/null +++ b/Pass1/.pydevproject @@ -0,0 +1,8 @@ + + + +/${PROJECT_DIR_NAME} + +python interpreter +Default + diff --git a/Pass1/Datatypes.py b/Pass1/Datatypes.py new file mode 100755 index 0000000..23f5a73 --- /dev/null +++ b/Pass1/Datatypes.py @@ -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)) \ No newline at end of file diff --git a/Pass1/Functions.py b/Pass1/Functions.py new file mode 100755 index 0000000..a201ae4 --- /dev/null +++ b/Pass1/Functions.py @@ -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) diff --git a/Pass1/Hello World.py b/Pass1/Hello World.py new file mode 100755 index 0000000..147d1da --- /dev/null +++ b/Pass1/Hello World.py @@ -0,0 +1,2 @@ +print("Hello World!") + diff --git a/Pass1/Inputs.py b/Pass1/Inputs.py new file mode 100755 index 0000000..3282292 --- /dev/null +++ b/Pass1/Inputs.py @@ -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) \ No newline at end of file diff --git a/Pass1/Iteration.py b/Pass1/Iteration.py new file mode 100755 index 0000000..76a9509 --- /dev/null +++ b/Pass1/Iteration.py @@ -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!") \ No newline at end of file diff --git a/Pass1/Lists.py b/Pass1/Lists.py new file mode 100755 index 0000000..643d48e --- /dev/null +++ b/Pass1/Lists.py @@ -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) \ No newline at end of file diff --git a/Pass1/Selection.py b/Pass1/Selection.py new file mode 100755 index 0000000..430e9e8 --- /dev/null +++ b/Pass1/Selection.py @@ -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) + diff --git a/Pass1/Strings.py b/Pass1/Strings.py new file mode 100755 index 0000000..7528849 --- /dev/null +++ b/Pass1/Strings.py @@ -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")) diff --git a/Pass1/Syntax.py b/Pass1/Syntax.py new file mode 100755 index 0000000..0a0a845 --- /dev/null +++ b/Pass1/Syntax.py @@ -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") \ No newline at end of file diff --git a/Pass1/hello.py b/Pass1/hello.py new file mode 100644 index 0000000..8e23576 --- /dev/null +++ b/Pass1/hello.py @@ -0,0 +1 @@ +print("Hello World") \ No newline at end of file