0

I am having trouble solving the following problem:

Ask number input from user and display it as 20.000,00 In case of invalid input from the user, the program must proper message and then repeats the question again. Salary: valid floating point number between (and including) 20.000,00 and 80.000,00.

So is there a way to display decimal separators with a comma? It seems that just about half the world uses dots and the other half uses commas. How do I tackle this problem without using the import function? If there is no better way then use import function then please show me how it's done in this case.

The following code is what I have tried to solve it:

while True:
    annual_salary = float(input("Annual Salary:"))
    print("{:,}".format(annual_salary))
    break

while True:
    annual_salary = float(input("Annual Salary:"))
    print("{:.2f}".format(annual_salary))
    break

Thank you in advance!

Weiyii Jin
  • 11
  • 3
  • Maybe https://stackoverflow.com/questions/7106417/convert-decimal-mark-when-reading-numbers-as-input or https://stackoverflow.com/questions/55379722/how-to-format-a-float-with-a-comma-as-decimal-separator-in-an-f-string – Timothy G. Sep 30 '22 at 18:15
  • Dear Timothy, I have seen the first link but not the second one, so thank you for your input. I am not really allowed to use import yet by my teacher but i will try if the second thread might help me. – Weiyii Jin Sep 30 '22 at 18:31

0 Answers0