I am trying to get the output like:
…
¥ 7,793.94
¥ 2,320.83
¥ 14,452.77
¥ 325.35
¥ 6,333.48
Here is the code:
money_list = [134, 978, 543, 1654, 1078, 321, 1999, 45, 876, 1500] total = [i * 7.23 for i in money_list] # converting USD to CNY print('nThe amount of yuan each tourist will get is:') for each_person in total: each_rounded = round(each_person,2) print(f'¥{each_rounded:{1}{2}}')
This is what I got:
The amount of yuan each tourist will get is:
¥ 968.82
¥ 7070.94
¥ 3925.89
¥ 11958.42
¥ 7793.94
¥ 2320.83
¥ 14452.77
¥ 325.35
¥ 6333.48
¥ 10845.0
The instructions I try to follow on f-string is: https://peps.python.org/pep-0498/
Please help provide other references that you think will be helpful?
Questions:
- How to add the ‘,’ every thousand?
- How to make the distance between ¥ and numbers even closer?
- How to change the last number to 10845.00 instead?
- I also tried the format like each_rounded:{10}.{2} which starts to give me scientific formats that I don’t need. I am confused about that too. That’s why I tried {1}{2}, even though I don’t know the mechanism behind it.
user26138788 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.