vendredi 27 août 2021

how to make a if statement print a string for every time a character is in an input

Ok so I am making a program in python that converts whatever someone inputs to a number code where a is 1 b is 2 so on and so forth. this is what my code looks like to start

print("input a message you would like to be converted to a number code")
inpi = input("")


if " " in inpi:
  print("")
if "a" in inpi:
    print("1.",end = "")
if "b" in inpi:
  print("2.",end = "")

the problem is if a character is in the input more than once it will only print its corresponding number once so for example if you input abab it only prints 1.2 not 1.2.1.2. Im guessing this is a pretty easy fix hopefully i'm not super skilled in python but im trying my best any help is appreciated keep in mind that the indents and lines are in order in my code but for some reason come up weird here.

Aucun commentaire:

Enregistrer un commentaire