s = "Hi everyone!"
for i in range(len(s)):
print(i, s[i])
lst = [ 2, 4, 8, 16, 32 ]
for i in range(len(lst)):
print(i, lst[i])
###
prices = [ 5.50, 3, 2.75 ]
total = 0
for i in range(len(prices)):
total = total + prices[i]
print(total)
###
lst = []
for i in range(1, 11):
lst = lst + [i]
print(lst)
print(lst)
###
s = "awesome"
result = ""
for i in range(len(s)-1, -1, -1):
result = result + s[i]
print(result)
###
"""
Write a bit of code that takes a list of numbers and creates a
new list of numbers where each number has been doubled.
For example, given [1, 2, 3], the code should produce [2, 4, 6].
"""
lst = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
result = []
for i in range(len(lst)):
result = result + [ lst[i] * 2 ]
print(result)
###
def isPalindrome(s):
for i in range(len(s)):
front = s[i]
back = s[len(s) - 1 - i]
print(front, back)
if front != back:
return False
return True
print(isPalindrome("racecar"))
print(isPalindrome("riskier"))
###
"""
write a function getPunctuationFrequency(text, punc) that takes a text message
(a string) and a punctuation character (another string) and returns the
frequency of how often that character appears in the text compared to other
characters - the number of times it appears over the total number of characters.
For example, getPunctuationFrequency("That's so exciting!! Good for you man!", "!")
would return ~0.079, because exclamation marks form 3/38 = ~0.079 as a ratio of
the characters in the text.
"""
def getPunctuationFrequency(text, punc):
count = 0
for i in range(len(text)):
if text[i] == punc:
count = count + 1
return count / len(text)
print(getPunctuationFrequency("That's so exciting!! Good for you man!", "!")) # should be 0.079