Уведомления

Группа в Telegram: @pythonsu

#1 Янв. 27, 2022 10:41:27

Ar4i23
Зарегистрирован: 2022-01-22
Сообщения: 1
Репутация: +  0  -
Профиль   Отправить e-mail  

Помогите с решением задачи Python

Добрый день , помогите пожалуйста с решением задачи . Не могу понять что ни так, и как с этим бороться . Проблема вот в чем , нужно написать программу которая будет считывать данные со строки и если в строке есть цифры то она их будет заменять на буквы английского алфавита нумерация которой будет соответствовать индексу ( то есть к примеру буква “a” = ) Прилагаю свой код на ваше обозрение , не судите строго только учусь
#Вот код
text = input()
alf = ‘abcdefghijklmnopqrstuvwxyz’
s = ''
i = 0

while i < len(text) - 1:
a = text
if ‘0’ <= a <= ‘26’:
g = alf
s = text.replace(a,g)

else:
s += text
i += 1

print(s)

Офлайн

#2 Янв. 27, 2022 23:23:34

far4ikg
Зарегистрирован: 2021-11-08
Сообщения: 17
Репутация: +  0  -
Профиль   Отправить e-mail  

Помогите с решением задачи Python

 from string import ascii_lowercase
def replace_function(target: str):
    test_text = ''
    skip = 0
    for index, smbl in enumerate(target):
        try:
            if skip == 1:
                skip = 0
                continue
            elif int(smbl) == 0:
                test_text += ascii_lowercase[int(smbl)]
            elif int(smbl) >= 3:
                test_text += ascii_lowercase[int(smbl)]
            elif index > 0 and int(target[index:index + 2]) <= 25:
                test_text += ascii_lowercase[int(target[index] + target[index])]
                skip += 1
            elif index > 0 and int(target[index - 1:index + 1]) <= 25:
                test_text += ascii_lowercase[int(target[index - 1:index])]
                skip += 1
            elif 0 <= int(smbl) < 3:
                test_text += ascii_lowercase[int(smbl)]
            else:
                test_text += ascii_lowercase[int(smbl)]
        except:
            test_text += smbl
    return test_text
editable_text = input('введите текст: ')
replaced_text = replace_function(target=editable_text)
print(replaced_text)

что то вроде этого должно получится… если не ошибаюсь…)

Офлайн

#3 Янв. 27, 2022 23:42:29

Nefarious
Зарегистрирован: 2022-01-08
Сообщения: 2
Репутация: +  0  -
Профиль   Отправить e-mail  

Помогите с решением задачи Python

2 решения с CyberForum.ru:
1 решение с вводом:
print(''.join(i for i in list(map(lambda x: (chr(int(x) + 97)) if x.isdigit() else x, input()))))
2 решение с текстом:
txt = ‘'’
The United Kingdom of Great Britain and Northern Ireland,
more commonly referred to as the United Kingdom or the UK,
is a unitary state consisting of England, Scotland, Wales and Northern Ireland.
There are also three Crown Dependencies in nearby waters,
and 14 Overseas Territories across the globe. During the 18th and 19th centuries,
the United Kingdom was the world’s foremost superpower,
with roughly a quarter of the world’s landmass and population under the dominion of the British Empire.
Throughout the 20th century, the British Empire gradually dissolved, and countries such as Germany,
the U.S., and USSR gained more international influence;
however, the UK remains one of the world’s leading economies,
with considerable political, cultural, and technological influence.
Since 2016, Brexit, i.e. the UK’s withdrawal from the European Union,
has been the most influential factor in the UK’s foreign policy,
and adaptation to life outside of the EU has had a significant impact domestically.
Thus far, most consider the economic and bureaucratic fallout of Brexit to have been overwhelmingly negative,
it has put strain on the UK’s political relationship with the European trading bloc,
and trade barriers have resulted in shortages or price hikes for certain goods and services.
Nonetheless, the UK will have a higher level of economic autonomy going forward,
and it remains to be seen whether any long-term benefits will outweigh the obstacles and challenges that the UK has faced until now.
'''
lst = ''
for i in txt:
if i.isdigit():
lst +chr(int(i)+65))
else:
lst += i
print(lst)

Офлайн

#4 Янв. 28, 2022 10:28:35

py.user.next
От:
Зарегистрирован: 2010-04-29
Сообщения: 9716
Репутация: +  842  -
Профиль   Отправить e-mail  

Помогите с решением задачи Python

Ar4i23
нужно написать программу которая будет считывать данные со строки и если в строке есть цифры то она их будет заменять на буквы английского алфавита нумерация которой будет соответствовать индексу
Сначала напиши программу словесно, без программирования. Если написать не можешь словесно (просто перечислить словами действия программы), то и язык программирования тебе никак не поможет написать программу.

Например, что будет, если в строке встретятся подряд цифры 123? Это будет 12-ая буква и 3-я буква или это будет 1-ая буква и 23-я буква? А может это вообще будет 1-ая, 12-ая, 23-я и 3-я? Просто опиши словами работу будущей программы. Опиши словами поведение алгоритма в данной ситуации.



Офлайн

Board footer

Модераторировать

Powered by DjangoBB

Lo-Fi Version