Я пытаюсь написать программу с математической задачей ⇐ Python
-
Anonymous
Я пытаюсь написать программу с математической задачей
I am in a Mathmatics Club on school. And I wanted to write a program, which answers the following question. An unknown starting number is subtracted from the 1 fifth, and then a half. In the end, another 64 are deducted. The solution: a table I wrote a code, but its DEFINATLY not working. I must say, that i am not good at programming and a child. Here is the code:
##### math ########## from tkinter import * from fractions import Fraction from math import * # generate variables width= 600 height= 600 # generate functions def Ftwo(): EL.pack() FE.place(x=350,y=3) SE.place(x=277,y=17) TE.place(x=386,y=31) OkB.place(x=100,y=100, width=450, height=300) def pressSEB(): SEB.place_forget() Ftwo() def OkBpress(): FEOutputx=FE.get() SEOutputx=SE.get() TEOutputx=TE.get() print(FEOutputx, SEOutputx, TEOutputx) if FEOutputx=="" or SEOutputx=="" or TEOutputx=="": print("Don't do this! LG Lasse") quit() else: mathematics(FEOutputx, SEOutputx, TEOutputx) ## Tkinter ## # Fenster Fenster=Tk() Fenster.geometry(f"{width}x{height}") Fenster.title("Mathematik-Aufgabe") # StringVar v = StringVar() v.set("*") # generate Widgets SEB=Button(Fenster,text="Starten", bg='red', command=pressSEB) EL=Label(Fenster,text="Aufgabe: Annika wirft beim Faschingumzug ihrer Bongbongs \n vom Umzugswagen. der restlichen Bonbongs \n behaelt Annika für ihre Geburtstagsparty. Die letzten Bongbongs darf \n ihr kleiner Bruder Max werfen. \n Wie viele Bongbongs hatte sie am Anfang?") FE=Entry(Fenster, bg='blue', width=6) SE=Entry(Fenster, width=4, bg='blue', textvariable = v) TE=Entry(Fenster, width=2, bg='blue') SL=Label(Fenster, text="* Anteil eingeben, Schreibweise als Kommazahl: a.b bsp: 1/5 (ein fuenftel)") OkB=Button(Fenster, command=OkBpress, text="Ok") #Widgets placen SEB.place(x=300, y=300, width=60, height=60) ################## Mathematischer Teil ################## def mathematics(FEOutput, SEOutput, TEOutput): anfang=100 t=anfang # int-en SEOutputL=SEOutput.split("/") FEOutputL=FEOutput.split("/") SEOutputL[0]=int(SEOutputL[0]) SEOutputL[1]=int(SEOutputL[1]) FEOutputL[0]=int(FEOutputL[0]) FEOutputL[1]=int(FEOutputL[1]) TEOutput=int(TEOutput) print("t:",t) liste=[[0,0,0,0," "]] # Startwerte anfang=100 # Anfang, als erstes auf 100 ermWL=[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,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100] t=0 # The amount that comes out of the invoice erreicht=False while erreicht==False: t=anfang t=t/FEOutputL[0] # Taking fractions t=t*FEOutputL[1] t=t/SEOutputL[0] t=t*SEOutputL[1] # Check if t is too big, too small, or correct if t == TEOutput: command= "richtig!" erreicht=True elif t > TEOutput: command= "Zu Gross!" # Everything in the list that is => t has to go while anfang not in ermWL: a=ermWL[-1] print(f"a:{a}") ermWL.append(a+1) for z in ermWL: if z >= anfang : ermWL.remove(z) elif t < TEOutput: command= "Zu Klein" for i in ermW: if i
Источник: https://stackoverflow.com/questions/780 ... -math-task
I am in a Mathmatics Club on school. And I wanted to write a program, which answers the following question. An unknown starting number is subtracted from the 1 fifth, and then a half. In the end, another 64 are deducted. The solution: a table I wrote a code, but its DEFINATLY not working. I must say, that i am not good at programming and a child. Here is the code:
##### math ########## from tkinter import * from fractions import Fraction from math import * # generate variables width= 600 height= 600 # generate functions def Ftwo(): EL.pack() FE.place(x=350,y=3) SE.place(x=277,y=17) TE.place(x=386,y=31) OkB.place(x=100,y=100, width=450, height=300) def pressSEB(): SEB.place_forget() Ftwo() def OkBpress(): FEOutputx=FE.get() SEOutputx=SE.get() TEOutputx=TE.get() print(FEOutputx, SEOutputx, TEOutputx) if FEOutputx=="" or SEOutputx=="" or TEOutputx=="": print("Don't do this! LG Lasse") quit() else: mathematics(FEOutputx, SEOutputx, TEOutputx) ## Tkinter ## # Fenster Fenster=Tk() Fenster.geometry(f"{width}x{height}") Fenster.title("Mathematik-Aufgabe") # StringVar v = StringVar() v.set("*") # generate Widgets SEB=Button(Fenster,text="Starten", bg='red', command=pressSEB) EL=Label(Fenster,text="Aufgabe: Annika wirft beim Faschingumzug ihrer Bongbongs \n vom Umzugswagen. der restlichen Bonbongs \n behaelt Annika für ihre Geburtstagsparty. Die letzten Bongbongs darf \n ihr kleiner Bruder Max werfen. \n Wie viele Bongbongs hatte sie am Anfang?") FE=Entry(Fenster, bg='blue', width=6) SE=Entry(Fenster, width=4, bg='blue', textvariable = v) TE=Entry(Fenster, width=2, bg='blue') SL=Label(Fenster, text="* Anteil eingeben, Schreibweise als Kommazahl: a.b bsp: 1/5 (ein fuenftel)") OkB=Button(Fenster, command=OkBpress, text="Ok") #Widgets placen SEB.place(x=300, y=300, width=60, height=60) ################## Mathematischer Teil ################## def mathematics(FEOutput, SEOutput, TEOutput): anfang=100 t=anfang # int-en SEOutputL=SEOutput.split("/") FEOutputL=FEOutput.split("/") SEOutputL[0]=int(SEOutputL[0]) SEOutputL[1]=int(SEOutputL[1]) FEOutputL[0]=int(FEOutputL[0]) FEOutputL[1]=int(FEOutputL[1]) TEOutput=int(TEOutput) print("t:",t) liste=[[0,0,0,0," "]] # Startwerte anfang=100 # Anfang, als erstes auf 100 ermWL=[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,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100] t=0 # The amount that comes out of the invoice erreicht=False while erreicht==False: t=anfang t=t/FEOutputL[0] # Taking fractions t=t*FEOutputL[1] t=t/SEOutputL[0] t=t*SEOutputL[1] # Check if t is too big, too small, or correct if t == TEOutput: command= "richtig!" erreicht=True elif t > TEOutput: command= "Zu Gross!" # Everything in the list that is => t has to go while anfang not in ermWL: a=ermWL[-1] print(f"a:{a}") ermWL.append(a+1) for z in ermWL: if z >= anfang : ermWL.remove(z) elif t < TEOutput: command= "Zu Klein" for i in ermW: if i
Источник: https://stackoverflow.com/questions/780 ... -math-task