現在、私は、グループでプレゼンテーションを行っていて、プレゼンテーションのコピーを印刷する必要がある場合に、何連の紙を購入する必要があるかを調べるプログラムを作成しています。プログラムを実行すると、次のように表示されます。
Traceback (most recent call last):
File "C:/Users/Shepard/Desktop/Assignment 5.py", line 11, in <module>
print ("Total Sheets: " & total_Sheets & " sheets")
TypeError: unsupported operand type(s) for &: 'str' and 'int'
>>>
私がやろうとしていることは次のとおりです。
print ("Total Sheets: " & total_Sheets & " sheets")
print ("Total Reams: " & total_Reams & " reams")
& 演算子を使用して文字列型と整数型を print と組み合わせるべきではありませんか? そうでない場合、私は何を間違っていますか?
これが私のプログラム全体です。
ream = 500
report_Input = int (input ("How many pages long is the report?"))
people_Input = int (input ("How many people do you need to print for? -Automatically prints five extras-"))
people = people_Input + 5
total_Sheets = report_Input * people
total_Reams =((total_Sheets % 500) - total_Sheets) / people
print ("Total Sheets: " & total_Sheets & " sheets")
print ("Total Reams: " & total_Reams & " reams")
編集:これを投稿した後、Jon Clements の回答が最良の回答であることがわかりました。また、それを機能させるには if ステートメントを挿入する必要があることもわかりました。助けてくれたすべてのおかげで、これが私の完成したコードです。
ream = 500
report_Input = int (input ("How many pages long is the report?"))
people_Input = int (input ("How many people do you need to print for? -Automatically prints five extras-"))
people = people_Input + 5
total_Sheets = report_Input * people
if total_Sheets % 500 > 0:
total_Reams =(((total_Sheets - abs(total_Sheets % 500))) / ream)+1
else:
total_reams = total_Sheets / ream
print ("Total Sheets:", total_Sheets, "sheets")
print ("Total Reams:", total_Reams, "reams")