4

How can I make this python code:

# -*- coding: cp1252 -*-
a=4
b=2
c=1.0
d=1.456
print '%fx³ + %fx² + %fx + %f = 0' %(a,b,c,d)

print like this:

4x³ + 2x² + 1x + 1.456 = 0

instead of like this (how it prints currently):

4.000000x³ + 2.000000x² + 1.0000000x + 1.456000 = 0
jamesbtate
  • 1,359
  • 3
  • 19
  • 25

2 Answers2

4
print '%gx³ + %gx² + %gx + %g = 0' %(a,b,c,d)
Bertrand Marron
  • 21,501
  • 8
  • 58
  • 94
2

Use this > Python Decimals format

Community
  • 1
  • 1
neebz
  • 11,465
  • 7
  • 47
  • 64