Sample programs: Functions basics

Simple programs - solution for practice:

 Copy and try on your own.
1) First 10 prime numbers program in python
    code:
    n = 10
    count=0
    answer=[]
    print("First ten prime no program in Python")
    for i in range(1,n+1):
        for j in range(2,n+1):
            if i % j == 0:
                count+=1
        if count == 1:
            answer.append(i)
        count=0
    print(answer)

Lists in Python

What is List?
  • List is one of the most common collection datatypes in Python which is ordered and mutable (changeable).
  • It is used to store a group of an element together in a sequence.
  • List can store both homogenous and heterogeneous elements i.e., a single list may contain data types like integers, floats, strings as well as objects.
    • Individual value in a list is called as elements.
    • These elements will be stored in a contiguous memory location.
        For Ex:  Number1 = 10
                      Number2 = 20
                      Number3 = 30,  
                      Number4 = 40 
    • These individual variables can be represented in a list as
                      Number_list = [ 10, 20, 30, 40 ]