Home > Software engineering >  Shrink range of numbers from the end
Shrink range of numbers from the end

Time:05-21

I need help how can i calculate this result?

for test in range(6):
    math = 3*test
    math1 = 141593*test


    print(math,round(math1))

3,141593
6,283186

i search output something to round

3,14
6,28

if 5  
6,285186
output search is 6,29

ect... all attempts make me mistake

CodePudding user response:

Since both math and math1 are integers, round won't do anything. Do you maybe want to just slice the "decimal" part to 2 characters?

for i in range(6):
    a = 3 * i
    b = 141593 * i
    print(a, str(b)[:2], sep=",")

This prints out

0,0
3,14
6,28
9,42
12,56
15,70

CodePudding user response:

solved

for i in range(1,6 1):
    a = 3.141593 * i
    print(a)
    print(round(a,2), sep=",")
  • Related