-
Notifications
You must be signed in to change notification settings - Fork 0
/
usd_to_pen.py
77 lines (56 loc) · 2.06 KB
/
usd_to_pen.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# !pip install yfinance
import yfinance as yf
import numpy as np
''' Conversor de moneda '''
''' Código creado para ser corrido en la terminal '''
usd = yf.Ticker('PEN=X').history(period='1d')
last = usd.tail(1)
# Última cotización
date = last.index.strftime('%d-%m-%Y').astype(str)[0]
price = last['Close'].astype(float)[0]
# Interfaz
print(' ')
print('Hola! ¿Qué conversión deseas realizar?')
print(f'--- Cotización: S/ {np.round(price, 3)} por 1 US$ ---')
print(f'--- Actualizado en Yahoo Finance al {date} ---')
print('1: Dólares a Soles, o 2: Soles a Dólares')
given = input('... ')
print(' ')
while True:
try:
if int(given) == 1:
print('¿Cuántos dólares deseas convertir?')
try:
usd_given = float(input('... US$ '))
pen_conv = price * usd_given
print(' ')
print(f'US$ {usd_given} equivale a S/ {np.round(pen_conv, 3)}')
print(' ')
except:
print('Ups! Quizás tipeaste mal la operación.')
elif int(given) == 2:
print('¿Cuántos soles deseas convertir?')
try:
pen_given = float(input('... S/ '))
usd_conv = pen_given/price
print(' ')
print(f'S/ {pen_given} equivale a US$ {np.round(usd_conv, 3)}')
print(' ')
except:
print('Ups! Quizás tipeaste mal la operación.')
print('¿Deseas continuar? [Y/N]')
solution_given = str(input('... '))
if solution_given == 'Y':
continue
else:
break
except:
print('Ups! Quizás tipeaste mal la operación.')
print('¿Deseas continuar? [Y/N]')
solution_given = str(input('... '))
if solution_given == 'Y':
print('1: Dólares a Soles, o 2: Soles a Dólares')
given = int(input('... '))
continue
else:
break