代码编写记录
2024.05.04
05.36.01version
换一个什么数代替剪子
我先建立一个函数judgement condition
石头=3
剪子=2
布=1
如何构建一个循环进行的架构,是我们最需要的想法
循环以什么条件开始呢
是小于2个还是大于2个。
guess_num = random.randint(1, 3)
computer_num = random.randint(1, 3)c_win = 0
g_win = 0while (c_win <= 2 or g_win <= 2) and not (c_win == 2 and g_win == 2):if computer_num == 1 and guess_num == 3:print("computer is", computer_num, "is win")c_win += 1elif computer_num > guess_num:print("computer is", computer_num, "is win")c_win += 1if guess_num > computer_num:print("guess is", guess_num, "is win")g_win += 1elif guess_num == 3 and computer_num == 1:print("guess is", guess_num, "is win")g_win += 1elif guess_num == computer_num:print("Is draw this result")c_win += 0g_win += 0
2024.05.04
我已经成功的做到了一些。现在我该如何确定由谁来担任循环条件呢?
谁先到2次就停止整个循环。那么我错在哪里了?
while 和if 还是不一样。
我的想法是谁先到达2次,就停止循环
现在利用 or 来完成但是效果不理想,因此存在另一个就是相等的情况。
相等的情况让我们的循环在一直进行下去,不停的往下走。
我是不是忽律了什么
忽律了生活,忽律了家人。只注重目标。
我们的代码就是只注重目标的一种行为。
注重代码的目标。
注重结果
我们是从结果出发来设计我们的代码
我们的代码就是因。
通过我们的结果我们在反向的设计和推广我们的结果。
我发现来我代码设计的错误。
我把随机条件放到来循环的外面。
我应该把随机条件加到循环的里面下面的代码解决相等也能不停循环的问题。循环条件并不是问题。
可能和我将随机条件放在循环外有着很大的关系。
c_win = 0
g_win = 0while c_win < 2 or g_win < 2 :guess_num = random.randint(1, 3)computer_num = random.randint(1, 3)if computer_num == 1 and guess_num == 3:print("computer is", computer_num, "is win")c_win += 1elif computer_num > guess_num:print("computer is", computer_num, "is win")c_win += 1if guess_num > computer_num:print("guess is", guess_num, "is win")g_win += 1elif guess_num == 3 and computer_num == 1:print("guess is", guess_num, "is win")g_win += 1else:continue
我想到了,给我这道题设计一个公用的变量
不管是谁成功到达2次,就将谁赋值给公用变量
以公用变量为循环的开关。
代码成功了。下次继续改进
c_win = 0
g_win = 0
total = 0
while total != 2:guess_num = random.randint(1, 3)computer_num = random.randint(1, 3)if c_win == 2:total = c_winprint("User is the computer winner")elif g_win == 2:total = g_winprint("User is the game winner")if computer_num == 1 and guess_num == 3:# print("computer is", computer_num, "is win")c_win += 1elif computer_num > guess_num:# print("computer is", computer_num, "is win")c_win += 1if guess_num > computer_num:# print("guess is", guess_num, "is win")g_win += 1elif guess_num == 3 and computer_num == 1:# print("guess is", guess_num, "is win")g_win += 1else:continue