In [5]:
#4: Write a function called showNumbers that takes a parameter called limit. 
#It should print all the numbers between 0 and limit with a label to identify the even and odd numbers. 
#For example, if the limit is 3, it should print:
#0 EVEN
#1 ODD
#2 EVEN
#3 ODD

def showNumbers(limit):
    for x in range(limit+1):
        if x%2 == 0:
            print(x,"EVEN")
        else:
            print(x,"ODD")

showNumbers(3)
#if C1:
#     ???
#elif C2:
#    ???
#elif C3:
#    ???
#
#else:
#    ???
0 EVEN
1 ODD
2 EVEN
3 ODD
In [ ]:
x = 12
x%2 == 0
In [ ]:
import string

def encrypt(s):
    # this function returns the encrypted form of s
    # s = "14:00/the ships are in position"
    key = int(s[0:2])
    k = s.index('/')
    plain = s[k+1:]
    init_string = s[0:k+1]
    #Strategy 1:
    for c in plain:
        ???
    
    #Strategy 2:
    for word in plain.split():
        ???
    
    
    return answer
    # answer = "14:00/7,21,18_6,21,22,3,6_14,5,18_22,1_3,2,6,22,7,22,2,1"


###SLICE-DICE-STITCH STRINGS!!!!
    
    
    
    
def decrypt(s):
  # this function returns the decrypted form of s
  ???

def main():
    #s = "14:00/the ships are in position"
    #s = "21:30/17,25_21,12,25_12,25,21,24,19_14,9_21,14,14,21,23,5"
    while True:
        s = input("\nEnter e plain-text or d coded-text or q: ")
        if s[0] == "e":
            print("Encrypted text is: "+encrypt(s[2:]))
        elif s[0] == "d":
            print("Decrypted text is: "+decrypt(s[2:])) 
        elif s[0] == "q":
            break
        else:
            print("Invalid choice")

main()
In [11]:
s = "14:00/the ships are in position"
int(s[0:2])
str(344)
Out[11]:
'344'
In [21]:
s = "namaste/howdy"
k = s.index("/")
fw = s[0:k]
sw = s[k+1:]
nw = s[k+1:] + '/' + s[0:k]
print(fw)
print(sw)
print(nw)
namaste
howdy
howdy/namaste
In [14]:
xs = [10,20,30,40,50,60]
xs.index(30)
Out[14]:
2
2 strategies: encrypt one letter at a time encrypt one word at a time
In [22]:
x = "the ships are in position".split()
print(x)
['the', 'ships', 'are', 'in', 'position']
In [ ]: