 What's wrong with this code?

What's wrong with this code?
0

I want to make a code that detect the presence of ascending or descending number. The code will works like this, it will ask you to enter a number unless u enter ‘x’. Then it will output A if numbers are in ascending order, D if numbers are in descending order. If there is only one number, it will output A and D.
The numbers are not necessarily next to each other, they can be 1,2,3,4,6 or 1,3,3,4,5. It will output nothing if the numbers are not in ascending or descending order.

Below are the output I supposed to get. However, it only output A when there is only one number. And it does not output D when the numbers are in descending order.
Number: -1
Number: -1
Number: x
A
D

Number: 1
Number: 3
Number: 3
Number: 4
Number: -5
Number: x

Number: 1
Number: 3
Number: 3
Number: 4
Number: 5
Number: x
A

Number: 1
Number: x
A
D

Number: 1
Number: -100
Number: x
D

num=input('Number: ')
count=0
count1=0
count2=0
k=[num]
while num!='x':
num=input('Number: ')
k.append(num)
count+=1
for i in range(count):
if k[i]<=k[i+1]:
count1+=1
if count1==count:
print('A')
if k[i]>=k[i+1]:
count2+=1
if count2==count or count==1:
print('D')

what errors do you get ?

num=int(input('Number: '))
count=0
count1=0
count2=0
k=[num]
while num != ‘x’:
num=int(input('Number: '))
k.append(num)
count+=1
for i in range(count):
if k[i]<=k[i+1]:
count1+=1
if count1==count:
print(‘A’)
if k[i]>=k[i+1]:
count2+=1
if count2==count or count==1:
print(‘D’)

it only outputs A when there is only one number, but it is supposed to output both A and D when there is only one number. And it does not output D when the numbers are in descending order.

okay let me check again

1 Like