Python - N5
Python - N5
What is a variable?
A variable is a named memory location that holds data that during the execution of a program, the data
can change
Variables can store a variety of different types of data such as integer, float, boolean.
a = 0
a = 10
What is an array?
Note:
Array : It is a collection of data items of same data type.
List : It is a collection of data items of different data type.
Index : It's the address or pointer to to access the element based on its position.
Print a particular elment in array :
print (fruits)
✅ What is a Loop?
A loop helps us repeat a set of lines without writing the same code again and again.
fruits_length = len(fruits)
for i in range(fruits_length):
print(fruits[i])
# Loop through the list and check if the fruit starts with 'B'
for i in range(fruits_length):
if user_input == i:
print("Fruit is Found")
Print a multiplication table using FOR LOOP
for i in range(5):
print( num , "x" , i+1 , "=" , num * (i+1) )
2 x 1 = 2
2 x 2 = 4
2 x 3 = 6
2 x 4 = 8
2 x 5 = 10
Running Total
Running total means adding values in the Array to the sum using a for loop.
A running total, also known as sum, is a calculation that progressively adds each value in a sequence to
the sum of all previous values. It represents a running or ongoing sum that updates with each new data
point.
Q1.
Q2.
Q3.
Q4.
Q5. Solve below
Q8.
Q9.