Skip to content

Instantly share code, notes, and snippets.

@rohithreddy
Last active August 29, 2015 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rohithreddy/0fe1cfbefa5cd2774799 to your computer and use it in GitHub Desktop.
Save rohithreddy/0fe1cfbefa5cd2774799 to your computer and use it in GitHub Desktop.
Vacationlabs
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
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)
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: ")))
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