Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit d9f9111

Browse files
hackerrank
1 parent b4262a7 commit d9f9111

File tree

5 files changed

+111
-0
lines changed

5 files changed

+111
-0
lines changed

‎Hackerrank-Python3/SplitandJoin.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#Task
2+
#You are given a string. Split the string on a " " (space) delimiter and join using a - hyphen
3+
4+
def split_and_join(line):
5+
s = ""
6+
s = line.split(" ")
7+
s = '-'.join(s)
8+
print(s)
9+
split_and_join("praveen kumar srivas")

‎Hackerrank-Python3/find_string.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Output Format
2+
3+
# Output the integer number indicating the total number of occurrences of the substring in the original string.
4+
5+
# Sample Input
6+
7+
# ABCDCDC
8+
# CDC
9+
# Sample Output
10+
11+
# 2
12+
13+
14+
def count_substring(string, sub_string):
15+
l = len(string)
16+
c = 0
17+
match = ""
18+
indx = 0
19+
x = 0
20+
z = 0
21+
for x in range(l):
22+
z = 0
23+
z = x
24+
for y in range(len(sub_string)):
25+
match += string[z]
26+
z += 1
27+
if (z > (l - 1)):
28+
break
29+
#print(z)
30+
31+
if (match == sub_string):
32+
c += 1
33+
z = 0
34+
match = ""
35+
else:
36+
match = ""
37+
z=0
38+
39+
return c
40+
41+
42+
if __name__ == '__main__':
43+
string = input().strip()
44+
sub_string = input().strip()
45+
46+
count = count_substring(string, sub_string)
47+
print(count)

‎Hackerrank-Python3/function.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
# In the Gregorian calendar three criteria must be taken into account to identify leap years:
3+
4+
# The year can be evenly divided by 4, is a leap year, unless:
5+
# The year can be evenly divided by 100, it is NOT a leap year, unless:
6+
# The year is also evenly divisible by 400. Then it is a leap year.
7+
8+
9+
def is_leap(year):
10+
year = int(year)
11+
leap = False
12+
if (year % 4 == 0 and (year % 100 != 0 and year % 400 == 0)):
13+
leap = True
14+
return leap
15+
16+
17+
year = int(input())
18+
print(is_leap(year))

‎Hackerrank-Python3/if-else.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Task
2+
# Given an integer, , perform the following conditional actions:
3+
4+
# If is odd, print Weird
5+
# If is even and in the inclusive range of to, print Not Weird
6+
# If is even and in the inclusive range of to, print Weird
7+
# If is even and greater than, print Not Weird
8+
9+
n = int(input())
10+
if (n % 2 != 0):
11+
print('weird')
12+
elif (n % 2 == 0 and n >= 2 and n <= 5):
13+
print('Not Weird')
14+
elif (n % 2 == 0 and n >= 6 and n <= 20):
15+
print('weird')
16+
else:
17+
print("Not Weird")

‎Hackerrank-Python3/mutation.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Sample Input:
2+
# abracadabra
3+
# 5 k
4+
5+
# Sample Output:
6+
# abrackdabra
7+
# Using any of the methods explained above, replace the character at index k with giving character .
8+
9+
10+
def mutate_string(string, position, character):
11+
new = ""
12+
new=string[:position]+character+string[position+1:]
13+
return new
14+
15+
16+
if __name__ == '__main__':
17+
s = input()
18+
i, c = input().split()
19+
s_new = mutate_string(s, int(i), c)
20+
print(s_new)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /