CH-8.8-8.10
(TOTALING, COUNTING,
STRING LENGTH,
SUBSTRING, UPPER AND
LOWER STRING)
CLASS CONTENTS
•Totaling
Ch-8.8-8.10
•Counting
•String Length
•Substring
•upper and lower string
2
TOTALING
Python code:
total = 0
For x in range(0, 11):
total = total + x
print(“The total is: ”, total)
Print(“The grand total is ”, total)
3
COUNTING
Python code:
count= 0
total = 0
For x in range(0, 11):
total = total + x
print(“The total is: ”, total)
count = count + 1
Print(“The grand total is ”, total)
Print(“The for loop continued for”, count - 1, “ times.”)
4
LENGTH, UPPER AND LOWER STRING
Python code:
name = input(“Enter your name”)
namelength = len(name)
nameLOW = name.lower()
nameUP = name.upper()
print(“The length of your name is: ”, nameLength)
print(“The lowercase of your name is: ”, nameLOW)
print(“The uppercase of your name is: ”, nameUP)
5
SUBSTRING
Python code:
name = input(“Enter your name”)
nameSub = name[0:1]
nameMoreSub = name[0:3]
Substring = “Helllooooo”[0:1]
Print(“The second character of the substringis: ”, Substring)
Print(“The second character of your name is: ”, nameSub)
Print(“The 2nd till 4th character of your name is: ”, nameMoreSub)
6