Last active
August 29, 2015 14:23
-
-
Save rohithreddy/0fe1cfbefa5cd2774799 to your computer and use it in GitHub Desktop.
Vacationlabs
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
Instructions to run the programs | |
Download the gist | |
Run hiphop.py by using command | |
$> python hiphop.py | |
Run freqcount.oy by passing the file name containing numbers as an argument for script. Note : place the FILE with numbers in same directory as freqcount.py or specify full path | |
$> python freqcount.py numbers |
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 collections,sys | |
file = open(sys.argv[1]) | |
nlist = file.read().split() | |
freq = collections.Counter(nlist) | |
#Counter from collections module returns frequencies in a dictionary with numbers as key and frequencies as value | |
file.close() | |
print(freq) |
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 hiphop(n): | |
'''takes n as argument and prints all numbers from 1 to n except for cases if a number is divisible by | |
(a). 3 prints "Hip" | |
(b). 5 prints "Hop" | |
(c). both by 3 & 5 prints "Whazza" ''' | |
for i in range(1, n+1): | |
if i % 3 == 0 : | |
if i % 5 == 0 : | |
print("Whazza") | |
else: | |
print("Hip") | |
elif i % 5 == 0: | |
print("Hop") | |
else: | |
print(i) | |
# call the function and prompt user for input | |
hiphop(int(input("Enter the n value: "))) |
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
1 1 3 68 8 2 36 8 9 1 1 4 5 7 89 1 3 4 5 6 7 9 7 87 6 5 79 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment