TypeError:不支持的操作数类型 - :'int'和'str'
问题描述:
好的,所以我正在编写一个程序来查找星期几,程序可以顺利运行,直到这个区块
Ok so i am writing a program to find the day of the week and the program works smoothly until this block
D = input()
A = ( (14 - 'month') /12)
Y = ( 'Year' - 'A' )
MonthProblem = ( 'month' + 12 * 'A' - 2 )
week = ( ('D' + 'Y' + 'Y'/4 - 'Y'/100 + 'Y'/400 + 31 * 'MonthProblem'/12) % 7 )
错误是TypeError:不支持的操作数类型 - :'int'和'str'
the error is TypeError: unsupported operand type(s) for -: 'int' and 'str'
答
当你把倒置的逗号放在圆形的东西上时它变成一个字符串,所以'month'
表示单词this,而 month
表示变量中的值为month 。
When you put inverted commas round something it makes it into a string, so 'month'
means the word this, whereas month
means the value in the variable called month.
如果您删除'
s,您的程序将停止向您提供该特定错误:
Your program will stop giving you that particular error if you remove the '
s:
D = input()
A = ( (14 - month) /12)
Y = ( Year - A )
MonthProblem = ( month + 12 * A - 2 )
week = ( (D + Y + Y/4 - Y/100 + Y/400 + 31 * MonthProblem/12) % 7 )
您之前是否定义了月
等的值?
Had you defined the values of month
etc before?