Skip to content

Instantly share code, notes, and snippets.

@SlyCodePanda
Created December 19, 2018 04:31
Show Gist options
  • Save SlyCodePanda/d9a056ed1ab639003264ead6d7726ad3 to your computer and use it in GitHub Desktop.
Save SlyCodePanda/d9a056ed1ab639003264ead6d7726ad3 to your computer and use it in GitHub Desktop.
Learning to use pytest with a HackerRank challenge.
def 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()
result = sum(student_marks[name])/n
print(result/n)
print('%.2f' % result)
'''
Run this to test the findingPercentage.py file.
run : pytest findingPercentage_test01.py
'''
import findingPercentage
def test_app(capsys):
input_values = [2, 'Harsh 25 26.5 28', 'Anurag 26 28 30', 'Harsh']
def mock_input():
return input_values.pop(0)
findingPercentage.input = mock_input
findingPercentage.main()
out, err = capsys.readouterr()
assert out == '26.50'
assert err == ''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment