strs = 'abcdefghijklmnopqrstuvwxyz' def shiftvalue(value): sentence = input('Enter a short sentence included 5 or 6 words: ') try: value = int(value) if value == 0: print('A shift value must be an integer and not be zero!') else: except ValueError: print('This shift value cannot be an integer! Try again...') if all(sentence.isalpha() or sentence.isspace() for x in sentence): else: print('A sentence should be contained only letters and spacese!') data = [] for i in sentence: if i.strip() and i in strs: data.append(strs[(strs.index(i) + value) % 26]) else: data.append(i) output = ''.join(data) return output コード
質問です。ord関数を使って, アルファベット文字をシフト値(Shift Value)に応じて変えたいのです。
例)shiftvalue=2, A → C, B → D, Y → A, Z → B.
shiftvalue=-2, E → C.
こんな感じの事をやりたいのですが, 調べてもord関数や大文字を小文字に変換するやり方がよくわかりません。
アドバイスお願いします。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。