TCS CodeVita julio de 2019

Prueba de programación (Python)

1. Supongamos que el día dd-mm-aaaa se produjo un eclipse. Ahora, estamos interesados ​​en calcular la fecha en que ocurrirá el próximo eclipse. ( No resolvió )

Aporte:

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

Sentí que faltaban algunos detalles aquí.

2. Dado el monto invertido, el monto final obtenido a cambio y el período de inversión, averigüe la tasa de retorno simple y el retorno anualizado de esta inversión.

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.

Python

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:
10000
20000
5

Sample output:
20.00
14.87

3. Sam está interesado en los mercados y las inversiones. A menudo compra nuevas acciones y vende las que no tienen fines de lucro una vez. Para hacer lo mismo, busca la ayuda de un corredor que le cobra a Sam cierta cantidad. Averigüe cuánto le paga Sam al corredor por determinadas transacciones. ( Sin resolver: fallan algunos casos de prueba )

Input:
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).

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.

Python

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:
2
0.5
1 S1 100 B
2 S2 110 S

Sample output:
1.05

En general, la prueba no fue demasiado difícil, pero requirió algo de investigación para comprender el problema.

Publicación traducida automáticamente

Artículo escrito por GeeksforGeeks-1 y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *