質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

Q&A

解決済

1回答

2087閲覧

米大課題 摂氏=華氏 変換プログラム

needhelpman

総合スコア2

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

0グッド

1クリップ

投稿2020/10/30 11:42

編集2020/10/30 12:03

摂氏から華氏、華氏から摂氏に変換するプログラムの問題。
私が書いたプログラムは動作するのですが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()

よろしくお願いします。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

TakaiY

2020/10/30 12:31

環境作って動かしてみてもちゃんと動くし、問題どおりにできていると思うので、0点の理由はわかりません。 breezypythongui というライブラリが使われていますが、これが提出先の環境で使えないということではないですか?
needhelpman

2020/10/30 12:39

コメントありがとうございます。質問を直しましたのでチェックお願いします。
needhelpman

2020/10/30 13:04

助けてくださりありがとうございました。 すみません。gentaro is shit にすれば良かったです。日本人は素晴らしい人たちです。
gentaro

2020/10/30 13:08

あっそ。通報しとくわ。
needhelpman

2020/10/30 13:12

そのコメント、ライクです lol あなたは日本の中にいるchineseですね。ぶかんに帰ってヴァイルス撃退してください。
Zuishin

2020/10/30 13:17

それとももうおいだされたあとかな?
needhelpman

2020/10/30 13:17

やはり日本人はしんせつ。ありがとうございます。
needhelpman

2020/10/30 13:21

ZuishinはCのprofessinalですね。respectです。ぜひ、ジャマイカに来て欲しい。
Zuishin

2020/10/30 13:25

https://stackoverflow.com/ こっちにわたしなどくらべものにならないほどすごいひとがいるのでぜひいどうしてください。
needhelpman

2020/10/30 13:39 編集

宇宙飛行士の募集が来年の秋にあるので是非応募してみてください。 あの若田光一氏と野口聡一氏を凌ぐ才能があなたにはあります。 あと平仮名ばかりだととても読みにくいので漢字を覚えるといいですよ。 goodnight
Zuishin

2020/10/30 13:36

かんじだとあなたがよめないでしょう。
needhelpman

2020/10/30 13:40

ありがとうございます。このサイト使ってみます。
guest

回答1

0

ベストアンサー

私が書いたプログラムは動作するのですが0%正答という結果が帰ってきます。

華氏32°は摂氏0°なので、プログラムは正しく動いてるように見えます。
なにが問題なのでしょうか?

32° Fahrenheit is equal to 0° Celsius, so your code seem to be working correctly.
what's the problem?

追記

self.getInputCelsius となっている箇所を self.celsiusField
self.getInputFahrenheit となっている箇所を self.fahrField にすべて変更してください。

投稿2020/10/30 12:06

編集2020/10/30 12:43
tiitoi

総合スコア21956

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

needhelpman

2020/10/30 12:26

Thank you for your response! 下に書いたものが働いているかcheckerで調べられているようです The GUI Tests check that the program gracefully handles converting 30.0 Celsius correctly into Fahrenheit and 68.0 Fahrenheit into Celsius. Make sure your program gracefully converts Celsius to Fahrenheit and vice versa using the correct math. 受け取るエラー error1: Traceback (most recent call last): File "nt-test-3f909f34.py", line 5, in <module> tester.after(1000, tester.celsiusField.setNumber, 30.0) AttributeError: 'TemperatureConverter' object has no attribute 'celsiusField' error2: Traceback (most recent call last): File "nt-test-b688c68e.py", line 5, in <module> tester.after(1000, tester.fahrField.setNumber, 68.0) AttributeError: 'TemperatureConverter' object has no attribute 'fahrField'
TakaiY

2020/10/30 12:34

この情報は重要なので、質問にも加えてください。
tiitoi

2020/10/30 12:36 編集

日本人ですか?日本語が大丈夫なら日本語でやり取りしようと思うので。
tiitoi

2020/10/30 12:37

self.getInputCelsius, self.getInputFahrenheit についてですが、 これらの入力欄の変数名について、課題ではなにか指定はありませんでしたか? エラーを見る限り、self.getInputCelsius, self.getInputFahrenheit ではなく、self.celsiusField, self.fahrField という名前で定義されていることを前提としているように見えます。
TakaiY

2020/10/30 12:39

エラー情報を見ると、テスト用のプログラムがあって、「TemperatureConverter」オブジェクトが「celsiusField」や「fahrField」というattributeを持っていることを期待したテストプログラムでチェックしているようです。 そもそも、ソフトウェアの作りが問題に合っていないのではないでしょうか? ソフトウェアの要件が別にあるのではないでしょうか?
needhelpman

2020/10/30 12:39

助けがないと中学生レベルの日本語ですがよろしくお願いします。
needhelpman

2020/10/30 12:42

その通りでした。 課題の中にこのような文があったのでこれにしたがってcodeingしなければいけなかったみたいです。 # self.addLabel (Label for Celsius) # self.celsiusField (Celsius field) # self.addLabel (Label for Fahrenheit) # self.fahrField (Fahrenheit field) # self.addButton (Celsius button) # self.addButton (Fahrenheit button)
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問