dimanche 28 février 2021

Outputs printed on same line - python

message = str(input())
for i in message:
  if i == " ":
    print(" ")
  else:
    # ord(i) returns the ASCII number for i
    # To get the actual alphabetical position of i, you have to do ASCII of letter - ASCII of A + 1.
    print(ord(i)-ord("a")+1)

This program converts each character of the users input to a letter, based on their alphabetical order (a = 1, b = 2, ect) and prints each number output on a new line. How do I get change this so that when each number is printed, it is on the same line as the last? (eg 123)

Aucun commentaire:

Enregistrer un commentaire