Skip to content
Open
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
26 changes: 26 additions & 0 deletions hackerrank.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# ## Bonus Question 1
# [HACKERRANK: FIND DIGITS](https://www.hackerrank.com/challenges/find-digits/problem)

def findDigits(n):
n=str(n)
l=len(n)
summ=0
for i in range(l):
if int(n[i])==0:
continue
elif int(n)%int(n[i])==0:
summ+=1
return summ

# ## Bonus Question 2
# [HACKERRANK: CAPITALIZE](https://www.hackerrank.com/challenges/capitalize/problem)

def solve(s):
s=s.split(' ')
for i in range(len(s)):
if s[i]=='':
continue
s[i]=s[i][0].capitalize()+s[i][1:]
s=' '.join([str(item) for item in s])
return s
solve('chris alan')
19 changes: 19 additions & 0 deletions q1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# ## 1-perfect_number.py
# Perfect number: Perfect number is a positive integer that is equal to the sum of its proper divisors.

# The smallest perfect number is `6`, which is the sum of `1`, `2`, and `3`.

# Some other perfect numbers are `28(1+2+4+7+14=28)`, `496` and `8128`.

# Write a function that finds perfect numbers between `1` and `1000`.
# Check perfect numbers between `1` and `1000` and find the sum of the perfect numbers using reduce and filter functions. <br />

def perfect_number(x):
summ=0
for i in range(1,x):
if x%i==0:
summ+=i
if summ==x:
return True
from functools import reduce
print(reduce(lambda a,b:a+b,(list(filter(lambda x: perfect_number(x),range(1,1000))))))
23 changes: 23 additions & 0 deletions q2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# ## 2-reading_number.py
# Write a function that outputs the transcription of an input number with two digits.

# Example:
# ```
# 28---------------->Twenty Eight

reading1=['','One','Two','Three','Four','Five','Six','Seven','Eight','Nine']
reading2=['Twenty','Thirty','Forty','Fifty','Sixty','Seventy','Eighty','Ninety']
reading3=['Ten','Eleven','Twelve','Thirteen','Fourteen','Fifteen','Sixteen','Seventeen','Eighteen','Nineteen']
def reading_numb():
x=input("A number only with two digits: ")
if x.isdigit()==False:
read= x
elif int(x)<10 or int(x)>99:
read= x
elif 20>int(x)>=10:
read='{}--------->{}'.format(x,reading3[int(x[1])])

else:
read='{}--------->{} {}'.format(x,reading2[int(x[0])-2],reading1[int(x[1])])
return read
print(reading_numb())
19 changes: 19 additions & 0 deletions q3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# ## 3-alphabetical_order.py
# Write a function that takes an input of different words with hyphen (-) in between them and then:<br />
# * sorts the words in alphabetical order,
# * adds hyphen icon (-) between them,
# * gives the output of the sorted words.

# Example:
# ```
# Input >>> green-red-yellow-black-white
# Output >>> black-green-red-white-yellow
# ```

def alphabetical_order():
words=input("Words with - : ")
words=words.split('-')
words.sort()
words='-'.join(words)
return words
print(alphabetical_order())
18 changes: 18 additions & 0 deletions q4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# ## 4-unique_list.py
# Write a function that filters all the unique(unrepeated) elements of a given list.

# Example:
# ```
# Function call: unique_list([1,2,3,3,3,3,4,5,5])
# Output : [1, 2, 3, 4, 5]
# ```

def unique_list(list):
new_list=[]
for i in list:
if i in new_list:
continue
else:
new_list.append(i)
return new_list
unique_list([1,2,3,3,3,3,4,5,5])
14 changes: 14 additions & 0 deletions q5.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# ## 5-equal_reverse.py
# Write a function that controls the given inputs whether they are equal to their reversed order or not.

# Example:
# ```
# Input >>> madam, tacocat, utrecht
# Output >>> True, True, False
# ```
def reserved(x):
if x==x[::-1]:
return True
else:
return False
print(list(map(lambda x: reserved(x),['madam','tacocat','utrecht'])))