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 random, sys | |
| def displayHint(answers, choosed_word): | |
| won = True | |
| for i in range(len(choosed_word)-1): | |
| if choosed_word[i] in answers: | |
| print choosed_word[i], | |
| else: | |
| won = False | |
| print '-', |
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 random | |
| with open('sowpods.txt') as dict_file: | |
| words_list = dict_file.read().split('\n') | |
| print words_list[random.randint(0, len(words_list))] |
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
| numbers = range(100) | |
| low = 0 | |
| tries = 0 | |
| high = len(numbers) - 1 | |
| while True: | |
| print str(low) + " : " + str(high) | |
| tries += 1 | |
| if low == high: | |
| print "You must have choosed : " + numbers[low] | |
| break |
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 printBoard(dimension): | |
| for i in range(dimension): | |
| for j in range(dimension): | |
| print " ", | |
| for k in range(dimension): | |
| print "-", | |
| print "\n", | |
| print "|", | |
| for j in range(dimension): | |
| for k in range(dimension): |
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
| with open('primenumbers.txt') as prime_file: | |
| prime_nums = prime_file.read().split('\n') | |
| with open('happynumbers.txt') as happy_file: | |
| happy_nums = happy_file.read().split('\n') | |
| for prime_num in prime_nums: | |
| if prime_num in happy_nums: | |
| print prime_num |
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 random | |
| def main(): | |
| randomNum = str(random.randint(1000, 9999)) | |
| tries = 0 | |
| choosedNum = '0000' | |
| while choosedNum != randomNum: | |
| choosedNum = raw_input("Enter your number : ") | |
| print getCowAndBulls(choosedNum, randomNum) | |
| tries += 1 |
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 requests | |
| from bs4 import BeautifulSoup | |
| base_url = 'http://www.nytimes.com' | |
| r = requests.get(base_url) | |
| soup = BeautifulSoup(r.text, "html.parser") | |
| for story_heading in soup.find_all(class_="story-heading"): | |
| if story_heading.a: | |
| print(story_heading.a.text.replace("\n", " ").strip()) |
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
| inputString = raw_input("Enter you string : ") | |
| inputString = inputString.split(" ") | |
| inputString.reverse() | |
| inputString = " ".join(inputString) | |
| print inputString |
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 getNextFibonnaciElement(lastElement, currentElement): | |
| return lastElement + currentElement | |
| if __name__ == '__main__': | |
| num = int(raw_input("Enter number of fibonacci series element : ")) | |
| lastElement = 0 | |
| currentElement = 1 | |
| for i in range(num): | |
| print str(currentElement) + "," |
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 getBoundaryElements(a): | |
| return [a[0], a[-1]] | |
| if __name__ == '__main__': | |
| a = [5, 10, 15, 20, 2510, 15, 20, 2510, 15, 20, 225] | |
| print getBoundaryElements(a) |
NewerOlder