Home > OS >  Substract given numbers?
Substract given numbers?

Time:10-22

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

CodePudding user response:

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!

CodePudding user response:

Is your "bulk items" in a type of data structure, i.e. an "Array"? If so create a loop / iterator that goes through all the bulk items and times them by 0.1;

i.e.

for i in bulk:
  print(i * 0.1 "\n") 
  • Related