{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "“all is well, and everything is unfolding as it should. there are no mistakes. none have ever been made, none are being made, and none will ever be made. its all perception. it’s how you perceive things. for instance, when you look at me what do you see? if i ask each one of you i get seven, eight, nine different answers, but the truth is you are seeing yourself. i am simply a mirror for your own reflection, but i am a self-contained mirror. so all this is taking place as an image on myself. all of life experiences are images on the screen of eternity. the screen is real. the images change. consciousness is the screen. when you identify with consciousness you become consciousness. when you identify with the image you enhance the image, and you worry, and fret, and fear and you have all sorts of experiences.\n", "\n", "as soon as you begin to identify with reality, with consciousness, all fear leaves you, all doubt leaves you, all false thinking leaves you, and you become free. but that’s the only free choice you get. everything else has been preordained.\n", "\n", "the free choice again is: with what are you going to identify, with the image or the screen? if you identify with consciousness you are no longer reacting to conditions, because you understand that all things are for a short time only, then they disappear. consequently nothing will irritate you, nothing will upset you, nothing will bother you for you are now appearing as only an image and will soon disappear.\n", "\n", "look at this planet which has been here for billions of years. there have been civilizations on this planet for billions of years, and they come and go. we had civilizations on this planet that surpassed our existence today. they are all gone. no trace. as a matter of fact, a couple of years ago there were some excavations in egypt of a city that was buried about 5,000 years ago. the only thing left is a sign. they deciphered the sign and it said, “my name is king so-and-so, and this is my city that will last forever.”\n", "\n", "so today we think we are going to make this a better world in which to live, and we are going to save the world, and so on. the world has it’s own collective karma. it’s going through a phase. your job is to save yourself. if you find yourself in a burning building, you do not stop to admire the pictures on the wall, you get out of the building as fast as you can. so, when you know you have a short time in this existence you do not stop to play the games of life, you try to find yourself and become free as fast as you can….”\n", "\n" ] } ], "source": [ "fname = \"ra.txt\"\n", "with open(fname) as f:\n", " data = f.read().lower()\n", "print(data)" ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [], "source": [ "letters = 'abcdefghijklmnopqrstuvwxyz'\n", "sentence = 'This is a sentence'" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "abcdefghijklmnopqrstuvwxyz\n" ] } ], "source": [ "print(letters)" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "158" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "data.count('a')" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[158, 25, 55, 55, 246, 52, 51, 91, 158, 1, 11, 85, 33, 153, 175, 27, 1, 99, 136, 153, 67, 21, 39, 5, 74, 2]\n" ] } ], "source": [ "def get_counts(fname):\n", " with open(fname) as f:\n", " data = f.read().lower()\n", " letters = 'abcdefghijklmnopqrstuvwxyz'\n", " # Accumulator pattern\n", " counts = [] # initial value of the accumulator\n", " for letter in letters:\n", " num = data.count(letter) # find out what to accumulate\n", " counts.append(num) # accumulate\n", " return counts" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "150\n" ] } ], "source": [ "nums = [10,20,30,40,50]\n", "\n", "# Accumulator pattern\n", "sum = 0\n", "for n in nums:\n", " sum = sum + n\n", "\n", "print(sum)" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "15" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "letters.find('p')" ] }, { "cell_type": "code", "execution_count": 20, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "2" ] }, "execution_count": 20, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sentence.find('is')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "(letters.find(char) + shift) % 26" ] }, { "cell_type": "code", "execution_count": 21, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[158, 25, 55, 55, 246, 52, 51, 91, 158, 1, 11, 85, 33, 153, 175, 27, 1, 99, 136, 153, 67, 21, 39, 5, 74, 2]\n" ] } ], "source": [ "counts = [] # initial value of the accumulator\n", "for letter in letters:\n", " num = data.count(letter) # find out what to accumulate\n", " counts.append(num) # accumulate\n", "print(counts)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## OBJECTS AND CLASSES" ] }, { "cell_type": "code", "execution_count": 31, "metadata": {}, "outputs": [], "source": [ "class Student:\n", "\n", " # Constructor Method\n", " def __init__(self,name):\n", " self._name = name\n", " self._courses = []\n", " \n", " # Mutator methods\n", " def change_name(self,name):\n", " self._name = name\n", "\n", " def add_course(self,cno,credits,grade):\n", " self._courses.append((cno,credits,grade))\n", " \n", " #s1._courses = [('CSc7003',1.5,'A'), ('CSc6710',4,'B'), ('CSc3320',3,'C')]\n", " \n", " # Accessor methods\n", " def gpa(self):\n", " grade_points = {'A': 4, 'B': 3, 'C': 2, 'D': 1, 'F': 0}\n", " points = 0.0\n", " total_credits = 0.0\n", " for (cn,cr,g) in self._courses:\n", " value = cr * grade_points[g]\n", " points = points + value\n", " total_credits = total_credits + cr\n", " if (total_credits > 0):\n", " return round(points/total_credits,2)\n", " else:\n", " return None" ] }, { "cell_type": "code", "execution_count": 32, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "\n", "Transcript for Timmy Jones \n", "\n", "CSc7003 1.5 A\n", "CSc6710 4.0 B\n", "CSc3320 3.0 C\n", "\n", "GPA: 2.82 \n", "\n", "\n", "\n", "Transcript for Hilary Smith \n", "\n", "CSc 1301 4.0 A\n", "CSc 1302 4.0 A\n", "CSc 2510 3.0 B\n", "CSc 2720 3.0 A\n", "CSc 3210 3.0 C\n", "CSc 3320 3.0 A\n", "\n", "GPA: 3.55 \n", "\n" ] } ], "source": [ "def print_transcript(s):\n", " print(\"\\n\\nTranscript for \",s._name,\"\\n\")\n", " for c in s._courses:\n", " print(\"%6s %.1f %3s\"%(c[0],c[1],c[2]))\n", " print(\"\\nGPA: \",s.gpa(),\"\\n\")\n", "\n", "def main():\n", " s1 = Student(\"Tommy Jones\")\n", " s1.add_course('CSc7003',1.5,'A')\n", " s1.add_course('CSc6710',4,'B')\n", " s1.add_course('CSc3320',3,'C')\n", " s1.change_name('Timmy Jones')\n", " print_transcript(s1)\n", "\n", " s2 = Student(\"Hilary Smith\")\n", " s2.add_course('CSc 1301',4,'A')\n", " s2.add_course('CSc 1302',4,'A')\n", " s2.add_course('CSc 2510',3,'B')\n", " s2.add_course('CSc 2720',3,'A')\n", " s2.add_course('CSc 3210',3,'C')\n", " s2.add_course('CSc 3320',3,'A')\n", " print_transcript(s2)\n", "\n", "main()" ] }, { "cell_type": "code", "execution_count": 30, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0\n", "0.5\n", "4.3\n", "{'A': 4, 'B': 3, 'C': 2, 'D': 1, 'F': 0.5, 'A+': 4.3}\n" ] } ], "source": [ "# dictionary is a set of key-value pairs\n", "grade_points = {'A': 4, 'B': 3, 'C': 2, 'D': 1, 'F': 0}\n", "phone_numbers = { \"John\": \"111-1234\", \"James\": \"222-3333\"}\n", "print(grade_points['F'])\n", "grade_points['F'] = 0.5\n", "print(grade_points['F'])\n", "grade_points['A+'] = 4.3\n", "print(grade_points['A+'])\n", "print(grade_points)" ] }, { "cell_type": "code", "execution_count": 33, "metadata": {}, "outputs": [ { "ename": "IndentationError", "evalue": "unindent does not match any outer indentation level (, line 8)", "output_type": "error", "traceback": [ "\u001b[0;36m File \u001b[0;32m\"\"\u001b[0;36m, line \u001b[0;32m8\u001b[0m\n\u001b[0;31m def next(self):\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mIndentationError\u001b[0m\u001b[0;31m:\u001b[0m unindent does not match any outer indentation level\n" ] } ], "source": [ "class Time(object):\n", " def __init__(self, hour, minute, second, ampm):\n", " self._hour = hour # 1..12\n", " self._minute = minute # 0..59\n", " self._second = second # 0..59\n", " self._ampm = ampm # midnight will be AM!!; ampm = 'AM' or 'PM'\n", "\n", " def next(self):\n", " if self._hour == 11 and self._minute == 59 and self._second == 59:\n", " if self._ampm == 'AM':\n", " next_time = Time(12,0,0,'PM')\n", " else:\n", " next_time = Time(12,0,0,'AM')\n", " elif self._hour == 12 and self._minute == 59 and self._second == 59:\n", " next_time = Time(1,0,0,self._ampm)\n", " elif self._second == 59:\n", " if self._minute == 59:\n", " next_time = Time(self._hour+1,0,0,self._ampm)\n", " else:\n", " next_time = Time(self._hour,self._minute+1,0,self._ampm)\n", " else:\n", " next_time = Time(self._hour, self._minute, self._second+1, self._ampm)\n", " return next_time\n", " \n", " def previous(self):\n", "\n", " def add(self,nseconds):\n", " t = Time(self._hour,self._minute,self._second,self._ampm)\n", " for i in range(nseconds):\n", " t = t.next() \n", " return t\n", "\n", " def sub(self,nseconds):\n", "\n", " def seconds_from_midnight(self):\n", "\n", " def after(self,t):\n", "\n", " def equals(self,t):\n", " return ((self._second == t._second) and\n", " (self._minute == t._minute) and\n", " (self._hour == t._hour) and\n", " (self._ampm == t._ampm))\n", "\n", " def before(self,t):\n", "\n", " def seconds_between(self,t):\n", "\n", " def __str__(self):\n", " def two_spaces(n):\n", " if n<10:\n", " return '0'+str(n)\n", " else:\n", " return str(n)\n", " return two_spaces(self._hour)+\":\"+two_spaces(self._minute)+\":\"+ \\\n", " two_spaces(self._second)+\" \"+self._ampm" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "t1 = Time(8,10,0,'PM')\n", "t1.next() # = 8:10:1 PM" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.5" } }, "nbformat": 4, "nbformat_minor": 2 }