+ 4

[SOLVED] Please what's wrong with this python exercise?

Program to get lease number of an array without using min() function. Why is my output 0 ? https://code.sololearn.com/cTro0R3eC78N/?ref=app

22nd Dec 2020, 8:44 AM
Stonny
Stonny - avatar
8 Respostas
+ 8
arr = [63, 88, 9, -1, 0] min_num = arr[0] + 1 for index in arr: if index < min_num: min_num = index print(min_num)
22nd Dec 2020, 8:47 AM
Иван Чикyнов
Иван Чикyнов - avatar
+ 4
print(min(arr)) in your code the variable "num" does not change until all iterations of the loop have passed. add "print (num)" immediately after "num=arr[0]"
22nd Dec 2020, 9:05 AM
Hips
Hips - avatar
+ 3
Иван Чикyнов thanks. and why did you add +1 up there ?
22nd Dec 2020, 8:50 AM
Stonny
Stonny - avatar
+ 3
Then, when rebuilding, min_num will first become equal to the first element of the array
22nd Dec 2020, 8:52 AM
Иван Чикyнов
Иван Чикyнов - avatar
+ 2
Иван Чикyнов Thank you so much 🎅🙂
22nd Dec 2020, 8:55 AM
Stonny
Stonny - avatar
+ 2
It's printing -1
23rd Dec 2020, 5:12 PM
brijal kansara
brijal kansara - avatar
+ 1
brijal kansara IT'S BEEN SOLVED 🎅🙂 THAT'S WHY YOU SEE -1
23rd Dec 2020, 6:30 PM
Stonny
Stonny - avatar
- 1
Poaomm,z .s,
24th Dec 2020, 12:54 AM
M.Ridho