I was watching this complete Python Tutorial by Mosh Hamadani on youtube.
I saw a small piece of code that he wrote and I wrote it in pycharm.
I got an output that was different from what he got.
This is a program to find the largest number.
This is the piece of code.
The result was
Where did I go wrong?
I saw a small piece of code that he wrote and I wrote it in pycharm.
I got an output that was different from what he got.
This is a program to find the largest number.
This is the piece of code.
1 2 3 4 5 6 |
numbers = [ 11 , 2 , 23 , 45 , 67 , 99 , 101 ] largest_num = numbers[ 0 ] for number in numbers: if number > largest_num: largest_num = number print (largest_num) |
Output:23
45
67
99
101
But, The intended result was 101, the largest number.Where did I go wrong?