Counting Coins – Create a function to calculate the sum of coins, read Input from STDIN and print output to STDOUT

Counting Coins using python

Counting Coins

Problem Statement:

Create a function which can calculate the sum of the total amount of coins, the function should accept four arguments which denotes the number of two rupee coins, five rupee coins, ten rupee coins and hundred rupees as input and return the total values of the each coin and find total amount.

Sample Case 0

Sample Input

1 1 1 1

Sample Output

2
5
10
100
117

Explanation

In this case, we have one 2 rupee coin, one 5 rupee coin, one 10 rupee coin and one 100 rupee coin, so the total amount of coins will be

1 x 2    = 2
1 x 5    = 5
1 x 10   = 10
1 x 100  = 100

and their total sum will be 2 + 5 + 10 + 100 = 117

Sample Case 1

Sample Input

5 10 1 1

Sample Output

10
50
10
100
170

Explanation

In this case, we have five 2 rupee coin, ten 5 rupee coin, one 10 rupee coin and one 100 rupee coin, so the total amount of coins will be

5 x 2    = 10
10 x 5   = 50
1 x 10   = 10
1 x 100  = 100

and their total sum will be 10 + 50 + 10 + 100 = 170

Solution:

import sys
# Receiving input from STDIN
for line in sys.stdin:
  row_string = line

# Mapping string to list of integers
row_string_list = row_string.split()
map_int = map(int, row_string_list)
int_list = list(map_int)

# Counting functions
def SumCoin(tows, fives, tens, hundreds):
  count_list = []
  count_list.append(tows * 2)
  count_list.append(fives * 5)
  count_list.append(tens * 10)
  count_list.append(hundreds * 100)
  
  for i in count_list:
    print(i)
  sum_of_coins = sum(count_list)
  print(sum_of_coins)


sys.stdout = SumCoin(int_list[0], int_list[1], int_list[2], int_list[3])

Output:

$python counting_coins.py 1 1 1 1
2
5
10
100
117
Lokesh Kumar: Being EASTER SCIENCE's founder, Lokesh Kumar wants to share his knowledge and ideas. His motive is "We assist you to choose the best", He believes in different thinking.
Related Post
Leave a Comment

This website uses cookies.