Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/284.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 in range()语句不起作用_Python_If Statement - Fatal编程技术网

Python in range()语句不起作用

Python in range()语句不起作用,python,if-statement,Python,If Statement,`所以我只是在做一些测试,看看我是否可以根据输入做出某些输出 每次我尝试输入答案时,这里都没有发生任何事情 我使用了if-elif语句,其中包含in-range。 当我键入答案时,没有显示任何内容 from random import randint from termcolor import colored repeat = True from termcolor import colored import time import sys import multiprocessing

`所以我只是在做一些测试,看看我是否可以根据输入做出某些输出

每次我尝试输入答案时,这里都没有发生任何事情 我使用了if-elif语句,其中包含in-range。 当我键入答案时,没有显示任何内容

from random import randint
from termcolor import colored
repeat = True
from termcolor import colored
import time
import sys
import multiprocessing


   print colored("Hello, this is a program to help you practice algebraic 
    expressions.","magenta")
    print("")
     time.sleep(4)
     print colored("Alright let's start with something very basic...\nWhat is x 
     if 
     2x 
     = 32?","magenta")
     prob = int(raw_input())
   if int(prob) in range (16, 16):
     print colored("Well done, you got the warmup correct","yellow")
   elif int(prob) in range(1, 15):
     print colored("Incorrect answer try again","red")

我写了这段代码,删除了所有你没有使用过的函数,以及那些看起来总是出错的彩色文本。范围通常用于for循环,但在条件语句中,如果大于<小于!=不等于e.t.c

import time
print ("Hello, this is a program to help you practice algebraic 
expressions.")
print("")
time.sleep(4)
prob =int (input("Alright let's start with something very basic What is 
x if 2x = 32? "))

if prob ==16:
    print("Well done, you got the warmup correct")
else:
    print("Incorrect answer try again")
           `
如果intprob在范围16,16:内,则该行有问题。函数rangex,y生成的列表等于[x,y,这意味着从x开始,包括x,以y结束,不包括y,因此,您询问您的数字是否在空数组中。 例子:
list_of_numbers=range12,16为我们提供了元素列表list_of_numbers=[12,13,14,15]

我试图格式化您的代码,但您的缩进已关闭,请修复它。如果intprob在16、16范围内,您希望它做什么?因为它现在基本上什么都不做。您的代码只包含1到14之间的输入。我在16、16范围内进行了设置,因为其他所有操作都失败。如果您检查16、16范围内返回的内容,它将有意义。不明白是什么答案的问题是