Thursday, January 23, 2020

how to write a basic class in python

class Student:
    def read(self):
        print("Reading student class")
     
s=Student()
s.read()

outputL
Reading student class


you can call multiple times
class Student:
    def read(self):
        print("Reading student class")
     
s=Student()
s.read()
s.read()
s.read()
s.read()

output:
Reading student class
Reading student class
Reading student class
Reading student class


example 2:
class Student:
    def __init__(self,x,y,z):
        self.name=x
        self.rollno=y
        self.marks=z
 
       
s=Student("anil",100,90)
print(s.name,s.rollno,s.marks)

output:
anil 100 90

How to Perform Addition, Subtraction, Multiplication, Division and Modulus operation on two integers.


#include<stdio.h>
void main()
{ int a,b;
printf("\n enter two values: ");
scanf("%d %d",&a,&b);
printf("\n a + b = %d", a+b);
printf("\n a - b = %d", a-b);
printf("\n a * b = %d", a*b);
printf("\n a / b = %d", a/b);
printf("\n a modulus b = %d", a%b);
getch();
}

input:

 enter two values: 13  5

output:

 a + b = 18           
 a - b = 8
 a * b = 65
 a / b = 2
 a modulus b = 3

python class topic video