TypeError:不支持的操作数类型 - :'int'和'str' [英] TypeError: unsupported operand type(s) for -: 'int' and 'str'

查看:604
本文介绍了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?

这篇关于TypeError:不支持的操作数类型 - :'int'和'str'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆