K
The problem is you used a or where it should be and: if signo1 != '-' or signo1 != '+':
Using or the condition will always be fulfilled, as if you put +Then it will be different from -But if you put - Then it will be different from +. One of the docks will always be true. But only if it's different from both (and) you should reject that input.It's quite common to get confused in this kind of comparisons, so I recommend you do something like if signo1 not in ["+", "-"] that in my opinion is less unequivocal.BonusI take the opportunity to tell you some better things in your code, in case they are of your interest.When the user enters wrong signo1For example, the program tells you it's wrong, but still continue and ask him signo2. The usual thing would be for me to keep asking him for signo1 until you receive a valid entry. This can be achieved with a loop while.The function code, as you could see, is very repetitive. The code that asks for each of the signs and values is exactly the same, only that it changes the variable in which it is going and slightly the message to the user to tell you what term or value it is introducing.This type of code so repetitive is a clear symptom that a loop can be used to make those repetitions, rather than copying the same instructions over and over again.The loop would be repeated 3 times, one for each term. You can have a variable that will take the values 1, 2, 3 to generate the appropriate messages with respect to which term is being requested.Instead of three variables signo1, signo2, signo3 (and so many for values), lists can be used. The lists allow you to go by adding elements to then iterate for them.Using these ideas the code could be rewritten in the following form, which you see is shorter. However it makes use of lists, which perhaps is a concept that you did not yet have, of a dictionary to translate numbers into words (1 is "first", 2 is "second", etc.) and of things like zip() to match elements of different lists. I invite you to study this code and ask what is not clear to you.def ecuaciones_3():
ordinal = { 1: "primer", 2: "segundo", 3: "tercer"}
signos = []
valores = []
for t in [1,2,3]: # Bucle que se repite para cada termino
print(f"Termino {t}, Ec 1:\n")
print("¿Es + o - ?\n")
signo = input()
while signo not in ["+", "-"]: # Bucle para volver a preguntar hasta que esté bien
print("Dato incorrecto vuelva a intentar")
signo = input()
# Añadir el signo a la lista de signos
signos.append(signo)
# Y el valor a la lista de valores
print(f"Ingrese el valor{t} del {ordinal[t]} termino:\n")
valor = float(input())
valores.append(valores)
Una vez introducidos los tres términos
print("Ingrese el resultado o Valor absoluto: \n")
result = float(input())
Imprimir cada término con su signo
for s,v in zip(signos, valores):
print(s,v, end=" ")
print( "=", resultado) # Imprimir resultado
return "done"