Python Forum
Python random formatting issues
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python random formatting issues
#10
(Jan-28-2018, 09:23 PM)Gribouillis Wrote:
(Jan-28-2018, 09:03 PM)Barnettch3 Wrote: It just seems like a bug and was wondering if anyone else had experience with something like this.
If there is a bug, it is in your code, it is not in the python interpreter. The round function does exactly what the documentation says. If you are experimenting errors with formatting, then you need the format method. For example the line
print(F*100, "%")
is better written
print('{:.2f} %'.format(F*100))
Can you describe the issue more precisely or give a code that we can run to see the pathological behavior?

Thank you that works but im just trying to understand why it would give me this problem in the first place, if you look at item B you can see what I mean.
def dms_calc():
    import math
    DMS = input("Choose DMS Letter A-F").strip().upper()
    DMS_Cost = 250000
    if DMS == "A":
        A = (0.187547-(0.01836*(math.log10(DMS_Cost/7.76))))
        A = round(A,4)
        print(A*100, "%")
        print("$",DMS_Cost*A)
    elif DMS == "B":
        B = (0.164145-(0.015303*(math.log10(DMS_Cost/7.76))))
        B = round(B,4)
        print(B*100, "%")
        print("$",DMS_Cost*B)
    
    elif DMS == "C":
        C = (0.142432-(0.010594*(math.log10(DMS_Cost/7.76))))
        C = round(C,4)
        print(C*100, "%")
        print("$",DMS_Cost*C)
    elif DMS == "D":
        D = (0.141419-(0.01236*(math.log10(DMS_Cost/7.76))))
        D = round(D,4)
        print(D*100, "%")
        print("$",DMS_Cost*D)
    elif DMS == "E":
        E = (0.118011-(0.009279*(math.log10(DMS_Cost/7.76))))
        E = round(E,4)
        print(E*100, "%")
        print("$",DMS_Cost*E)
    elif DMS == "F":
        F = (0.09521-(0.006301*(math.log10(DMS_Cost/7.76))))
        F = round(F,4)
        print(F*100, "%")
        print("$",DMS_Cost*F)
>>> dms_calc()
Choose DMS Letter A-FA
10.48 %
$ 26200.0
>>> dms_calc()
Choose DMS Letter A-FB
9.520000000000001 %
$ 23800.0
>>> dms_calc()
Choose DMS Letter A-FC
9.47 %
$ 23675.0
>>> dms_calc()
Choose DMS Letter A-FD
8.57 %
$ 21425.0
>>> dms_calc()
Choose DMS Letter A-FE
7.62 %
$ 19050.0
>>> dms_calc()
Choose DMS Letter A-FF
6.68 %
$ 16700.0
>>> 
Reply


Messages In This Thread
Python random formatting issues - by Barnettch3 - Jan-24-2018, 06:05 PM
RE: Python random formatting issues - by Larz60+ - Jan-24-2018, 06:35 PM
RE: Python random formatting issues - by j.crater - Jan-24-2018, 06:54 PM
RE: Python random formatting issues - by j.crater - Jan-24-2018, 07:02 PM
RE: Python random formatting issues - by snippsat - Jan-24-2018, 09:33 PM
RE: Python random formatting issues - by Barnettch3 - Jan-28-2018, 09:03 PM
RE: Python random formatting issues - by Barnettch3 - Jan-28-2018, 10:31 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  String formatting (strptime) issues Henrio 2 904 Jan-06-2023, 06:57 PM
Last Post: deanhystad
  python-docx: preserve formatting when printing lines Tmagpy 4 2,216 Jul-09-2022, 01:15 AM
Last Post: Tmagpy
Shocked Issues Installing Pyenv/Python 3.9.1 Brandon_Contactum 1 2,627 Feb-22-2022, 06:32 PM
Last Post: snippsat
  OpenPyXl formatting issues kpayney1 0 1,745 Nov-26-2021, 01:56 AM
Last Post: kpayney1
  Formatting issues? Mark17 1 1,750 Dec-30-2020, 04:17 PM
Last Post: Mark17
  Changing to new Python formatting example leodavinci1990 3 2,078 Sep-22-2020, 07:36 PM
Last Post: yaythomas
  TurtleWorld on MAC in Python 3.6 issues benniehanas 3 3,779 Jul-09-2018, 08:00 PM
Last Post: ichabod801
  Issues with Python script as service satishgunjal 8 7,632 Jun-21-2018, 11:40 AM
Last Post: satishgunjal
  python variable issues - using spyder and opencv Afrodizzyjack 5 5,895 Jun-19-2018, 09:46 AM
Last Post: gontajones
  issues while using Psexec from python code dev_devil_1983 0 3,620 May-28-2018, 07:55 AM
Last Post: dev_devil_1983

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020