This file contains hidden or 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 number_of_lines_and_words_of_the_file(filename): | |
f = open(filename) | |
lineNo=0 | |
wordNo=0 | |
for line in f: | |
wordNo+=len(line.split(" ")) | |
lineNo+=1 | |
return lineNo, wordNo | |
print number_of_lines_and_words_of_the_file("series.txt") |
This file contains hidden or 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 insertion_sort(*args): | |
sList=list(args[:]) //copies args to sList | |
for index in range(1, len(sList)): //starts from first index not zero | |
value = sList[index] | |
i = index-1 | |
while i>=0: //compare values before the current value to the current value | |
if value<sList[i]: | |
sList[i+1], sList[i] = sList[i], sList[i+1] //swap if the current value smaller than previous value | |
i = i-1 | |
else: |
This file contains hidden or 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 webapp2,cgi | |
form='''<form method="post"> | |
<textarea name="text"> | |
%(text)s | |
</textarea> | |
<input type="submit"> | |
</form> | |
''' |
This file contains hidden or 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
#!/usr/bin/env python | |
# | |
# Copyright 2007 Google Inc. | |
# | |
# Licensed under the Apache License, Version 2.0 (the "License"); | |
# you may not use this file except in compliance with the License. | |
# You may obtain a copy of the License at | |
# | |
# http://www.apache.org/licenses/LICENSE-2.0 | |
# |
This file contains hidden or 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
#!/usr/bin/env python | |
# | |
# Copyright 2007 Google Inc. | |
# | |
# Licensed under the Apache License, Version 2.0 (the "License"); | |
# you may not use this file except in compliance with the License. | |
# You may obtain a copy of the License at | |
# | |
# http://www.apache.org/licenses/LICENSE-2.0 | |
# |
This file contains hidden or 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
-- create objects | |
local rect1 = display.newRect( 0, 0, 100, 100 ) | |
local rect2 = display.newRect(300,300, 50,50) | |
-- touch listener function | |
local function move(self, event ) | |
if event.phase == "began" then | |
--set focus on touched object so it won't interfere with other display objects. | |
display.getCurrentStage():setFocus( self, event.id ) | |
self.isFocus = true |
This file contains hidden or 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
-- create object | |
local myObject = display.newRect( 0, 0, 100, 100 ) | |
myObject:setFillColor( 255 ) | |
-- touch listener function | |
function myObject:touch( event ) | |
if event.phase == "began" then | |
self.markX = self.x -- store x location of object | |
self.markY = self.y -- store y location of object | |
elseif event.phase == "moved" then |
This file contains hidden or 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
module(..., package.seeall) | |
local director = require("director") | |
function new() --all objects and functions should be inside this function | |
local group = display.newGroup() --create a group object to keep display objects | |
time = 3 -- count down from 3 | |
--Text will be displayed when time is up! | |
gogogo = display.newText("Go go go!", 0, 0, "James Fajardo", 100) |
This file contains hidden or 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
local director = require("director") --import director | |
--GLOBALS-- | |
W = display.contentWidth | |
H = display.contentHeight | |
--Change Scene-- | |
director: changeScene("scene1") -- go to first scene |
This file contains hidden or 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
local storyboard = require("storyboard") --import storyboard | |
storyboard.purgeOnSceneChange=true --clean scene before moving anothe scene | |
--GLOBALS-- | |
W=display.contentWidth | |
H=display.contentHeight | |
----------------------------- | |
--Change scene-- | |
storyboard.gotoScene("scene1") --go to first scene |