CODEZEROINTERACTIVE

Chapter 7 / 15

Parte 16 — Registrar varios movimientos

Entrada de datos con input(), conversiones, respuestas del usuario y formulario interactivo de MiniFinance.

Lesson 1738%

17 / 22 lessons in this chapter

Parte 16 — Registrar varios movimientos

1 / 1 in this part

Current chapter

Chapter 7 — input(): recibir información del usuario

Self-paced

Parte 16 — Registrar varios movimientos

Solicitar dos ingresos

python terminal
ingreso_1 = int(input("Primer ingreso: "))
ingreso_2 = int(input("Segundo ingreso: "))

total_ingresos = ingreso_1 + ingreso_2

Solicitar dos gastos

python terminal
gasto_1 = int(input("Primer gasto: "))
gasto_2 = int(input("Segundo gasto: "))

total_gastos = gasto_1 + gasto_2

Calcular el saldo

python terminal
saldo_actual = saldo_inicial + total_ingresos - total_gastos

Ejemplo:

text terminal
Saldo inicial: 1000
Ingreso 1: 500
Ingreso 2: 250
Gasto 1: 200
Gasto 2: 100

Cálculo:

text terminal
1000 + 500 + 250 - 200 - 100 = 1450

Limitación actual

Si queremos registrar diez movimientos, necesitaríamos crear:

python terminal
ingreso_1
ingreso_2
ingreso_3

y muchas variables adicionales.

Eso no es práctico.

Más adelante aprenderemos listas y bucles para almacenar una cantidad flexible de movimientos.

Por ahora, utilizar dos o tres movimientos nos permite practicar input() y conversiones.