如果以前已经使用过代码,如何设置不重复的内容?

时间:2019-05-16 19:07:45

标签: python python-2.7 turtle-graphics

我试图制作一个子手程序。我还用乌龟制作了子手绘图。有时绘图会更改,并重复很多次。这个词是python。在以下情况下会发生此问题:

  1. 您不会猜到第一个字母
  2. 您猜到第二个字母
  3. 您无法猜测第二次尝试

基线变长。我希望代码first()在第一个字母完成后再也不会重复。

对不起,我的英语不好,很难形容。我认为您尝试该问题后就会理解。

此代码使用Python 2.7,但不使用3。

在使用代码后,我尝试添加“ x”并执行x = x + 1。我也用了while命令。

"""This code will continue on working unless you find the selected word, you only got 10 chances to win """
#From this section on there is the traditional hangman picture
#The word is PHYTON
from turtle import * 
penup()
setposition(-150,-120)
pendown()


def first():
  forward(200)

def second():
  backward(100)
  left(90)
  forward(300)

def third():
  right(90)
  forward(100)

def fourth():
  right(90)
  forward(50)

def fifth():
  penup()
  forward(60)
  left(90)
  pendown()
  circle(30)
  right(90)
  forward(100)

def sixth():
  backward(80)
  left(35)
  forward(75)

def seventh():
  backward(75)
  right(70)
  forward(75)

def eight():
  backward(75)
  left(35)
  forward(80)
  left(25)
  forward(75)

def ninth():
  backward(75)
  right(50)
  forward(75)

"""
first()
second()
third()
fourth()
fifth()
sixth()
seventh()
eight()
ninth()
"""
#From this part the algorithm for the system is starting

def first_letter():
    letter_1=input("Enter the first letter: \n")
    if (letter_1=="p"):
        print "Right letter!"
    else:
        print "Wrong letter!"
        first()
        letter_1=input("Enter the first letter: \n")
    if (letter_1=="p"):
        print "Right letter!"
    else:
        print "Wrong letter!"
        second()
        letter_1=input("Enter the first letter: \n")
    if (letter_1=="p"):
        print "Right letter!"
    else:
        print "Wrong letter!"
        third()
        letter_1=input("Enter the first letter: \n")
    if (letter_1=="p"):
        print "Right letter!"
    else:
        print "Wrong letter!"
        fourth()
        letter_1=input("Enter the first letter: \n")
    if (letter_1=="p"):
        print "Right letter!"
    else:
        print "Wrong letter!"
        fifth()
        letter_1=input("Enter the first letter: \n")
    if (letter_1=="p"):
        print "Right letter!"
    else:
        print "Wrong letter!"
        sixth()
        letter_1=input("Enter the first letter: \n")
    if (letter_1=="p"):
        print "Right letter!"
    else:
        print "Wrong letter!"
        seventh()
        letter_1=input("Enter the first letter: \n")
    if (letter_1=="p"):
        print "Right letter!"
    else:
        print "Wrong letter!"
        eight()
        letter_1=input("Enter the first letter: \n")
    if (letter_1=="p"):
        print "Right letter!"
    else:
        print "Wrong letter!"
        ninth()
def second_letter():
    letter_2=input("Enter the second letter: \n")
    if (letter_2=="y"):
        print "Right letter!"
    else:
        print "Wrong letter!"
        first()
        letter_2=input("Enter the second letter: \n")
    if (letter_2=="y"):
        print "Right letter!"
    else:
        print "Wrong letter!"
        second()
        letter_2=input("Enter the second letter: \n")
    if (letter_2=="y"):
        print "Right letter!"
    else:
        print "Wrong letter!"
        third()
        letter_2=input("Enter the second letter: \n")
    if (letter_2=="y"):
        print "Right letter!"
    else:
        print "Wrong letter!"
        fourth()
        letter_2=input("Enter the second letter: \n")
    if (letter_2=="y"):
        print "Right letter!"
    else:
        print "Wrong letter!"
        fifth()
        letter_2=input("Enter the second letter: \n")
    if (letter_2=="y"):
        print "Right letter!"
    else:
        print "Wrong letter!"
        sixth()
        letter_2=input("Enter the second letter: \n")
    if (letter_2=="y"):
        print "Right letter!"
    else:
        print "Wrong letter!"
        seventh()
        letter_2=input("Enter the second letter: \n")
    if (letter_2=="y"):
        print "Right letter!"
    else:
        print "Wrong letter!"
        eight()
        letter_2=input("Enter the second letter: \n")
    if (letter_2=="y"):
        print "Right letter!"
    else:
        print "Wrong letter!"
        ninth()    
def third_letter():
    letter_3=input("Enter the third letter: \n")
    if (letter_3=="t"):
        print "Right letter!"
    else:
        print "Wrong letter!"
        first()
      letter_3=input("Enter the third letter: \n")
    if (letter_3=="t"):
        print "Right letter!"
    else:
        print "Wrong letter!"
        second()
        letter_3=input("Enter the third letter: \n")
    if (letter_3=="t"):
        print "Right letter!"
    else:
        print "Wrong letter!"
        third()
        letter_3=input("Enter the third letter: \n")
    if (letter_3=="t"):
        print "Right letter!"
    else:
        print "Wrong letter!"
        fourth()
        letter_3=input("Enter the third letter: \n")
    if (letter_3=="t"):
        print "Right letter!"
    else:
        print "Wrong letter!"
        fifth()
        letter_3=input("Enter the third letter: \n")
    if (letter_3=="t"):
        print "Right letter!"
    else:
        print "Wrong letter!"
        sixth()
        letter_3=input("Enter the third letter: \n")
    if (letter_3=="t"):
        print "Right letter!"
    else:
        print "Wrong letter!"
        seventh()
        letter_3=input("Enter the third letter: \n")
    if (letter_3=="t"):
        print "Right letter!"
    else:
        print "Wrong letter!"
        eight()
        letter_3=input("Enter the third letter: \n")
    if (letter_3=="t"):
        print "Right letter!"
    else:
        print "Wrong letter!"
        ninth()




first_letter()
second_letter()
third_letter()

我希望乌龟以前使用它时不要再次使用first()函数。

0 个答案:

没有答案