The Brain Booster
Python Data Structure Sololearn Course
PYTHON DATA STRUCTURE PROGRAM CODE FILE:-https://docs.google.com/document/d/1AKMIXWqYCA2-Ic0I8GBNDDJ_mtVGNRLoQi-8lVe5cU8/edit?usp=sharingThe Brain Booster
Python Data Structures
1] Letter Frequency
#your code goes here
string = input("")
string1 = input("")
number = 0
i = string1
for i in string:
if i == string1:
number += 1
#print(number)
len = len(string)
calc = number/len*100
print(int(calc))
2] Average Word Length
0
text = input()
a = text.split()
b=len(a)
only_alpha = ""
for i in text:
if i.isalpha():
only_alpha += i
print(len(only_alpha)/b)
3] Ticket Office
data = {
"100-90": 25, "42-01": 48, "55-09": 12, "128-64": 71, "002-22": 18, "321-54": 19, "097-32": 33, "065-135": 64,
"99-043": 80, "111-99": 11, "123-019": 5, "109-890": 72, "132-123": 27, "32-908": 27, "008-09": 25, "055-967": 35,
"897-99": 44, "890-98": 56, "344-32": 65, "43-955": 59, "001-233": 9, "089-111": 15, "090-090": 17, "56-777": 23,
"44-909": 27, "13-111": 21, "87-432": 15, "87-433": 14, "87-434": 23, "87-435": 11, "87-436": 12, "87-437": 16,
"94-121": 15, "94-122": 35, "80-089": 10, "87-456": 8, "87-430": 40
}
age = int(input())
# your code goes here
new = 0
old = 530
for var in data.values():
if var < age:
new += 5
else:
new += 20
if age < 18:
print(int((new - old) / old * 100))
else:
print(0)
4] Balanced Parentheses
# Function to test balanced brackets
def BalancedBrackets(Str):
# stack for storing opening brackets
stack = []
# Loop for checking string
for char in Str:
# if its opening bracket, so push it in the
# stack
if char == '{' or char == '(' or char == '[':
stack.append(char) # push
# else if its closing bracket then
# check if the stack is empty then return false or
# pop the top most element from the stack
# and compare it
elif char == '}' or char == ')' or char == ']':
if len(stack) == 0:
return False
top_element = stack.pop() # pop
# function to compare whether two
# brackets are corresponding to each other
if not Compare(top_element, char):
return False
# lastly, check that stack is empty or not
if len(stack) != 0:
return False
return True
# Function to check two corresponding brackets
# equal or not.
def Compare(opening, closing):
if opening == '(' and closing == ')':
return True
if opening == '[' and closing == ']':
return True
if opening == '{' and closing == '}':
return True
return False
# Test function
exp=input()
print(BalancedBrackets(exp))
#print(BalancedBrackets("{123(456[.768])}"))
0 Comments