DEV Community

A K I L A N
A K I L A N

Posted on

Simple Programs in python

My trainer gave me 5 question to solve in python the question are look simple when we read line by line sometimes you may understand in different type but there are simple

The questions are

  1. Five students enter the classroom one after another. The first student gets roll number 1, the second gets 2, and so on. Display the assigned roll numbers.

here the answer is

for i in range(1,6):
    print('Student -',i)
    print('Roll no:',i)

Enter fullscreen mode Exit fullscreen mode

from the above

for is the keyword,
i is variable ,
in is use to itrate over the given range() or sequence
sequence given range(),list.

Remaing all three are similar pattens so i will tell the change only

for j in range(2,12,2):
    print("position: ",j)

Enter fullscreen mode Exit fullscreen mode

we can change the starting number and ending number , also step between, we can give step in negative order also

----------------------------x-------------------------------------------x-------

What is Class?

  • Python is a object orientend language, in python every thing is object with its properties and methods

  • class is like a blueprint

  • we can create class name using** class myclass** here **Class **is the keyword

  • we can delete class using del class_name ** here
    **del
    is the keyword

what is object?

  • A object is a real instance of a class it contains Data and Methods

  • data conatins attribute / variables

  • mean while method contains functions

Top comments (0)