在range()语句中不起作用

时间:2018-03-02 20:56:17

标签: python if-statement

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

每当我尝试输入答案时,这里什么都没发生 我使用if ifif()中的elif语句。 我输入答案时没有显示任何内容

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")

2 个答案:

答案 0 :(得分:0)

这一行if int(prob) in range(16,16):是个问题。函数range(x,y)生成的列表等于[x,y),这意味着从x开始并包含x,以y结尾,不包括y,因此,您将询问您的数字是否为空数组。 例:     list_of_numbers = range(12,16)为我们提供了包含list_of_numbers = [12,13,14,15]

元素的列表

答案 1 :(得分:-1)

我已经编写了这段代码,删除了您尚未使用的所有功能以及似乎总是出错的彩色文本。范围通常用于"用于"循环,但在条件中你需要使用==如果它等于>大于<小于!=不等于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")
           `