Skip to content
Related Articles

Related Articles

TCS CodeVita July 2019

View Discussion
Improve Article
Save Article
  • Last Updated : 12 Jan, 2022

Programming test (Python)

1. Suppose on dd-mm-yyyy an eclipse occurred. Now, we are interested to calculate the date when next eclipse occurs. (Didn’t solve)


Input: The date in format dd-mm-yyyy
Output: Desired date in yyyy-mm-dd format
    It is guaranteed that given date is valid.
    01 <= dd <= 31
    01 <= mm <= 12
    1900 <= yy <= 2100

I felt some details were missing here.

2. Given the amount invested, final amount got in return and the period of investment, found out the simple rate of return and annualized return for this investment.

1st line contains amount invested. 
2nd line contains amount returned. 
3rd line contains period of investment.

1st line contains simple rate of return. 
2nd line contains annualized return. 
Output must be rounded off to up to 2 decimal places.


import sys, os
amount_invested = float(raw_input())
final_amount = float(raw_input())
period = float(raw_input())
temp_val = ((final_amount - amount_invested)) / amount_invested
rate = ((final_amount - amount_invested) * 100.0) / amount_invested / period
annualized_return = round(((1 + temp_val) ** (1 / period) - 1) * 100.0, 2)
print "%.2f" % round(rate, 2)
print "%.2f" % annualized_return

Sample input:

Sample output:

3. Sam is interested in markets and investments. He often buys new stock and sell the non-profiting once. In order to do the same, he takes help for a broker who charges Sam certain amount. Find out how much does Sam pay the broker for given transactions. (Unsolved – some test cases failing)

1st line contains no. of stocks Sam deals with (N). 2nd line contains constant brokerage rate that the broker takes from Sam for every transaction (B).
The next lines will have stock details in the form: Volume or numbers of a stock, stock name, unit price of stock, bought/sold (B/S).

Total amount Sam pays to the broker. The output will be upto 2 decimal places and the value will be rounded off to DOWN.


n = int(raw_input())
broker_rate = float(raw_input())
total_turnover = 0.0
for i in range(n):
    lst = raw_input().split()
    total_turnover += float(lst[0]) * float(lst[2])
fee = total_turnover * broker_rate
print "%.2f" % (fee / 100.0)

Sample input:
1 S1 100 B
2 S2 110 S

Sample output:

Overall, the test was not too difficult but required some research to understand the problem.

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!