Search code examples
pythonloopsprintingrowpercentage

Substract given numbers?


i'd like to give a row of bulk numbers and print their 10% (*0.1):

1000
2000
3500

print results -->

100
200
350

Do i do this basic example with Python?
Any suggestion appreciated


Solution

  • You can do this by looping though the list.
    Lets say you have a list of numbers, like so:

    nums = [1000, 2000, 3500]
    

    Now we can create a loop, to go through each item in the list:

    for num in nums:
        print(num)
    

    The above would print each number in the list, but if you want 10%, you can multiply by 0.1 before you print it:

    print(num * 0.1)
    

    Merge these toghether, and you'll have your loop!