摂氏から華氏、華氏から摂氏に変換するプログラムの問題。
私が書いたプログラムは動作するのですが0%正答という結果が帰ってきます。
問題。(英文)
Write a GUI-based program that allows the user to convert temperature values between degrees Fahrenheit and degrees Celsius. The interface should have labeled entry fields for these two values.
1.These components should be arranged in a grid where the labels occupy the first row and the corresponding fields occupy the second row.
2.At start-up, the Fahrenheit field should contain 32.0, and the Celsius field should contain 0.0.
3.The third row in the window contains two command buttons, labeled >>>> and <<<<.
4.When the user presses the first button, the program should use the data in the Celsius field to compute the Fahrenheit value, which should then be output to the Fahrenheit field.
The second button should perform the inverse function.
完成形の見本
わたしが書いたコード
コード# importing the module breezypythongui from breezypythongui import EasyFrame class TemperatureConverter(EasyFrame): # setting up the window and widgets def __init__(self): EasyFrame.__init__(self, width="1000", title="Temperature Converter") # adding label "Celsius" self.addLabel(text="Celsius", row=0, column=0) # adding a float field for Celsius and storing the value in variable self.getInputCelsius = self.addFloatField(value=0.0, row=1, column=0) # adding label "Fahrenheit" self.addLabel(text="Fahrenheit", row=0, column=1) # adding a float field for Fahrenheit and storing the value in variable self.getInputFahrenheit = self.addFloatField(value=32.0, row=1, column=1) # adding buttons for conversion self.grp1 = self.addButton(text=">>>>", row=2, column=0, command=self.computeFahrenheit) self.grp2 = self.addButton(text="<<<<", row=2, column=1, command=self.computeCelsius) # function called on pressing ">>>>" button def computeFahrenheit(self): # getting the value from the float field "getInputCelsius" inputVal = self.getInputCelsius.getNumber() # calculating temperature in Fahrenheit op = 9.0/5.0 * inputVal + 32 # setting the temperature in "getInputFahrenheit" self.getInputFahrenheit.setValue(op) # function called on pressing "<<<<" button def computeCelsius(self): # getting the value from the float field "getInputFahrenheit" inputVal = self.getInputFahrenheit.getNumber() # calculating temperature in Celsius op = (inputVal - 32) * 5.0/9.0 # setting the temperature in "getInputCelsius" self.getInputCelsius.setValue(op) def main(): # this keeps the window from closing automatically TemperatureConverter().mainloop() if __name__ == "__main__": main()
よろしくお願いします。
回答1件
あなたの回答
tips
プレビュー