#creating a lists of students
students=["Onuorah", "Abiodun", "Abu", "Chioma"]
#creating a lists of grades
grades=[50, 48, 20, 37]
#continue from example 1
print (grades)
print (students)
#continue from example 1
#loop through the lists and print each items
for name in students:
print (name)
for grade in grades:
print (grade)
students=["Onuorah", "Abiodun", "Abu", "Chioma"]
print (students[0]) #will output Onuorah
print (students[1]) #Abiodun
print (students[2]) #Abu....
msg="Welcome to TEA Learn"
#accessing single character from the string
print (msg[0]) #will output 'W'
print (msg[0:7]) #will output 'Welcome'
print (msg[8:11]) #will output 'to'
itemcost = [] #empty list
num=int(input("How many products was ordered "))
#use loop to loop through number of products ordered.
for n in range(num):
#ask user to enter the cost for each product
each_cost = float(input("Enter a product cost "))
#store the inputted cost to the empty list
itemcost.append(each_cost)
#Display each product cost and sum total
total_cost=0
count=0
for y in range(num):
product_cost=itemcost[y]
count=count+1
print ("Product ",count," = ",product_cost)
#sum as we loop through....
total_cost=total_cost+product_cost
print ("The total cost is ",total_cost)
#Program to search if user name exist in a list
usernames=["bola", "hammed", "chido", "ada"]
search=input("Enter the name you searching for ")
flag=0
for item in usernames:
if search.lower()==item:
flag = 1
break #item found exit loop
if flag==1:
print (search, " exist in our record")
else:
print (search, " NOT found...")
No Comment yet!