Array input doubt

How can we take array as input from user?

Hello @vatsal50, it depends on the way the nos. are shown in the input format.
For eg., if the input format is,
5
1
2
3
4
5
Then you will take input like,

n = int(input())
arr = []
for i in range(n):
   x = int(input())
   arr.append(x)

if the input format is,
5
1 2 3 4 5

Then you will take input like,

n = int(input())
arr = list(map(int,input().split()))

I hope both the ways are clear to you depending on the type of input format.
If it is clear to you pls mark it as resolve.
Thanks :slight_smile:

Pls explain this line arr = list(map(int,input().split()))

https://ide.codingblocks.com/s/399086 Please check

In this format, we have been given the nos. in the series like,
1 2 3 4 5 6
if we do n = input()
then the value of n will be 1 2 3 4 5 6 as a whole, and its type will be a string
But by doing arr = list(map(int,input().split()))
I am inputting the nos. Splitting them using the input(). Split () function and then I am specifying the type of the no. or whatever I want, so I have decided that by giving int, we need to map this int with every no. The list is used to enclose all of them into a list.
So, the arr will be

arr = [1, 2, 3, 4, 5, 6] # So the array will be this,

I hope both the ways are clear to you, in case if there is any confusion pls let me know.
If it is clear to you, please mark it as resolve and feel free to provide the feedback.
Thanks :slight_smile:

Can you pls tell me which ques is this ??

Python Practice Questions - Increasing decreasing sequence

Please reply and suggest changes

Hello @vatsal50, hey bro sorry for the delay.
Your code is absolutely correct. It is just not handling the cases where all the elements or the consecutive elements are equal as we need strictly increasing or decreasing sequence.
Add this condition as well,

		if x == a:
			print("false")
			k = 1
			break

Your corrected code:

try:
	check=0
	k=0
	n=int(input())
	a=int(input())
	for i in range(0,n-1):
		x=int(input())
		if x == a:
			print("false")
			k = 1
			break
		if x<a and check==0:
			a=x
			continue
		elif x>a and check==0:
			check=1
			a=x
		elif x<a and check==1:
			print("false")
			k=1
			break
		elif x>a and check==1:
			a=x
			continue	
	if k==0:
		print("true")

except:
	pass

It will surely work, and I hope you understand this.

Thank you for help!!!

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.