hacker rank py
if __name__ == '__main__':
n = int(input())
student_marks = {}
for _ in range(n):
name, *line = input().split()
scores = list(map(float, line))
student_marks[name] = scores
query_name = input()
for name in student_marks:
if name==query_name:
a=student_marks[name]
print(format(sum(a)/len(a),'.2f'))
#o/p is:
2
faizan 20 20
umar 30 20
faizan
20.00
#sunday:
def print_full_name(first_name, last_name):
# Write your code here
print(f'Hello {first_name} {last_name}! You just delved into python.')
if __name__ == '__main__':
first_name = input()
last_name = input()
print_full_name(first_name, last_name)
#o/p is:
faizan
umar
Hello faizan umar! You just delved into python.
#split and join:
def split_and_join(line):
# write your code here
split=line.split(" ")
join="-".join(split)
return join
if __name__ == '__main__':
line = input()
result = split_and_join(line)
print(result)
#o/p is:
I am faizan
I-am-faizan
'''
textwrap.TextWrapper(width=max_width):
Creates a TextWrapper object that wraps text to the specified max_width.
wrapper.fill(text=string):
Wraps the string into lines of max_width and returns a single string with line breaks.
((wrapper.wrap) stores it as a list while (wrapper.fill) stores it as a string)
'''
import textwrap
def wrap(string, max_width):
wrapper = textwrap.TextWrapper(width=max_width)
result = wrapper.wrap(text=string)
if max_width<=len(string):
return'\n'.join (result)
else:
print('invalid input')
if __name__ == '__main__':
string, max_width = input(), int(input())
result = wrap(string, max_width)
print(result)
#o/p is:
3
abc
def
ghj
kl
Comments
Post a Comment