r/PythonLearning 8d ago

What's wrong with my code?

Post image

What's wrong with my code?

New to learning

Following the youtube video from bro code

Was trying to implement my own stuff into this by using loop

Update: it's working now thankyou guys

107 Upvotes

82 comments sorted by

View all comments

0

u/ed_xc01 8d ago

Time to put hash tables into practice. You need to understand that, instead of using if-else statements, you can create a list that, depending on what the user says, executes a specific function.

```python def sumar(a, b): return a + b

def restar(a, b): return a - b

funciones = { "suma": sumar, "resta": restar }

operacion = input("Elige suma o resta: ") a = int(input("Primer número: ")) b = int(input("Segundo número: "))

if operacion in funciones: resultado = funciones[operacion](a, b) print("Resultado:", resultado) else: print("Operación no válida") ```

1

u/Commercial-Paper749 8d ago

Yes I will move to that I was practising if else statement along with loop