简体   繁体   English

为什么我的代码不起作用? “同时”不会停止

[英]Why my code doesn't work? "while" doesn't stop

Why it doesn't work?为什么它不起作用? It should be stopped.应该停止它。 My v == 3 .我的v == 3

while t < 3 , it should be stopped, while t < 3时,应该停止,

You see in the code that my t is worth to 4 ,您在代码中看到 my t4

Why my while doesn't stop?为什么我的while不停?

t = 4 < 3  == false

My code:我的代码:

import random

stages = ['''
  +---+
  |   |
  O   |
 /|\  |
 / \  |
      |
=========
''', '''
  +---+
  |   |
  O   |
 /|\  |
 /    |
      |
=========
''', '''
  +---+
  |   |
  O   |
 /|\  |
      |
      |
=========
''', '''
  +---+
  |   |
  O   |
 /|   |
      |
      |
=========''', '''
  +---+
  |   |
  O   |
  |   |
      |
      |
=========
''', '''
  +---+
  |   |
  O   |
      |
      |
      |
=========
''', '''
  +---+
  |   |
      |
      |
      |
      |
=========
''']

letters_number = 3

word_list = ["ardvark", "baboon", "camel"]

c = []
a = random.randint(0,(len(word_list) -1))
word_generator = word_list[a]
#print(word_generator)
d = 0
q = ""
z = 0
h = ''
t = 0
v = 3

for i in range(0,len(word_generator)):
    if i < len(word_generator):
      c += '_'

while  d  < len(word_generator) or int(t) < v:
  chose = input("Guess a letter\n")
  for i in range(0,len(word_generator)):

    if chose == word_generator[i]:
       c[i] = word_generator[i]
       d += 1
       #print("right")
    if c[i] == chose:
      z += 1000
    if c[i] != chose:
      z += -1
    if z < 0:
      h ="Wrong"
      z = 0
    else:
      h = "True"

  if h == "Wrong":
    t += 1

  print(c)
  print(z)
  print(h)
  h = ''
  z = 0
  print("t =",t)
if d == len(word_generator):
  print("you win")
if t == letters_number:
  print("you loose")

运行代码的输出截图

The while condition has two parts: while 条件有两个部分:

while  d  < len(word_generator) or int(t) < v

If the t < v part is false, the loop will still run if the d < len() part is true, because it is an or condition.如果t < v部分为假,如果d < len()部分为真,则循环仍将运行,因为它是一个or条件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM