菜鸟基于python3.3的一个问题
本帖最后由 lilihao2010 于 2013-12-24 10:53:22 编辑 写程序:
month = ['January','February','March','April','May','June','July','August','September','October','November','December']
month_number =input("Input Month Number(1-12):")
day_number = input("Input Day Number(1-31):")
year_number = input("Input Year Number(0000-9999):")
month_name = month[month_number-1]
print(day_number+month_name+year_number);
会弹出如下错误:
Traceback (most recent call last):
File "/Users/lilihao/Documents/workspace/hello/hello.py", line 5, in <module>
month_name = month[month_number-1]
TypeError: unsupported operand type(s) for -: 'str' and 'int'
我明白是month_name转型的问题,它这里应该被转成String类型的。但是不知道怎么转,望有大哥帮忙解答
[解决办法]
month_number =int(input("Input Month Number(1-12):"))