Skip to content

Commit 6a2bca9

Browse files
Add files via upload
1 parent 6624475 commit 6a2bca9

File tree

18 files changed

+1465
-0
lines changed

18 files changed

+1465
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
def case_converter(string):
2+
"""
3+
Given string as input, if string has more uppercase letters
4+
than lowercase print string in all uppercase. Otherwise, does
5+
the oppsite.
6+
"""
7+
# We can get the uppercase and lowercase letter count by this method. But using map and sum is more cleaner method.
8+
#
9+
# lower_case = ""
10+
# upper_case = ""
11+
# for char in string:
12+
# if ord(char) >= 65 and ord(char) <= 90:
13+
# upper_case += char
14+
# else: #Since input only contains uppercase and lowercase, checking one condition should be enough.
15+
# lower_case += char
16+
#
17+
# total_lower = len(lower_case)
18+
# total_upper = len(upper_case)
19+
20+
total_lower = sum(map(str.islower, string))
21+
total_upper = sum(map(str.isupper, string))
22+
23+
if total_upper > total_lower:
24+
return string.upper()
25+
else:
26+
return string.lower()
27+
28+
29+
user_input = input()
30+
result = case_converter(user_input)
31+
print(result)
32+
33+
# print(case_converter.__doc__) # Access docstring
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
def char_checker(string):
2+
"""
3+
Check wheater a string is number, word or mixed with digits and letters.
4+
"""
5+
ref_str = "0123456789"
6+
len_str = len(string)
7+
count = 0
8+
9+
for i in string:
10+
if i in ref_str:
11+
count += 1
12+
13+
if count == 0:
14+
print("WORD")
15+
elif count < len_str:
16+
print("MIXED")
17+
elif count == len_str:
18+
print("NUMBER")
19+
20+
21+
user_input = input()
22+
char_checker(user_input)
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
def lower_substr(string):
2+
"""
3+
Given a string with two uppercase characters, prints the lowercase characters
4+
between the two uppercase characters.
5+
"""
6+
upper_count = sum(map(str.isupper, string))
7+
if upper_count == 2:
8+
for i in string:
9+
if i.isupper():
10+
start = string.find(i)
11+
new_str = string.replace(i, i.lower())
12+
break
13+
14+
for i in new_str:
15+
if i.isupper():
16+
end = new_str.find(i)
17+
break
18+
19+
var = string[start + 1 : end]
20+
if var != "":
21+
print(var)
22+
else:
23+
print("BLANK")
24+
25+
else:
26+
print("More than 2 uppercase chracters")
27+
28+
29+
user_input = input()
30+
lower_substr(user_input)
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
def replace_word(string):
2+
"""
3+
Given a string, this function search for the substring "too good".
4+
If it find that, then replaces the substring with another substring
5+
"execellent" and returns the modified string. Otherwise, it returns
6+
the original string
7+
"""
8+
# We can do the program like below which don't use replace method. Or, we can just use find and replace method.
9+
#
10+
# replaced_str = ""
11+
# pos = -1
12+
# for i in range(len(string)):
13+
# if string[i] == "t" and string[i + 1] == "o" and string[i + 2] == "o" and string[i + 3] == " " and string[i + 4] == "g" and string[i + 5] == "o" and string[i + 6] == "o" and string[i + 7] == "d":
14+
# pos = i
15+
# break
16+
#
17+
#
18+
# if pos != -1:
19+
# replaced_str = string[:pos] + "execellent" + string[pos + len("too good"):]
20+
# print(replaced_str)
21+
# elif pos == -1:
22+
# print(string)
23+
24+
pos = string.find("too good")
25+
if pos == -1:
26+
print(string)
27+
elif pos != -1:
28+
new_str = string.replace("too good", "execellent")
29+
print(new_str)
30+
31+
32+
user_name = input()
33+
replace_word(user_name)
34+
35+
# print(replace_word.__doc__) # Access Docstring.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
def common_char(input_list):
2+
"""
3+
Given two strings, this function prints a new string with
4+
the common characters of the origal two string.
5+
"""
6+
if len(input_list[0]) < len(input_list[1]):
7+
ref_str = input_list[1]
8+
str_var = input_list[0]
9+
else:
10+
ref_str = input_list[0]
11+
str_var = input_list[1]
12+
13+
new_str = ""
14+
for i in str_var:
15+
if i in ref_str:
16+
new_str += i
17+
18+
for i in ref_str:
19+
if i in str_var:
20+
new_str += i
21+
22+
if new_str == "":
23+
print("Nothing in common")
24+
else:
25+
print(new_str)
26+
27+
28+
user_input = input().split(",")
29+
common_char(user_input)
30+
31+
# print(common_char.__doc__) # Acess Docstring.
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
def is_Spec_Char(character):
2+
"""
3+
Given a character, this function checks wheater a character is
4+
one of the four special characters.
5+
"""
6+
spec_char = "_$#@"
7+
if character in spec_char:
8+
return True
9+
else:
10+
return False
11+
12+
13+
def password_checker(password):
14+
"""
15+
Given a password as string, this function checks wheater the password
16+
fulfills the four requirements :
17+
1. At least one lowercase letter
18+
2. At least one uppercase letter
19+
3. At least one digit (0-9)
20+
4. At least one special character (_,$,#,@)
21+
If the password does not fulfill the requirements if returns one of the
22+
four specific errors. Otherwise, if all the reqirments are met, it
23+
returns "OK".
24+
"""
25+
lower_count = sum(map(str.islower, password))
26+
upper_count = sum(map(str.isupper, password))
27+
digit_count = sum(map(str.isdigit, password))
28+
spec_count = sum(map(is_Spec_Char, password))
29+
30+
error = ""
31+
if lower_count == 0:
32+
error = "Lowercase Chracter Missing"
33+
34+
if upper_count == 0:
35+
if error != "":
36+
error += ", "
37+
error += "Uppercase Chracter Missing"
38+
39+
if digit_count == 0:
40+
if error != "":
41+
error += ", "
42+
error += "Digit Missing"
43+
44+
if spec_count == 0:
45+
if error != "":
46+
error += ", "
47+
error += "Special Chracter Missing"
48+
49+
if error == "":
50+
print("OK")
51+
else:
52+
print(error)
53+
54+
55+
password = input()
56+
password_checker(password)
57+
58+
# print(password_checker.__doc__) # Acess Docstring
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
def universal_list(number):
2+
"""
3+
Given number as string input, this function convert the string
4+
into an integer and add the integer to the List named "ref_list".
5+
"""
6+
global ref_list
7+
temp = [int(number)]
8+
ref_list += temp
9+
10+
11+
user_input = input()
12+
ref_list = []
13+
while user_input != "STOP":
14+
universal_list(user_input)
15+
user_input = input()
16+
17+
18+
frequency = [[num, ref_list.count(num)] for num in ref_list]
19+
frequency = sorted(
20+
frequency, key=lambda x: x[0]
21+
) # Sorting the frequency list by the first element (number) the of the sublist
22+
23+
sorted_frequency = []
24+
[
25+
sorted_frequency.append(item) for item in frequency if item not in sorted_frequency
26+
] # Creating a list with unique items
27+
28+
for inpt, outpt in sorted_frequency:
29+
print(f"{inpt} - {outpt} times")
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
def sum_list(lst):
2+
"""
3+
Given a list as input, this function checks wheater the sum of given
4+
list is maximum among the input lists.
5+
"""
6+
global max_sum, max_lst
7+
lst_sum = sum(lst)
8+
if lst_sum > max_sum:
9+
max_sum = lst_sum
10+
max_lst = lst
11+
12+
13+
N = int(input())
14+
max_sum = 0
15+
max_lst = []
16+
for i in range(N):
17+
lst = [int(num) for num in input().split()]
18+
sum_list(lst)
19+
20+
print(max_sum)
21+
print(max_lst)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
def list_multiplication(lst_1, lst_2):
2+
"""
3+
Given two list as input, this function returns a new list
4+
containing the cross multiplication product between the given
5+
two lists.
6+
"""
7+
return [(i * j) for i in lst_1 for j in lst_2]
8+
9+
10+
list_1 = [int(num) for num in input().split()]
11+
list_2 = [int(num) for num in input().split()]
12+
result = list_multiplication(list_1, list_2)
13+
print(result)
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
def UB_Jupmer(List):
2+
"""
3+
Given a list as input, this function returns True if the input
4+
list is a UB Jumper or return False otherwise.
5+
"""
6+
ref_list = [num for num in range(1, len(List))]
7+
abs_diff = []
8+
9+
for i in range(len(List) - 1):
10+
elem = List[i] - List[i + 1]
11+
elem = abs(elem)
12+
abs_diff.append(elem)
13+
14+
if sorted(ref_list) == sorted(abs_diff):
15+
return True
16+
else:
17+
return False
18+
19+
20+
user_input = input()
21+
result = []
22+
while user_input != "STOP":
23+
List = [int(num) for num in user_input.split()]
24+
25+
if UB_Jupmer(List):
26+
result.append("UB Jumper")
27+
else:
28+
result.append("Not UB Jumper")
29+
30+
user_input = input()
31+
32+
for output in result:
33+
print(output)

0 commit comments

Comments
 (0)