Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/288.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
我需要添加什么,让我的Python3程序检查输入是按升序还是降序?_Python - Fatal编程技术网

我需要添加什么,让我的Python3程序检查输入是按升序还是降序?

我需要添加什么,让我的Python3程序检查输入是按升序还是降序?,python,Python,我需要让我的程序检查输入是否按降序排列。它已经工作了,但是不正确,我相信我需要添加更多的东西?我对编程很陌生 这是我的密码: b = 0 last = int(input()) finished= False while not finished: new = int(input()) if new == -1: finished = True elif last == -1: finished = True elif new > last :

我需要让我的程序检查输入是否按降序排列。它已经工作了,但是不正确,我相信我需要添加更多的东西?我对编程很陌生

这是我的密码:

b = 0
last = int(input()) 

finished= False
while not finished:
  new = int(input())
  if new == -1:
    finished = True
  elif last == -1:
    finished = True
  elif new > last :
    b = 1
  elif new <= last:
    b = 2
  last = new

if b == 1:
  print ('yes')
elif b == 2:
  print ('no') 
b=0
last=int(输入())
完成=错误
未完成时:
new=int(输入())
如果新建==-1:
完成=正确
elif last==-1:
完成=正确
elif new>last:
b=1

ELIF新版

应考虑<代码> b <代码>:

b = 0
last = int(input()) 

while True:
    new = int(input())
    if (new == -1) or (last == -1):
        break
    elif new > last :
        if b == 2: # this has been descending until now
            b = 0 # neither ascending nor descending
            break
        b = 1
    elif new < last:
        if b == 1: # this has been ascending until now
            b = 0
            break
        b = 2
    else: # when two adjacent values are equal, this order is neither ascending, nor descending
        b = 0
        break
    last = new

if not b:
    print("Neither ascending, nor descending")
elif b == 1:
    print ('ascending')
elif b == 2:
    print ('descending')
else:
    print("This is odd, we shouldn't have got here...")
b=0
last=int(输入())
尽管如此:
new=int(输入())
如果(新==-1)或(上次==-1):
打破
elif new>last:
如果b==2:#这一直在下降
b=0#既不上升也不下降
打破
b=1
elif new
这将继续请求用户输入,直到它收到一个
-1
作为输入。如果有单个输入按降序排列列表,它将在循环末尾打印
'no'
(当用户输入
-1

b=0
last=int(输入('last:'))
尽管如此:
new=int(输入('new:'))
如果新==-1或上次==-1:
打破

如果是新的,那么将所有输入放在一个列表中并在该列表上操作会更简单。您能提供一些您将获得的输入和输出吗?我们很容易理解您需要什么,为什么您同时要求两个输入?执行此操作时,您还将重写
last
@Exprator中的数据。例如,如果输入1、2、3、4、5、6、7。如果输入1、2、3、4、5、4、3、5、6、7、8,程序必须输出“是”。程序必须输出“否”,但兄弟,你只接受2个输入?你只能查2个号码谢谢,这很有用!
b = 0
last = int(input('Last: ')) 

while True:
  new = int(input('New: '))     
  if new == -1 or last == -1:
      break
  elif new <= last:
    b = 2
  last = new

if b == 2:
  print ('no')
else:
  print ('yes')