0
import sys
import cs50

while True:
    if len(sys.argv) != 2:
        print("Please enter the key")
    break

key = sys.argv[1]
i = 0
string = cs50.get_string()

for i in range (i,len(string),+1):
    if (isalpha(string[i])):
        #ASCII VALUES
        if (upper(string[i])):
            a = string[i] - 65
            b = (a + k) % 26
            c = b + 65
            print(c)
        else:
            a = string[i] - 97
            b = (a + k) % 26
            c = b + 97
            print(c)
    else:
        print(string[i])

Why python does not detect my commands if (isalpha(string[i])):, if (upper(string[i])): and in the ASCII formula b = (a + k) % 26

some library missing?

In Python what is the equivalent symbol in c for (%)?

0

In python % is the same as % in c

| improve this answer | |
1

Python string method upper corresponds to C's toupper, instead use string[i].isupper().

And there was a hint towards ord and chr for conversion between character and unicode number.

And you might want to add some , end="" to your print function's arguments to suppress the newline at the end.

And for i in range (i,len(string),+1): should really be for i in range (0,len(string),1): without i in the call to range, or better for i in range(len(string)): (and no i=0 needed)

You use k, while you wrote key = sys.argv[1]. You might want to use the same name for both, and use int function on sys.argv[1], like k = int(argv[1]).

Your while loop

while True:
    if len(sys.argv) != 2:
        print("Please enter the key")
    break

is equivalent to

if len(sys.argv) != 2:
    print("Please enter the key")

so you don't exit the application on missing arguments, but just complain and proceed.

| improve this answer | |

You must log in to answer this question.