Skip to content

Commit b3c2124

Browse files
committed
Day 14 and Day 15
1 parent 01c355d commit b3c2124

File tree

6 files changed

+106
-0
lines changed

6 files changed

+106
-0
lines changed

Day14/q49.py

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Problem Link -> https://www.hackerrank.com/challenges/string-validators/problem
2+
3+
__author__ = "Mahtab Alam"
4+
5+
s = input()
6+
for test in ('isalnum', 'isalpha', 'isdigit', 'islower', 'isupper'):
7+
print(any(eval("c." + test + "()") for c in s))

Day14/q50.py

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Problem link -> https://www.hackerrank.com/challenges/capitalize/problem
2+
3+
__author__ = "Mahtab Alam"
4+
5+
6+
def cap(s):
7+
l = s.split(" ")
8+
a = [i.capitalize() for i in l]
9+
return " ".join(a)
10+
11+
12+
s = input()
13+
print(cap(s))

Day14/q51.py

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Problem Link => https://www.hackerrank.com/challenges/whats-your-name/problem
2+
3+
__author__ = "Mahtab Alam"
4+
5+
6+
def print_full_name(a, b):
7+
print("Hello {0}{1}! You just delved into python.".format(a, b))
8+
9+
10+
if __name__ == '__main__':
11+
first_name = input()
12+
last_name = input()
13+
print_full_name(first_name, last_name)

Day15/q52.py

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
from math import pow
2+
3+
4+
class Complex:
5+
def __init__(self, real, imag):
6+
self.real = real
7+
self.imag = imag
8+
9+
def __add__(self, other):
10+
return Complex(self.real+other.real, self.imag+other.imag)
11+
12+
def __sub__(self, other):
13+
return Complex(self.real-other.real, self.imag-other.imag)
14+
15+
def __mul__(self, other):
16+
return Complex(self.real*other.real-self.imag*other.imag, self.real*other.imag+self.imag*other.real)
17+
18+
def __truediv__(self, other):
19+
try:
20+
return self.__mul__(Complex(other.real, -1*other.imag)).__mul__(complex(1.0/(other.mod().real)**2, 0))
21+
except ZeroDivisionError as e:
22+
print(e)
23+
return None
24+
25+
def mod(self):
26+
return Complex(pow(self.real**2+self.imag**2, 0.5), 0)
27+
28+
def __str__(self, precision=2):
29+
return str(("%."+"%df" % precision) % float(self.real))+('+' if self.imag >= 0 else '-')+str(("%."+"%df" % precision) % float(abs(self.imag)))+'i'
30+
31+
32+
33+
34+
if __name__ == '__main__':
35+
c = map(float, input().split())
36+
d = map(float, input().split())
37+
x = Complex(*c)
38+
y = Complex(*d)
39+
print(*map(str, [x+y, x-y, x*y, x/y, x.mod(), y.mod()]), sep='\n')

Day15/q53.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Write a Python class named Rectangle constructed by a length and width and a method which will compute the area of a rectangle.
2+
3+
__author__ = "Mahtab Alam"
4+
5+
class Rectangle:
6+
def __init__(self, length, breadth):
7+
self.length = length
8+
self.breadth = breadth
9+
10+
def area(self):
11+
return self.length * self.breadth
12+
13+
14+
newRectangle = Rectangle(10, 12)
15+
16+
print(newRectangle.area())

Day15/q54.py

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Write a Python class which has two methods get_String and print_String. get_String accept a string from the user and print_String print the string in upper case.
2+
3+
__author__ = "Mahtab Alam"
4+
5+
class IOstring:
6+
def __init__(self):
7+
self.str = ""
8+
9+
def get_string(self):
10+
self.str = input()
11+
12+
def print_string(self):
13+
print(self.str.upper())
14+
15+
16+
string = IOstring()
17+
string.get_string()
18+
string.print_string()

0 commit comments

Comments
 (0)