#๐ How do i go about formatting this table?
23 messages ยท Page 1 of 1 (latest)
@polar swallow
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
what output are you expecting to get?
post your code as text, not a screenshot
Enter desired table length: 2
Kilograms Pounds
1 2.20
2 4.40
'''py#Request user input the length of table
amtKilo = int(input("Enter desired table length: "))
#Display headers for table
print(format("Kilograms", "<10s"), format("Pounds", "<10s"))
#Display table using the amtKilos
for i in range(1, amtKilo + 1):
print(f"{i:<10d}", end=' ')
pounds = (i * 2.2)
for i in range(1, amtKilo):
print(format(pounds, ".2f"))'''
Hey @polar swallow!
It looks like you are trying to paste code into this channel.
You seem to be using the wrong symbols to indicate where the code block should start. The correct symbols would be ```, not '''.
Furthermore, it looks like you incorrectly specified a language for your code block. Make sure you put your code on a new line following py. There must not be any spaces after py.
Here is an example of how it should look:
```py
print('Hello, world!')
```
This will result in the following:
print('Hello, world!')```
You can **edit your original message** to correct your code block.
'''py
If you don't insist on doing it all yourself, try the "tabulate" library
I can't understand what you're trying to do
I'm guessing you want this
!e
amtKilo = 10
print(format("Kilograms", "<10s"), format("Pounds", "<10s"))
for k in range(1, amtKilo + 1):
print(f"{k:<10d}", end=" ")
pounds = k * 2.2
print(format(pounds, ".2f"))
:white_check_mark: Your 3.12 eval job has completed with return code 0.
001 | Kilograms Pounds
002 | 1 2.20
003 | 2 4.40
004 | 3 6.60
005 | 4 8.80
006 | 5 11.00
007 | 6 13.20
008 | 7 15.40
009 | 8 17.60
... (truncated - too many lines)
Full output: https://paste.pythondiscord.com/HK4UVO753TI2MMGD6IQ75MS4FY
or if you as me, this is better
!e
import tabulate
table = []
for kilos in range(1, 11):
pounds = kilos * 2.2
table.append([kilos, pounds])
print(tabulate.tabulate(table, headers=["Kilograms", "Pounds"]))
:x: Your 3.12 eval job has completed with return code 1.
001 | Traceback (most recent call last):
002 | File "/home/main.py", line 1, in <module>
003 | import tabulate
004 | ModuleNotFoundError: No module named 'tabulate'
pff
it gives this ```
Kilograms Pounds
1 2.2
2 4.4
3 6.6
4 8.8
5 11
6 13.2
7 15.4
8 17.6
9 19.8
10 22
takes care of all that formatting for you
Yess this is what I was trying to do. Thank you for your help !
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.