授業を欠席した場合の費用を計算するプログラムを作成しようとしています。私は変数授業料、コース数、学期の週数を取り入れています。次に、結果をプロットします (python 2.7 を使用)。これが私が取り組んできたコードです:
import matplotlib.pyplot as plot
def calculations(t, c, w, wk):
two_week = (((t/c)/w)/2)*wk
three_week = (((t/c)/w)/3)*wk
return two_week, three_week
def main():
tuition = float(raw_input('Tuition cost (not including fees): '))
courses = int(raw_input('Number of courses: '))
weeks = int(raw_input('Number of weeks in the semester: '))
x_axis = range(0,10)
y_axis = []
y_axis2 = []
for week in x_axis:
cost_two, cost_three = calculations(tuition, courses, weeks, week)
y_axis += [cost_two]
y_axis2 += [cost_three]
plot.plot(x_axis, y_axis ,marker='o', label='course meets 2x a week', color='b')
plot.plot(x_axis, y_axis2,marker='o', label='course meets 3x a week', color='g')
plot.xlabel('number of missed classes')
plot.ylabel('cost ($)')
plot.title('Tuition: %.2f Courses: %d Weeks in a semester: %d\n Created by <MyName>') %(tuition, courses, weeks)
plot.legend()
plot.xticks(x_axis)
plot.xlim(0,x_axis[-1]+1)
plot.yticks(y_axis)
plot.ylim(0, y_axis[0]+1)
plot.grid()
plot.show()
plot.savefig('missing-class-cost.pdf')
main()
ただし、プログラムを実行するたびに、次のエラーが表示されます。
Traceback (most recent call last):
File "C:\Program Files (x86)\Wing IDE 101 4.1\src\debug\tserver\_sandbox.py", line 36, in <module>
File "C:\Program Files (x86)\Wing IDE 101 4.1\src\debug\tserver\_sandbox.py", line 26, in main
TypeError: unsupported operand type(s) for %: 'Text' and 'tuple'
26 行目は、次のコード行を参照しています。
plot.title('Tuition: %.2f Courses: %d Weeks in a semester: %d\n Created by <MyName>') %(tuition, courses, weeks)
数学のせいだと思いますが、プログラム全体でタプルを使用していないので、ちょっと途方に暮れています。
どんな助けでも大歓迎です、ありがとう。