简体   繁体   中英

Beginner Ord Print and Table Format Question

I have to write a code that produces the following:

Letter Code
  A     65
  B     66
  C     67
  D     68
  E     69

...

  Z     90

I have this written but it isn't working:

test_str = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
print("Letter " + " Code")
for chr in test_str:
  print(chr)
for ord in test_str:
  print(ord)

I can't get the ord Unicode to print and I don't know how to format so the letters and code end up in table format.

Any help for this beginner would be appreciated.

Try this

test_str = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
print("Letter " + " Code")
for chr in test_str:
     print(chr,ord(chr))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM