This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def r_sqrt(a): | |
a = float(a) | |
if a == 0.0: | |
return 0.0 | |
x = a | |
def sqrt(x): | |
epsilon = 0.000000000000001 | |
y = (x + a/x) / 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# this is learntris.py | |
import sys | |
def print_row(): | |
row = '. ' * 10 | |
return row.strip() + '\n' | |
def print_grid(): | |
row_list = [] | |
for i in range(22): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Course: | |
def __init__(self, name, units, status, score): | |
# global get_gpa | |
self.name = name | |
self.units = units | |
self.status = status | |
self.score = score | |
self.gpa = self.get_gpa() | |
self.wgpa = self.gpa * self.units |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Course: | |
def __init__(self, name, units, status, score): | |
self.name = name # name of the course | |
self.units = units # number of units the course weighs | |
self.status = status # can assume C, R or E | |
self.score = score # the score achieved in the course | |
@property | |
def wgpa(self): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def multiply(x, y): | |
if y == 0: | |
return 0 | |
z = multiply(x, y/2) | |
if y%2 == 0: | |
return 2*z | |
else: | |
return x + 2*z |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> import sys | |
>>> def stuff(): | |
... print("calling stuff!") | |
... | |
>>> def printer(frame, event, arg): | |
... print(frame, event, arg) | |
... return printer # return itself to keep tracing | |
... | |
>>> sys.settrace(printer) # register the tracing function | |
>>> stuff() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SOURCE_FILE = "data.txt" | |
DEST_FILE = "out.txt" | |
def stringify(s): | |
return('\"{}\"'.format(s.strip())) | |
def stringify_ls(string_ls): | |
return ','.join(list(map(stringify, string_ls.split(',')))) | |
def stringify_file(source_file, dest_file): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pdfkit | |
import requests | |
from bs4 import BeautifulSoup | |
html = requests.get("http://www.composingprograms.com/") | |
soup = BeautifulSoup(html.text, 'html.parser') | |
res = [] | |
for link in soup.find_all('a'): | |
linkstr = link.get('href') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
from bs4 import BeautifulSoup | |
ROOT_URL = "https://talendexpert.com/page/{pg_num}" | |
# for page in range(2,193): | |
# html_doc = requests.get(ROOT_URL.format(pg_num=page)).text | |
# soup = BeautifulSoup(html_doc, 'html.parser') | |
# for link in soup.findAll("h1", attrs={'class':"product_title"}): | |
# print (link.a.name) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for i in range(1, 101): | |
pass | |
# this one goes from 1 to 100 | |
for i in range(1, 100, -1): | |
print (i) |
OlderNewer