Ich bin neu in diesem Zeug, ich arbeite derzeit in einem Schulprojekt über einen Matrixrechner. Ich möchte die beiden Matrix eingeben und wenn ich auf eine Schaltfläche klicke, wird die Lösung des Vorgangs gedruckt. < /p>
import numpy as np
from IPython.display import clear_output, display
import ast
import ipywidgets as widgets
from ipywidgets.widgets import Output
escalar = None
output = Output()
def in_matriz():
print("ingrese la ",i+1," matriz en forma de lista de listas (Ejemplo: [1,2,3],[4,5,6],[7,8,9]))")
return np.array(ast.literal_eval(input()))
def in_escalar():
print("ingrese el escalar/potencia")
return int(input())
def on_btn_clic(btn):
with output:
print(resultado_m)
while True:
print("Menú"+"\n1) Calculadora científica."+"\n2) Calculadora de matrices."+"\n3) Salir.")
opcion = input("Seleccione una opción: ")
match opcion:
case "1":
.
.
.
case "2":
while True:
print("Has elegido Calculadora de matrices: ")
operacion = input("#here there is the operation menu")
continue
mapping={
#here I define all the operations
}
if operacion in ["1","2","3","4","6","8","9"]:
rango = 2
else:
rango = 1
for i in range(rango):
if i==0:
a_matriz=in_matriz()
#here the operations that only need one matriz
elif i==1:
b_matriz=in_matriz()
#here the operations that need two matriz
if operacion in ["5","7"]:
escalar=in_escalar()
try:
if operacion in ["10","11","12","13"]:
resultado_m = mapping[operacion](a_matriz)
def on_btn_clic(btn):
with output:
print(resultado_m)
boton2 = widgets.Button(description="Ver resultado")
boton2.on_click(on_btn_clic)
display(boton2, output)
elif operacion in ["5","7"]:
resultado_m = mapping[operacion](escalar, a_matriz)
def on_btn_clic(btn):
with output:
print(resultado_m)
boton2 = widgets.Button(description="Ver resultado")
boton2.on_click(on_btn_clic)
display(boton2, output)
else:
resultado_m = mapping[operacion](a_matriz, b_matriz)
def on_btn_clic(btn):
with output:
print(resultado_m)
boton2 = widgets.Button(description="Ver resultado")
boton2.on_click(on_btn_clic)
display(boton2, output)
except ValueError:
.
.
.
break
< /code>
Ich glaube nicht, dass das Problem mit der Lösung des Vorgangs selbst liegt, da ich im Variablen -Manager sehen kann, dass es (resultado_m) die Lösung des Vorgangs korrekt zugewiesen hat. Wie es jetzt ist, druckt es nichts, ich habe versucht, Anzeige anstelle von Druck zu verwenden, und die Funktion in den Inneren des Try -Blocks BC zu verschieben. Vielleicht ist das Problem, dass die Variable außerhalb des Try -Blocks nicht erkannt wird. Nichts hat geholfen, und wenn ich auf den Knopf klicke, wird nichts gedruckt.>
Wie kann ich dem On_Click -Ereignis erfolgreich eine Funktion zuweisen? ⇐ Python
-
- Similar Topics
- Replies
- Views
- Last post