我刚刚开始学习python,并且在执行最新项目时遇到无法修复的语法错误。
def adding_report():
report_value = input('Input an integer to add to the total or "Q" to quit: ')
while True:
if report_value == "":
report_value = input('Input an integer to add to the total or "Q" to quit: ')
elif report_value.isdigit():
final_value = int(report_value) + int(report_value)
elif report_value.lower() == "q"
break
adding_report()
我希望此函数可以运行,并要求我向报告中添加一个整数,直到我输入可以中断循环的“ Q”为止,然后会出现一个显示报告最终值的结果,但是有一种语法运行此代码时出错。
elif report_value.isdigit():
^
SyntaxError: invalid character in identifier
答案 0 :(得分:1)
您在行尾使用了https://ldap3.readthedocs.io/tutorial_operations.html#create-an-entry,而不是普通的冒号const arr = [
{jobid: "atA3Qi4BJu01VrUasiSX", id: "I1bncvyBsjbu7ePdPvYt", firstName: "Krishnakumar K R", Title: "design job", empname: "Rakesh"},
{jobid: "atA3Qi4BJu01VrUasiSX", id: "MDxEVS2hKftDrrPXsSWL", firstName: "test Candidate", Title: "design job", empname: "Rakesh"},
{jobid: "atA3Qi4BJu01VrUasiSX", id: "Mmu7oiAoCNcaU2ZWlLeS", firstName: "Rakesh", Title: "design job", empname: "Rakesh"},
{jobid: "atA3Qi4BJu01VrUasiSX", id: "m9SC2DbWxTrlTxJr12p0", firstName: "test user", Title: "design job", empname: "Rakesh"},
{jobid: "nCBNJ1yEn4EaGLR4BHDc", id: "1GMZpFhcOyDSt1KG4abK", firstName: "mohammed basheer", Title: "test job emp", empname: undefined},
{jobid: "nCBNJ1yEn4EaGLR4BHDc", id: "MDxEVS2hKftDrrPXsSWL", firstName: "test Candidate", Title: "test job emp", empname: undefined},
{jobid: "nCBNJ1yEn4EaGLR4BHDc", id: "Mmu7oiAoCNcaU2ZWlLeS", firstName: "Rakesh", Title: "test job emp", empname: undefined},
{jobid: "atA3Qi4BJu01VrUasiSX", id: "I1bncvyBsjbu7ePdPvYt", firstName: "Krishnakumar K R", Title: "design job", empname: "Rakesh"},
{jobid: "atA3Qi4BJu01VrUasiSX", id: "MDxEVS2hKftDrrPXsSWL", firstName: "test Candidate", Title: "design job", empname: "Rakesh"},
{jobid: "atA3Qi4BJu01VrUasiSX", id: "Mmu7oiAoCNcaU2ZWlLeS", firstName: "Rakesh", Title: "design job", empname: "Rakesh"},
{jobid: "atA3Qi4BJu01VrUasiSX", id: "m9SC2DbWxTrlTxJr12p0", firstName: "test user", Title: "design job", empname: "Rakesh"},
{jobid: "nCBNJ1yEn4EaGLR4BHDc", id: "1GMZpFhcOyDSt1KG4abK", firstName: "mohammed basheer", Title: "test job emp", empname: undefined},
{jobid: "nCBNJ1yEn4EaGLR4BHDc", id: "MDxEVS2hKftDrrPXsSWL", firstName: "test Candidate", Title: "test job emp", empname: undefined},
{jobid: "nCBNJ1yEn4EaGLR4BHDc", id: "Mmu7oiAoCNcaU2ZWlLeS", firstName: "Rakesh", Title: "test job emp", empname: undefined}
]
const tmp = new Map()
const rs = arr.reduce((acc, e) => {
if(tmp.has(e.id)) {
if (!tmp.get(e.id).includes(e.jobid)) {
acc.push(e)
tmp.set(e.id, [...tmp.get(e.id), e.jobid])
}
} else {
acc.push(e)
tmp.set(e.id, [e.jobid])
}
return acc
}, [])
console.log(rs)
。
只需删除它,然后将其替换为普通冒号(并且不要忘记在缺少冒号的地方添加一个):
:
答案 1 :(得分:0)
尝试以下代码:
def adding_report():
report_value = input(
'Input an integer to add to the total or "Q" to quit: ')
while True:
if report_value == "":
report_value = input(
'Input an integer to add to the total or "Q" to quit: ')
elif report_value.isdigit():
final_value = int(report_value) + int(report_value)
elif report_value.lower() == "q":
break
adding_report()
您在:
中使用了无效字符elif report_value.isdigit():
而不是:
(这是完全不同的字符,也许您使用了不同的键盘布局?),但是您忘了再输入{ {1}},后缀为