#๐Ÿ”’ How do i go about formatting this table?

23 messages ยท Page 1 of 1 (latest)

random otterBOT
#

@polar swallow

Python help channel opened

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.

jagged hamlet
#

what output are you expecting to get?

glad verge
#

post your code as text, not a screenshot

polar swallow
#

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"))'''

random otterBOT
#

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.
polar swallow
#

'''py

gleaming grail
#

backticks

#

not single quotes

glad verge
#

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"))
random otterBOT
glad verge
#

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"]))
random otterBOT
glad verge
#

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

polar swallow
random otterBOT
#
Python help channel closed

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.