lst = []
for i in range(1, 101):
lst = lst + [i]
print(lst)
###
s = "Hello World"
for i in range(len(s)):
print(i, s[i])
###
prices = [ 4, 7.5, 9, 2 ]
total = 0
for i in range(len(prices)):
total = total + prices[i]
print(total)
# vs
prices = [ 4, 7.5, 9, 2 ]
total = 0
for price in prices:
total = total + price
print(total)
###
s = "Hi guys!!! How are you!! I'm so excited!!!"
count = 0
for char in s:
if char == "!":
count = count + 1
print(count)
###
def isPalindrome(s):
s = s.replace(" ", "")
s = s.lower()
for i in range(len(s)):
if s[i] != s[len(s) - 1 - i]:
return False
return True
###
"""
Write a function findMax(lst) which takes a list of
numbers and returns the largest number in the list.
Hint: consider what variables you'll need to keep
track of, and what type of loop you should use.
"""
def findMax(lst):
largest = lst[0]
for number in lst:
if number > largest:
largest = number
return largest
###
def isCapitalized(s):
firstLetter = s[0]
restLetters = s[1:]
return firstLetter.isupper() and restLetters.islower()
###
def getFactors(n):
result = []
for factor in range(1, n+1):
if n % factor == 0:
result.append(factor)
return result