CMPT Final Handcoding
CMPT Final Handcoding
n = int(input('Enter: '))
num = 2
count = 0
while count < n:
isPrime = True
for i in range(2, num):
if num % i == 0:
isPrime = False
if isPrime == True:
print(num)
count += 1
num += 1
----------------------------------------------
-----------------------------------------------
# CHECK ASCENDING:
n = int(input('Enter length: '))
lst = []
for i in range(n):
num = int(input('Enter num: '))
lst.append(num)
isIncreasing = True
for j in range(len(alist) - 1):
if alist[j] > alist[j + 1]:
isIncreasing = False
if isIncreasing == True:
print('increasing')
else:
print('not increasing')
-----------------------------------------------
------------------------------------------------
------------------------------------------------
-----------------------------------------------
-------------------------------------------------
------------------------------------------------
# REPLACE OLD CHAR W/ NEW ONES:
-------------------------------------------------
def encrypt(s):
toMorse = ''
for i in range(len(s)):
if s[i] != ' ':
toMorse = toMorse + morse_code[s[i]] + ' '
else:
toMorse = toMorse + ' '
return toMorse
print(encrypt('TRY UR BEST'))
-------------------------------------------------
def split(s):
s = s + ' '
lst = []
word = ''
for i in range(len(s)):
if s[i] != ' ':
word += s[i]
elif word != '':
lst.append(word)
word = ''
return lst
print(split('Hello 1 2 3')
----------------------------------------------
# replace:
def replace(s, old, new):
res = ''
i = 0
while i < len(s):
if s[i] == old[0]:
if s[i : (i + len(old))] == old:
res = res + new
i += len(old)
else:
res = res + s[i]
i += 1
else:
res = res + s[i]
i += 1
return res
-------------------------------------------------
# decrypt:
def decrypt(s):
toStr = ''
word = ''
s = s + ''
i = 0
while i < len(s):
if s[i] != ' ':
word += s[i]
else:
if word != '':
for akey in morse_code:
if morse_code[akey] == word:
toStr = toStr + key
word = ''
else:
toStr = toStr + ' '
return toStr