用python创建一个高低游戏,需要很多帮助!

用python创建一个高低游戏,需要很多帮助!,python,Python,这是伪代码 向用户打印说明 从变量high=1000、low=1和TREATS=1开始 而高则大于低 猜猜高低的平均值 请用户对猜测作出回应 处理四种可能的结果: 如果猜测是正确的,则打印一条消息,尝试进行需要的猜测,然后退出程序 如果猜得太高,打印一条消息,上面写着“我会猜得更低。” 如果猜得太低,打印一条消息,上面写着“我会猜得更高。” 如果用户输入的值不正确,请再次打印说明 我甚至不知道从哪里开始。你不会说这是Python 2还是Python 3。以下内容适用于2的最新版本:;我对3不

这是伪代码

  • 向用户打印说明
  • 从变量high=1000、low=1和TREATS=1开始
  • 而高则大于低
  • 猜猜高低的平均值
  • 请用户对猜测作出回应
  • 处理四种可能的结果:
    • 如果猜测是正确的,则打印一条消息,尝试进行需要的猜测,然后退出程序
    • 如果猜得太高,打印一条消息,上面写着“我会猜得更低。”
    • 如果猜得太低,打印一条消息,上面写着“我会猜得更高。”
    • 如果用户输入的值不正确,请再次打印说明

  • 我甚至不知道从哪里开始。

    你不会说这是Python 2还是Python 3。以下内容适用于2的最新版本:;我对3不熟悉,但它可能至少也能让你从那里开始。既然这是家庭作业,我就推荐一些东西给你们研究

    • 你会想得到猜测,并在一个循环中检查它们。我建议查找循环
    • 要获取用户输入,请尝试
    • 要输出消息,请查找
    • 用于检查用户的响应

    从第一点开始:

    print "instructions to the user"
    
    (只需将字符串更改为更具信息性,这不是编程问题!-),然后继续第二点(三个作业,就像你的家庭作业所说的那样),然后是第三点:

    while high > low:
    

    这已经是你工作的一半了(6分中的1-3分)。除此之外,还有什么给你带来问题?你知道平均值是什么意思吗,所以(说)
    guess=(高+低)//2
    对你来说是可以理解的,还是什么?这就是第四点所需要的!你知道如何向用户提问并得到他们的回答吗?查找
    输入
    原始输入
    。。。好的,我已经讨论了六点中的前五点,当然你至少可以开始了

    好的,这不是答案,但你需要看看程序:

  • 打印出说明
  • 制作一个随机数或使用你自己的。(对于随机数,您需要使用模除技巧)
  • 可能使用while循环:检查猜测的数字是否较高、较低或相等
  • 如果打印量较高,则打印量较低,如果打印量相等,则中断或呼叫退出(可能中断即可)
  • 伪代码:

    print "intructions"
    thenumber = rand() % 1000+1
    while (true)
        getInput(guess);
        if (guess > thenumber)
            print "Guess lower"
        else if (guess < thenumber)
            print "Guess higher")
        else
            exit //or break.
    
    打印“指令”
    编号=兰德()%1000+1
    while(true)
    获取输入(猜测);
    如果(猜测>数字)
    打印“猜低”
    else if(猜测<数字)
    打印“猜测更高”)
    其他的
    退出//或中断。
    

    只是伪代码。

    这里是您的开始。将规范作为文档插入,然后一次做一个,一路测试

    # Print instructions to the user
    ### 'print "xyz"' will output the xyz text.
    
    # Start with the variables high = 1000, low = 1, and tries = 1
    ### You can set a variable with 'abc = 1'.
    
    # While high is greater than low
    ### Python has a while statement and you can use something like 'while x > 7:'.
    ### Conditions like 'x > 7', 'guess == number' can also be used in `ifs` below.
    
        # Guess the average of high and low
        ### The average of two numbers is (x + y) / 2.
    
        # Ask the user to respond to the guess
        ### Python (at least 2.7) has a 'raw_input' for this, NOT 'input'.
    
        # If the guess was right, print a message that tries guesses were required
        # and quit the program
        ### Look at the 'if' statement for this and all the ones below.
    
        # If the guess was too high, print a message that says “I will guess lower.”
        # If the guess was too low, print a message that says “I will guess higher.”
        # If the user entered an incorrect value, print out the instructions again.
    
    我还添加了一条小评论,详细说明了每个部分应该查找哪些语言元素。

    print(“***************Hi-Lo Game**********”)
    
    print ("*********** Hi Lo Game ***********")
    import random
    x = (random.randint(1,100))
    num1 = int(input("Enter your number:"))
    while num1 < x:
       print ("Too Low")
       num1 = int(input("Enter your number:"))
    while num1 > x:
       print ("Too High")
       num1 = int(input("Enter your number:"))
    if num1 == x:
       print ("Congratulations! You are Correct")
    
    随机输入 x=(random.randint(1100)) num1=int(输入(“输入您的号码:”) 当num1x时: 打印(“太高”) num1=int(输入(“输入您的号码:”) 如果num1==x: 打印(“祝贺你!你是对的”)
    良好工作高/低游戏w/分数
    来自随机导入randint
    导入时间
    打印“=”*20
    打印“向上/向下游戏”
    打印“向上或向下输入!”
    打印“连续获得10个奖励!”
    打印“=”*20
    打印“=”+“游戏开始”+“=”
    打印“=”*20
    打印“
    ans=“”
    分数=0
    尽管如此:
    n1=randint(2,13)
    n2=randint(2,13)
    打印“I have=%s”%(n1)
    ans=原始输入(“您选择什么:”)
    如果ans==‘向上’:
    打印“您的号码是:”
    睡眠时间(0.5)
    “打印”
    睡眠时间(0.5)
    打印“%s”%(n2)
    时间。睡眠(1)
    如果n1>n2:
    打印“对不起,你丢了。”
    时间。睡眠(2)
    打印“最终分数=%s”%(分数)
    时间。睡眠(2)
    打印“=”*20
    打印“重试”
    打印“=”*20
    分数=0
    elif n1 1:
    打印“这是%s的一行”%(分数)
    elif分数==1:
    打印“这是1分”
    elif分数==10:
    打印“恭喜你得到了奖励!!!”
    elif ans==“向下”:
    打印“您的号码是:”
    睡眠时间(0.5)
    “打印”
    睡眠时间(0.5)
    打印“%s”%(n2)
    时间。睡眠(1)
    如果n1=n2:
    分数+=1
    如果得分>1:
    打印“这是%s的一行”%(分数)
    elif分数==1:
    打印“这是1分”
    elif分数==10:
    打印“恭喜,你得到了奖励”
    其他:
    tryAgain=原始输入(“仅输入向上或向下”)
    
    我建议从头开始(并在结尾结束)。一次解决一个问题:制定一个能够解决问题的计划;然后,一旦它成功了,就把它扩展到做#2,依此类推。非常感谢:)这里的所有答案都有帮助。谢谢,它非常有用:)不起作用。您需要一个while循环,而不是两个顺序循环。如果用户猜得太高,然后又猜得太低,那么您的代码将在用户未完成游戏的情况下失败。您还没有按照OP的要求处理无效输入的情况。我建议您在代码中添加一些解释。代码没有映射到描述上的
    1:1
    ,因此如果您添加一些注释/方法,会更容易理解。哦,对不起。这是我的第一篇文章,也是我有史以来第一个有开始和结束的代码。我不知道该怎么解释。因为我所有的代码都是新手,我现在看到他想要更多的选项和平均值。。
    from random import randint
    import time
    print '='*20
    print 'The Up / Down Game'
    print 'Enter up or down !'
    print 'Get 10 in a row for a reward!'
    print '='*20
    print "=    "+'GAME START'+"    ="
    print '='*20
    print ''
    ans = ' '
    score = 0
    while True:
    
    n1 = randint(2,13)
    n2 = randint(2,13)
    print "I have = %s" % (n1)
    
    ans = raw_input("What do you choose: ")
    if ans == 'up':
        print "Your number is : "
        time.sleep(0.5)
        print "."
        time.sleep(0.5)
        print ". %s" % (n2)
        time.sleep(1)
        if n1 > n2:
            print "Sorry you lost."
            time.sleep(2)
            print "Final score = %s" % (score)
            time.sleep(2)
            print "="*20
            print "Try Again"
            print "="*20
            score = 0
        
        elif n1 <= n2:
            score += 1
            if score > 1:
                print "That's %s in a row" % (score)
            elif score == 1:
                print "Thats  1 point"
            elif score == 10:
                print "Congratz you got the reward!!!"
        
    elif ans == 'down':
        print "Your number is : "
        time.sleep(0.5)
        print "."
        time.sleep(0.5)
        print ". %s" % (n2)
        time.sleep(1)
        if n1 < n2:
            print "Sorry you lost."
            time.sleep(2)
            print "Final score = %s" % (score)
            time.sleep(2)
            print "="*20
            print "Try Again"
            print "="*20
            score = 0
        
        elif n1 >= n2:
            score += 1
            if score > 1:
                print "That's %s in a row" % (score)
            elif score == 1:
                print "Thats  1 point"
            elif score == 10:
                print "Congratz. You got the reward"
    
    
        else:
            tryAgain = raw_input("enter up or down only")