Написать программу, в которой вводимая строка перебиралась по буквам и буквы преобразовывались в числа из алфавита A1 - Z26, заранее спасибо =) (на python 2.7)
def convert_string_to_numbers(input_string): result = [] for char in input_string.upper(): if ord(char) >= 65 and ord(char) <= 90: result.append(ord(char) - 64) return result input_string = raw_input("Enter a string: ") numbers_list = convert_string_to_numbers(input_string) print("Numbers from the input string:") for num in numbers_list: print(num)
To run the program, simply copy and paste the code into a Python 2.7 interpreter or IDE. Then enter a string and the program will output the numbers corresponding to the letters in the input string.
Sure, here is the program in Python 2.7:
def convert_string_to_numbers(input_string):result = []
for char in input_string.upper():
if ord(char) >= 65 and ord(char) <= 90:
result.append(ord(char) - 64)
return result
input_string = raw_input("Enter a string: ")
numbers_list = convert_string_to_numbers(input_string)
print("Numbers from the input string:")
for num in numbers_list:
print(num)
To run the program, simply copy and paste the code into a Python 2.7 interpreter or IDE. Then enter a string and the program will output the numbers corresponding to the letters in the input string.