Maksymalna wartość

0

Jak przetłumaczyć ten kod z C# do Pythona ?

class Program
{
static void Main(string[] args)
{

int[] tab = new int[5];

        tab[0] = 12;
        tab[1] = 23;
        tab[2] = 45;
        tab[3] = 67;
        tab[4] = 97;

        int max = tab[0];
        
        for(int i=0; i<tab.Length; i++)
        {
            if(tab[i] > max)
            {
                max = tab[i];
            }
        }
        Console.Write("Max value is: " + max);
    }
}
0
list_of_numbers = [12, 23, 45, 67, 97]
print('Max value is: ', max(list_of_numbers))

Lub posługując się algorytmem (co jest według mnie dość bez sensowne jeśli mam funkcję wbudowaną):

list_of_numbers = [12, 23, 45, 67, 97]
maximum_value = list_of_numbers[0]

for number in list_of_numbers:
    if number > maximum_value:
        maximum_value = number

print('Max value is: ', maximum_value)

1 użytkowników online, w tym zalogowanych: 0, gości: 1