Reputation: 101
I'm very new to python but i will try to explain. I have a input like this 1234567890
and i want it to be more readable when it is a larger number and i want it to be formatted like this 1,234,567,890
.
from datetime import datetime
def price_calc():
the_item = 38
amount_of_the_item = input("Amount of items: ") #This output is what i want to change.
price = ((int(amount_of_the_item)) * (int(the_item)))
print("{:,}".format(price),"USD")
now = datetime.now()
t = now.strftime("%H:%M:%S")
print("Time", t)
while True:
price_calc()
Right now I get this from the console:
Amount of items: 1234567890
46,913,579,820 USD
Time 01:22:29
But I want to get this instead:
Amount of items: 1,234,567,890
46,913,579,820 USD
Time 01:22:29
and the first line of the console output is what I want to change.
Upvotes: 2
Views: 101
Reputation: 101
I solved the problem in a way so the input of the user gets cleard from the terminal before it shows up on the screen and I still have the value
OLD CODE
from datetime import datetime
def price_calc():
the_item = 38
amount_of_the_item = input("Amount of items: ") #This output is what i want to change.
price = ((int(amount_of_the_item)) * (int(the_item)))
print("{:,}".format(price),"USD")
now = datetime.now()
t = now.strftime("%H:%M:%S")
print("Time", t)
while True:
price_calc()
NEW CODE
import os #NEW
from datetime import datetime
def price_calc():
os.system("cls") #NEW
the_item = 38
amount_of_the_item = input("Amount of items: ")
print('\033[1A[\033[2K\033[1G', end='') #NEW
print('Amount of items: {:,}'.format(int(amount_of_the_item))) #NEW
price = ((int(amount_of_the_item)) * (int(the_item)))
print("{:,}".format(price),"USD")
now = datetime.now()
t = now.strftime("%H:%M:%S")
print("Time", t)
input("Press Enter To Continue") #NEW. This is a buffer so the code dont clear it self before i can read it.
while True:
price_calc()
The console output i get now is this:
Amount of items: 1,234,567,890
46,913,579,820 USD
Time 15:15:59
Press Enter To Continue
Thank you for all the help i got.
Upvotes: 1