View euler22.py
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
alphabet = {'"':0,'A':1,'B':2,'C':3,'D':4,'E':5,'F':6,'G':7,'H':8,'I':9,'J':10,'K':11,'L':12,'M':13,'N':14,'O':15,'P':16,'Q':17,'R':18,'S':19,'T':20,'U':21,'V':22,'W':23,'X':24,'Y':25,'Z':26} | |
def name_value(name, pos): | |
sum = 0 | |
for letter in name: | |
sum += alphabet[letter] | |
return sum * pos | |
names_file = open("names.txt") | |
names = names_file.readlines() |
View forms.py
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
from django import forms | |
class UploadForm(forms.Form): | |
image = forms.ImageField(); |
View settings.py
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
TEMPLATE_DIRS = ( | |
os.path.join(BASE_DIR, 'templates'), | |
) |
View urls.py
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
from django.conf.urls import patterns, include, url | |
from django.contrib import admin | |
urlpatterns = patterns('', | |
url(r'^$', 'converters.views.index', name='index'), | |
url(r'^admin/', include(admin.site.urls)), | |
) |
View upload.html
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
<h1>Hello, upload a file and I will turn it grey</h1> | |
<form method="POST" action="" enctype="multipart/form-data"> | |
{{ form.as_p }} | |
<input type='submit' value='Upload'/> | |
</form> |
View views.py
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
from django.shortcuts import render | |
from django.http import HttpResponse | |
from PIL import Image | |
from converters.forms import UploadForm | |
def index(request): | |
form = UploadForm(request.POST, request.FILES) | |
if form.is_valid(): | |
grey(request.FILES['image']) |
View settings.py
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
INSTALLED_APPS = ( | |
'django.contrib.admin', | |
'django.contrib.auth', | |
'django.contrib.contenttypes', | |
'django.contrib.sessions', | |
'django.contrib.messages', | |
'django.contrib.staticfiles', | |
'converters', | |
) |
View n_degree_pi.py
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 math | |
print "Enter a number and I will print out that many decimal places of PI." | |
places = int(raw_input('>')) | |
print str(math.pi)[:places+2] |
View n_degree_pi_mathmatically.py
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
from __future__ import division | |
from decimal import * | |
print "Enter a number and I will print out that many decimal places of PI." | |
places = int(raw_input('>')) | |
getcontext().prec = places | |
pi = 0 |
View n_degree_e.py
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 math | |
print "Enter a number and I will print that many decimal places of e" | |
places = int(raw_input('>')) | |
print str(math.e)[:places+2] |