我在解决代码时需要帮助。 下面的python代码'继续'工作不正常
dicemp = {'12345':''}
while(1):
choice = int(input("Please enter your choice\n"))
if (choice == 1):
empno = input("Enter employee number: ")
for i in dicemp.keys():
if i == empno:
print("employee already exists in the database")
continue
print("Hello")
输出:
请输入您的选择
1
输入员工编号:12345
员工已存在于数据库中
您好
所以对于上面的代码,如果我给同一个员工没有。 12345它将进入阻止并打印消息"员工已存在于数据库中"在此之后它应该从一开始就继续,但在这种情况下它也是打印"你好"。
答案 0 :(得分:2)
您的SELECT TOP 3
a1.year,
a1.quarter,
a1.team,
sum(a1.price) as Total
FROM
tbl_sales a1
WHERE
'some restrictions here'
AND a1.quarter = 1 --(or however quarters are identified)
AND a1.year = 2015 --(or however years are identified)
GROUP BY
a1.year,
a1.quarter,
a1.team
ORDER BY
sum(a1.price) DESC
UNION ALL
SELECT TOP 3
a2.year,
a2.quarter,
a2.team,
sum(a2.price) as Total
FROM
tbl_sales a2
WHERE
'some restrictions here'
AND a2.quarter = 2
AND a2.year = 2015
GROUP BY
a2.year,
a2.quarter,
a2.team
ORDER BY
sum(a2.price) DESC
UNION ALL
SELECT TOP 3
a3.year,
a3.quarter,
a3.team,
sum(a3.price) as Total
FROM
tbl_sales a3
WHERE
'some restrictions here'
AND a3.quarter = 3
AND a3.year = 2015
GROUP BY
a3.year,
a3.quarter,
a3.team
ORDER BY
sum(a3.price) DESC
UNION ALL
SELECT TOP 3
a1.year,
a1.quarter,
a1.team,
sum(a1.price) as Total
FROM
tbl_sales a4
WHERE
'some restrictions here'
AND a4.quarter = 4
AND a4.year = 2015
GROUP BY
a4.year,
a4.quarter,
a4.team
ORDER BY
sum(a4.price) DESC
正在将continue
循环移动到下一次迭代,无论如何都会发生这种情况。如果你需要继续外循环,你可以这样做:
for
现在while True:
choice = int(input("Please enter your choice\n"))
if choice == 1:
empno = input("Enter employee number: ")
found = False
for i in dicemp:
if i == empno:
print("employee already exists in the database")
found = True
break
if found:
continue
print("Hello")
超出continue
循环,因此它将继续外循环。
您可以将其简化为:
for
完全摆脱内循环。