| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1002 人关注过本帖
标题:求助】判断语句无效,加了flag也还是不行。
只看楼主 加入收藏
Uuuuna
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2020-12-7
结帖率:0
收藏
已结贴  问题点数:20 回复次数:2 
求助】判断语句无效,加了flag也还是不行。
代码如下:
def solve(sudoku):
    flag = 0
    list_a = reduce_vr(sudoku)
    list_temp = []
    for i in range(9):
        for j in range(9):
            if len(list_a[i][j]) != 1:
                flag = 1
            else:
                break
    if flag == 1:
        list_temp = trial(sudoku)
        print("1")
    else:
        list_temp = list_a
        print("2")

        return list_temp

run结果如下:
please input your sudoku question:000502000016000080000000000070030010060000000500009000030080000000000200700000509
2
[[8], [9], [4, 7], [5], [1, 4, 6, 7], [2], [1, 3, 4, 6, 7], [3, 4, 6, 7], [1, 4, 7]]
[[2], [1], [6], [3, 4, 7], [9], [3, 4, 7], [3, 4, 7], [8], [5]]
[[3], [5], [4, 7], [1, 4, 6, 7], [1, 4, 6, 7], [8], [1, 4, 6, 7], [9], [2]]
[[4], [7], [2], [8], [3], [5], [9], [1], [6]]
[[1], [6], [9], [4, 7], [2], [4, 7], [8], [5], [3]]
[[5], [8], [3], [1, 4, 6, 7], [1, 4, 6, 7], [9], [4, 7], [2], [4, 7]]
[[9], [3], [5], [2], [8], [1, 4, 6, 7], [1, 4, 6, 7], [4, 6, 7], [1, 4, 7]]
[[6], [4], [1], [9], [5], [3, 7], [2], [3, 7], [8]]
[[7], [2], [8], [1, 3, 4, 6], [1, 4, 6], [1, 3, 4, 6], [5], [3, 4, 6], [9]]

Process finished with exit code 0
搜索更多相关主题的帖子: 无效 flag 语句 sudoku 判断 
2020-12-07 15:38
Uuuuna
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2020-12-7
收藏
得分:0 
我解决了
2020-12-07 17:00
fall_bernana
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:贵宾
威 望:17
帖 子:244
专家分:2106
注 册:2019-8-16
收藏
得分:20 
以下是引用Uuuuna在2020-12-7 15:38:46的发言:

代码如下:
def solve(sudoku):
    flag = 0
    list_a = reduce_vr(sudoku)
    list_temp = []
    for i in range(9):
        for j in range(9):
            if len(list_a[j]) != 1:
                flag = 1
            else:
                break
    if flag == 1:
        list_temp = trial(sudoku)
        print("1")
    else:
        list_temp = list_a
        print("2")

        return list_temp

run结果如下:
please input your sudoku question:000502000016000080000000000070030010060000000500009000030080000000000200700000509
2
[[8], [9], [4, 7], [5], [1, 4, 6, 7], [2], [1, 3, 4, 6, 7], [3, 4, 6, 7], [1, 4, 7]]
[[2], [1], [6], [3, 4, 7], [9], [3, 4, 7], [3, 4, 7], [8], [5]]
[[3], [5], [4, 7], [1, 4, 6, 7], [1, 4, 6, 7], [8], [1, 4, 6, 7], [9], [2]]
[[4], [7], [2], [8], [3], [5], [9], [1], [6]]
[[1], [6], [9], [4, 7], [2], [4, 7], [8], [5], [3]]
[[5], [8], [3], [1, 4, 6, 7], [1, 4, 6, 7], [9], [4, 7], [2], [4, 7]]
[[9], [3], [5], [2], [8], [1, 4, 6, 7], [1, 4, 6, 7], [4, 6, 7], [1, 4, 7]]
[[6], [4], [1], [9], [5], [3, 7], [2], [3, 7], [8]]
[[7], [2], [8], [1, 3, 4, 6], [1, 4, 6], [1, 3, 4, 6], [5], [3, 4, 6], [9]]

Process finished with exit code 0

if len(list_a[j]) != 1:
                flag = 1
            else:
                break

没错呀,你每个i只判断j的第一个: 如果len()!=1你就break跳出j 的循环了呀。看你的这个数据,第一个的len都是1.所以flag不会等于1
2020-12-07 17:03
快速回复:求助】判断语句无效,加了flag也还是不行。
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017598 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved