Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 数字猜测游戏的编码问题_Python_Loops_While Loop - Fatal编程技术网

Python 数字猜测游戏的编码问题

Python 数字猜测游戏的编码问题,python,loops,while-loop,Python,Loops,While Loop,请有人能帮我找出我们这里出了什么问题。。。第一次猜测之后,它就停止了 游戏规则在print()文本中-谢谢 随机导入 num=random.randint(1100) 打印(“欢迎猜我!”) 打印(“我想的是一个介于1和100之间的数字”) 打印(“如果你的猜测与我的数字相差超过10,我会告诉你你很冷”) 打印(“如果你的猜测在我的数字的10以内,我会告诉你你很热情”) 打印(“如果你的猜测比你最近的猜测更远,我会说你越来越冷了”) 打印(“如果你的猜测比你最近的猜测更接近,我会说你正在变暖”

请有人能帮我找出我们这里出了什么问题。。。第一次猜测之后,它就停止了

游戏规则在print()文本中-谢谢


随机导入
num=random.randint(1100)
打印(“欢迎猜我!”)
打印(“我想的是一个介于1和100之间的数字”)
打印(“如果你的猜测与我的数字相差超过10,我会告诉你你很冷”)
打印(“如果你的猜测在我的数字的10以内,我会告诉你你很热情”)
打印(“如果你的猜测比你最近的猜测更远,我会说你越来越冷了”)
打印(“如果你的猜测比你最近的猜测更接近,我会说你正在变暖”)
打印(“让我们玩吧!”)
xs=[0]
尽管如此:
x=int(输入(“我想的是一个介于1和100之间的数字。\n你猜怎么着?”)
如果x<1或x>100:
打印('超出范围!请重试:')
持续
如果x==num:
打印(f'祝贺你,你只在{len(xs)}猜测中猜到了!!')
打破
追加(x)
如果xs[-2]:
如果abs(num-x)如果abs(num-x)输入错误很小,则代码工作正常:


import random
num = random.randint(1,100)

print("WELCOME TO GUESS ME!")
print("I'm thinking of a number between 1 and 100")
print("If your guess is more than 10 away from my number, I'll tell you you're COLD")
print("If your guess is within 10 of my number, I'll tell you you're WARM")
print("If your guess is farther than your most recent guess, I'll say you're getting COLDER")
print("If your guess is closer than your most recent guess, I'll say you're getting WARMER")
print("LET'S PLAY!")

xs = [0]

while True:
    x = int(input("I'm thinking of a number between 1 and 100.\n  What is your guess? "))

    if x < 1 or x > 100:
        print('OUT OF BOUNDS! Please try again: ')
        continue

    if x == num:
        print(f'CONGRATULATIONS, YOU GUESSED IT IN ONLY {len(xs)} GUESSES!!')
        break
        
    xs.append(x)

    if xs[-2]:  
        if abs(num-x) < abs(num-xs[-2]):
            print('WARMER!')
        else:
            print('COLDER!')

    else:
        if abs(num-x) <= 10:
            print('WARM!')
        else:
            print('COLD!')



随机输入
num=random.randint(1100)
打印(“欢迎猜我!”)
打印(“我想的是一个介于1和100之间的数字”)
打印(“如果你的猜测与我的数字相差超过10,我会告诉你你很冷”)
打印(“如果你的猜测在我的数字的10以内,我会告诉你你很热情”)
打印(“如果你的猜测比你最近的猜测更远,我会说你越来越冷了”)
打印(“如果你的猜测比你最近的猜测更接近,我会说你正在变暖”)
打印(“让我们玩吧!”)
xs=[0]
尽管如此:
x=int(输入(“我想的是一个介于1和100之间的数字。\n你猜怎么着?”)
如果x<1或x>100:
打印('超出范围!请重试:')
持续
如果x==num:
打印(f'祝贺你,你只在{len(xs)}猜测中猜到了!!')
打破
追加(x)
如果xs[-2]:
如果abs(num-x)abs(num-x[-2])
应该是
abs(num-xs[-2])

import random
num = random.randint(1,100)

print("WELCOME TO GUESS ME!")
print("I'm thinking of a number between 1 and 100")
print("If your guess is more than 10 away from my number, I'll tell you you're COLD")
print("If your guess is within 10 of my number, I'll tell you you're WARM")
print("If your guess is farther than your most recent guess, I'll say you're getting COLDER")
print("If your guess is closer than your most recent guess, I'll say you're getting WARMER")
print("LET'S PLAY!")

xs = [0]

while True:
    x = int(input("I'm thinking of a number between 1 and 100.\n  What is your guess? "))

    if x < 1 or x > 100:
        print('OUT OF BOUNDS! Please try again: ')
        continue

    if x == num:
        print(f'CONGRATULATIONS, YOU GUESSED IT IN ONLY {len(xs)} GUESSES!!')
        break
        
    xs.append(x)

    if xs[-2]:  
        if abs(num-x) < abs(num-xs[-2]):
            print('WARMER!')
        else:
            print('COLDER!')

    else:
        if abs(num-x) <= 10:
            print('WARM!')
        else:
            print('COLD!')