8000 added solutions to problem 1 and 4 by amanmj · Pull Request #253 · Show-Me-the-Code/python · GitHub
[go: up one dir, main page]

Skip to content
Open
8000
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions amanmj/0001/solution.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#Solution to problem 0001

'''
# Question 0001: As an independent developer of the Apple Store App, do you want to make a promotion, generate an activation code (or coupon)
# for your application , and how does Python generate
# 200 activation codes (or coupons)
'''

import string
import random
from sets import Set

numberOfActivationCodes = 200
lengthOfActivationCodes = 20

def getAllSymbols():
return string.letters + string.digits

allSymbolsString = getAllSymbols()

def printActivationCodes():
activationCodes = Set([])
while len(activationCodes) < numberOfActivationCodes:
lenOfString = 0
currString = ""
for i in range(0,len(allSymbolsString)):
probability = random.random()
if probability > 0.5:
currString = currString + allSymbolsString[i]
if(len(currString) == lengthOfActivationCodes):
activationCodes.add(currString)
break

for i in activationCodes:
print i


if __name__ == "__main__":
printActivationCodes()
3 changes: 3 additions & 0 deletions amanmj/0004/file.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
This pull request
is submitted by Aman Mahajan
Username : amanmj
36 changes: 36 additions & 0 deletions amanmj/0004/solution.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# from collections import Counter
# import re
#
#
# def creat_list(filename):
# datalist = []
# with open(filename, 'r') as f:
# for line in f:
# content = re.sub("\"|,|\.", "", line)
# datalist.extend(content.strip().split(' '))
# return datalist
#
#
# def wc(filename):
# print Counter(creat_list(filename))
#
# if __name__ == "__main__":
# filename = 'test.txt'
# wc(filename)


fileName = 'file.txt'

fileOpen = open(fileName,'r')

content = fileOpen.read()

counter = 0

for i in content.split(' '):
counter = counter + 1

print counter

fileOpen.close()

0