Hi, I’m following a YouTube video with some python simple programming exercises, but my returns are not what they should be. Such as:
student is asked to create a program to find the largest number in a list:
numbers = [3,6,2,4,8,10]
max=numbers[0]
for item in numbers:
if item>max:
max=item
print(max)
Thus the program should return only 10, claims the author of the video, because the program compares successively, each number with the first item and keeps only the largest. But in fact the program returns 6,8,10. Which is logical to me, because the way the code is written, there are three numbers>numbers[0]. But why this difference? And how should the code be written to get the desired return?
Another example:
student is asked to draw an F using only for loops - no print(* ‘*’)
**
**
**
according to the video Solution is:
numbers=[5,2,5,2,2]
for item in numbers:
stars = [""]
for stuff in range(item):
stars+="*"
print(stars)
However, this does not return the required result, the F, but something like
*
**
**, etc. Which is again logical, because the program iterates the whole range of each item, not only the final value. But why? Is it a matter of the Python version (video is from 2020)? And how should the code look like to get the result?