首页 > 学习资料 > 编程知识

用python编程解决下列问题? 2022-07-10 22:31:35

矿石和身份:有A、B、C三名地质勘探队员对一块矿石进行判断,每人判断两次: A两次的判断为:它不是铁矿石,不是铜矿石。 B两次的判断为:它不是铁矿石,是锡矿石。 C两次的判断为:它不是锡矿石,是铁矿石。在这三名队员中,有工程师、技术员和实习生各一名,并且: 工程师的两次判断都正确; 技术员的两次判断中,只有一次是正确的; 实习生的两次判断都不正确。请裁定该矿石是什么矿以及这三人的身份各是什么?

  其实不编程也能很快推理出来,编代码反而有点复杂了。

  代码如下:

option = { 1: "Fe", 2: "Cu", 3: "Sn", 4: "other" } rank = { 2: "工程师", 1: "技术员", 0: "实习生" } def A1(answer): return ( (option[answer] == "Cu" or option[answer] == "Sn" or option[answer] == "other") ) def A2(answer): return( (option[answer] == "Fe" or option[answer] == "Sn" or option[answer] == "other" ) ) def B1(answer): return ( (option[answer] == "Cu" or option[answer] == "Sn" or option[answer] == "other") ) def B2(answer): return (option[answer] == "Sn") def C1(answer): return ( (option[answer] == "Fe" or option[answer] == "Cu" or option[answer] == "other") ) def C2(answer): return (option[answer] == "Fe") def get_result(): for answer in range(1, 5): A_score = A1(answer) + A2(answer) B_score = B1(answer) + B2(answer) C_score = C1(answer) + C2(answer) if ( (A_score == 2 and B_score == 1 and C_score == 0) or (A_score == 2 and B_score == 0 and C_score == 1) or (A_score == 1 and B_score == 2 and C_score == 0) or (A_score == 1 and B_score == 0 and C_score == 2) or (A_score == 0 and B_score == 1 and C_score == 2) or (A_score == 0 and B_score == 2 and C_score == 1) ): print("矿石为: {}".for ** t(option[answer])) print("A is {}".for ** t(rank[A_score])) print("B is {}".for ** t(rank[B_score])) print("C is {}".for ** t(rank[C_score])) get_result()

  结果截图:

相关标签:

<