TCS CodeVita July 2019

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:



    Input: The date in format dd-mm-yyyy
    Output: Desired date in yyyy-mm-dd format
    Constraints:
        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.

    Input: 
    1st line contains amount invested. 
    2nd line contains amount returned. 
    3rd line contains period of investment.
    
    Output: 
    1st line contains simple rate of return. 
    2nd line contains annualized return. 
    Output must be rounded off to up to 2 decimal places.
    
    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    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

    chevron_right

    
    

    Sample input:
    10000
    20000
    5
    
    Sample output:
    20.00
    14.87
    
  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)

    Input:
    1st line contains no. of stocks Sam deals with (N). 2nd line contians 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).
    
    Output:
    Total amount Sam pays to the broker. The output will be upto 2 decimal places and the value will be rounded off to DOWN.
    
    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    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)

    chevron_right

    
    

    Sample input:
    2
    0.5
    1 S1 100 B
    2 S2 110 S
    
    Sample output:
    1.05
    

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


Write your Interview Experience or mail it to contribute@geeksforgeeks.org




My Personal Notes arrow_drop_up

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.