Part of an assignment to re-implement a cypher as a function using string.ascii_uppercase and eventually string.digits to iterate through a given input string/statement. Seeing the amount of other versions is cool, but have to use this specific method.
I can get along with doing this outside of a function, but whence added to a function, I yield only a single character and being unfamiliar with the string method, I think there may be a piece missing from what I constructed.
function: cypher(s)
input: s
result: result of function
key: 25-letter_position
import string
def cypher(s):
s=s.upper()
result=""
for ch in s:
if ch in string.ascii_uppercase():
letter_position = string.ascii_uppercase.find(ch)
new_letter = string.ascii_uppercase[25-letter_position]
result = result + new_letter
else:
result = result + ch
return result
s = input("Input a string: ")
print("Cyphertext: ",result)
sonofjeffgoldblum is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1