Recently I am doing the assignment of COMP9021. It is too difficult and it is about the Knight and Knave. While I tried to finish this assignment, however I only finnished the code with the testcase Professor Martin gave. I encontered a problem was that if there is only one element in a tuple, actually we need to add a comma.

Examples as follows can help us to understand it.

a = ((2, 3),)
b = ((2, 3))
c = (2,)
d = (2) print(a, b, c, d)
print(len(a), len(b), len(c)) outputs:
((2, 3),) (2, 3) (2,) 2
1 2 1

Actually, variable a is a tuple with only one element which is (2, 3).

Variable b is a tuple with two elements which is 2 and 3.

So if you want to create a tuple with only one element, you need to add a comma otherwise you will create a different tuple.

【377】only one element in a tuple的更多相关文章

  1. 【原创】leetCodeOj --- Majority Element 解题报告(脍炙人口的找n个元素数组中最少重复n/2次的元素)

    题目地址: https://oj.leetcode.com/problems/majority-element/ 题目内容: Given an array of size n, find the ma ...

  2. 【JAVA】【Eclipse】出现This element neither has attached source nor attached Javadoc...的解决方法

    This element neither has attached source nor attached Javadoc and hence no Javadoc could be found Ec ...

  3. 【leetcode】Find Peak Element

    Find Peak Element A peak element is an element that is greater than its neighbors. Given an input ar ...

  4. 【leetcode】Kth Largest Element in an Array (middle)☆

    Find the kth largest element in an unsorted array. Note that it is the kth largest element in the so ...

  5. 【LeetCode】169 - Majority Element

    Given an array of size n, find the majority element. The majority element is the element that appear ...

  6. 【LeetCode】27 - Remove Element

    Given an array and a value, remove all instances of that value in place and return the new length. T ...

  7. 【leetcode】Find Peak Element ☆

    A peak element is an element that is greater than its neighbors. Given an input array where num[i] ≠ ...

  8. 【vue】使用vue+element搭建项目,Tree树形控件使用

    1.依赖安装 本例中,使用render-content进行树节点内容的自定义,因此需要支持JSX语法.(见参考资料第3个) 在Git bash中运行一下指令 cnpm install\ babel-p ...

  9. 【vue】vue使用Element组件时v-for循环里的表单项验证方法

    转载至:https://www.jb51.net/article/142750.htm标题描述看起来有些复杂,有vue,Element,又有表单验证,还有v-for循环?是不是有点乱?不过我相信开发中 ...

随机推荐

  1. [UE4]寻找敌人

  2. [UE4]Delay的使用技巧:改变引擎执行顺序

    如果要游戏一开始就让机器人开火,但这是引擎还没有执行到武器的创建步骤,就可以使用“Delay”并设置函数的等待时间,让引擎先执行创建枪的步骤,然后机器人开火就没问题了.

  3. nginx 1.14.0 配置部署 thinkphp 5.1

    开始接触NGINX,配置tp5配了半天,找不到具体原因,于是用网上搜索到的配置复制粘贴搞定. 感谢 https://blog.csdn.net/qq_36431213/article/details/ ...

  4. Android Studio启动后出现cannot bind to 127.0.0.1:5037 10048的解决办法

    第一次:先连接测试手机,然后启动Android studio时出现下面的弹框,网上查找资料说是360手机助手导致的,但是发现没有安装360手机助手只有360,卸载360后再启动Android stud ...

  5. 关于Element UI中页面样式小问题

    一,修改组件dialog窗口的大小 二,在我使用upload组件上传一张美女图片时,发现当预览图片时,图片是灰色的,点击一下才会变亮,这种效果使我很不舒服,于是我通过添加下面的一条样式,问题解决了(可 ...

  6. PostgreSQL 一主多从(多副本,强同步)简明手册 - 配置、压测、监控、切换、防脑裂、修复、0丢失 - 珍藏级

    参考来源: https://github.com/digoal/blog/blob/master/201803/20180326_01.md#postgresql-一主多从多副本强同步简明手册---配 ...

  7. hbase 核心知识

    Hbase 负载均衡 Hbase全局计划 Hbase全局计划执行的流程--估算 Hbase随机分配计划 Hbase 批量启动分配计划 Hbase 通过shell控制负载均衡 何时使用HBase

  8. mysql千万级数据库插入速度和读取速度的调整记录

    一般情况下mysql上百万数据读取和插入更新是没什么问题了,但到了上千万级就会出现很慢,下面我们来看mysql千万级数据库插入速度和读取速度的调整记录吧. 1)提高数据库插入性能中心思想:尽量将数据一 ...

  9. 写了一个bug----使用已经被删除的内存

    #include <iostream> #include <stdio.h> #include <memory.h> using namespace std; ; ...

  10. PHP获取中文首字母的函数

    PHP获取中文首字母的函数 <?php header("Content-type: text/html; charset=utf-8"); function getFirst ...