+ 3

Square Footage #python for data science

You are given an array that holds the square footage data for houses on a particular street. A new house has just been constructed on that street. Modify your program to take the new house value as input, add it to the array, and output the array sorted in ascending order. May I please ask where my error is ############### import numpy as np data = np.array([1000, 2500, 1400, 1800, 900, 4200, 2200, 1900, 3500]) new = input() data = np.append(data,new) data = np.sort(data) print(data)

26th May 2021, 1:16 PM
LI HAN
LI HAN - avatar
13 odpowiedzi
+ 5
LI HAN , your code is ok, except the input, that should be int: new = int(input()
26th May 2021, 3:37 PM
Lothar
Lothar - avatar
+ 6
Freddy Fernando Maldonado Huicho , it would be better if you start a new feed with your question. but i can give you an answer related to appending a new value as int or string: if the new value is input as an int, the result will be: 1900 [1000 2500 1400 1800 900 4200 2200 1900 3500 1900] [ 900 1000 1400 1800 1900 1900 2200 2500 3500 4200] if the new value is input without converting it to int, all values in the array are strings: '1900'' ['1000' '2500' '1400' '1800' '900' '4200' '2200' '1900' '3500' '1900'] ['1000' '1400' '1800' '1900' '1900' '2200' '2500' '3500' '4200' '900'] <<<< sorting in case values are strings, the sorting is done lexicographically, so 900 is the greatest value, because it starts with the greatest digit.
22nd Aug 2022, 6:32 PM
Lothar
Lothar - avatar
+ 5
Simon Sauter , are you sure that your suggestion is working? have you tested it? we are talking here about a numpy array.
26th May 2021, 3:39 PM
Lothar
Lothar - avatar
+ 5
Lavanya 2000 , you posted 100% exactly the same code as ali abdollahi 1 month ago ?
5th Dec 2022, 7:05 PM
Lothar
Lothar - avatar
+ 3
The answer is this import numpy as np data = np.array([1000, 2500, 1400, 1800, 900, 4200, 2200, 1900, 3500]) new = int(input()) data = np.append(data,new) data = np.sort(data) print(data)
25th Aug 2021, 4:06 PM
ANDREW TSEGAYE
ANDREW TSEGAYE - avatar
+ 1
correct answer import numpy as np data = np.array([1000, 2500, 1400, 1800, 900, 4200, 2200, 1900, 3500]) new = int(input()) data = np.append(data,new) data = np.sort(data) print(data)
9th Oct 2021, 12:20 PM
Raoof Zakarna
+ 1
May I ask why when I dont punt int before the input function the array it isn't sort properly?. I saw that the only number wasn't properly sorted was the "900". But why? If the number input was "1100". It is like the number "900" already given in the array was a text. I am confused.
22nd Aug 2022, 3:16 PM
Freddy Fernando Maldonado Huicho
Freddy Fernando Maldonado Huicho - avatar
+ 1
import numpy as np data = np.array([1000, 2500, 1400, 1800, 900, 4200, 2200, 1900, 3500]) newhouse=int(input()) data = np.append(data, newhouse) data = np.sort(data) print(data)
17th Nov 2022, 2:14 AM
Benjamin Fadina
Benjamin Fadina - avatar
0
No. I think my post was wrong.
26th May 2021, 3:43 PM
Simon Sauter
Simon Sauter - avatar
0
Thank you !! It works. Lothar I have forgotten the basic input code haha
26th May 2021, 3:49 PM
LI HAN
LI HAN - avatar
0
Thank you Simon Sauter for the quick reply. Appreciated it.
26th May 2021, 3:51 PM
LI HAN
LI HAN - avatar
0
import numpy as np data = np.array([1000, 2500, 1400, 1800, 900, 4200, 2200, 1900, 3500]) data = np.append(data,int(input())) print(np.sort(data))
27th Oct 2022, 9:47 PM
ali abdollahi
0
import numpy as np data = np.array([1000, 2500, 1400, 1800, 900, 4200, 2200, 1900, 3500]) data = np.append(data,int(input())) print(np.sort(data))
5th Dec 2022, 10:51 AM
Lavanya Mangala