我有一个平均降雨量的代码,我一直试图通过用户输入每月的降雨来计算出来。但是我一直收到这个错误代码:
const CourseSchema = new Schema({
_id: { type: String },
});
CourseSchema.virtual('sections', {
type: Schema.Types.String,
ref: 'Section',
localField: 'sectionIds',
foreignField: '_id',
justOne: false,
});
CourseSchema.statics.findSections = function(id) {
return this.findById(id)
.populate('sections')
.then(course => course.sections);
}
const SectionSchema = new Schema({
_id: { type: String },
});
SectionSchema.virtual('course', {
type: Schema.Types.String,
ref: 'Course',
localField: 'courseId',
foreignField: '_id',
justOne: true,
});
谁能告诉我它有什么问题?
File "/Users/brittneybutcher/Desktop/UM-Flint/Average Rainfall.py", line 17, in <module>
"Average rainfall: " + format( averagerainfall, ".2f" ) )
TypeError: bad operand type for unary +: 'str' "
答案 0 :(得分:0)
在倒数第二行,您同时拥有+
和,
。最终的印刷声明应为:
print( "Number of Months: " + format( totalnumberofmonths, "d"), "Total inches of rainfall: " \
+ format( totalinchesofrainfall, ".2f" ), \
"Average rainfall: " + format( averagerainfall, ".2f" ) )
答案 1 :(得分:0)
看起来你有额外的&#39; +&#39;在print语句的倒数第二行。我建议打破各个组件的格式,使其更具可读性。
以下内容应该有效:
monthStr = format( totalnumberofmonths, "d")
inchStr = format(totalinchesofrainfall, ".2f")
avgStr = format( averagerainfall, ".2f" )
print("Number of months: {0}\tTotal inches: {1}\tAverage rainfall: {2}".format(monthStr, inchStr, avgStr))