[Python] Trying to loop through a str array and convert elements to integers

Discussão em 'Python' iniciado por Stack, Setembro 2, 2025.

  1. Stack

    Stack Membro Participativo

    I am working on a simple problem where I sort exactly three integers in ascending order. Here's what I have written:

    import stdio
    import sys

    nums = sys.argv
    idxLow = min(nums).index
    idxHigh = max(nums).index
    numMid = 0

    for i in nums:
    i = int(float(i))

    if i != idxLow and i != idxHigh:
    numMid = int(float(nums))

    stdio.write(nums[idxLow] + " " + numMid + " " + nums[idxHigh])


    I keep getting ValueErrors, and no matter where I cast, the elements of the nums array, despite being integers, still return errors.

    Input: python three_sort.py 9 2 4

    Restrictions: can only use the stdio and sys libraries, can only use min(), max(), and basic arithmetic

    Continue reading...

Compartilhe esta Página