app.use(function(req, res, next) {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,PATCH,OPTIONS');
res.header('Access-Control-Allow-Headers', 'Content-Type, Authorization, Content-Length, X-Requested-With');
// allow preflight
if (req.method === 'OPTIONS') {
res.send(200);
} else {
next();
}
});
当我执行此代码并输入" 10"我在shell中得到了内置函数chr。我希望它根据分数打印A或其他角色。例如,如果输入分数是8或9,则必须阅读B.但是,我试图先通过第一步。我是编程的新手,如果我能指出正确的方向,那将会有很大的帮助。
答案 0 :(得分:0)
# declare score as integer
score = int
# declare rating as character
rating = chr
在两个语句之上,指定函数int
,chr
,而不是使用默认值声明变量。 (顺便说一下,chr
不是一个类型,而是一个将代码点值转换为字符的函数)
请改为:
score = 0 # or int()
rating = '' # or 'C' # if you want C to be default rating
注意 score
无需初始化,因为它是由score = input("Enter score: ")
答案 1 :(得分:0)
在python中,您不能进行静态类型化(即,您不能将变量固定为类型)。 Python是动态类型。
您需要的是将类型强制为输入变量。
# declare score as integer
score = '0' # the default score
# declare rating as character
rating = 'D' # default rating
# write "Enter score: "
# input score
score = input("Enter score: ")
# here, we are going to force convert score to integer
try:
score = int (score)
except:
print ('score is not convertable to integer')
# if score == 10 Then
# set rating = "A"
# endif
if score == 10:
rating = "A"
print(rating)