Thursday, May 7, 2020

Multiplication table

MULTIPLICATION TABLE USING 'C'


#include <stdio.h>

int main() 
{
    int num, i = 1,j;
    printf("Enter Number:");
    scanf("%d", &num);
    printf("enter the digit");
    scanf("%d",&j);
 printf("Multiplication table of %d: ", num);
    
    
    while (i <= j) 
    {
  printf(" %d x %d = %d\n", num, i, num * i);
        i++;
    }
    return 0;
}




output:


Tuesday, November 27, 2018

Introduction to Python

Introduction to Python

Python
Python logo and wordmark.svg
ParadigmObject-orientedimperativefunctionalproceduralreflective
Designed byGuido van Rossum
DeveloperPython Software Foundation
First appeared1990; 28 years ago[1]
Stable release
Typing disciplineDuckdynamicstrong; and since version 3.5: Gradual[4]
LicensePython Software Foundation License
Filename extensions.py, .pyc, .pyd, .pyo (prior to 3.5),[5] .pyw, .pyz (since 3.5)[6]
Websitewww.python.org
Major implementations
CPythonIronPythonJythonMicroPythonNumbaPyPyStackless Python
Dialects
CythonRPython
Influenced by
ABC,[7] ALGOL 68,[8] APL[9] C,[10] C++,[11]CLU,[12] Dylan,[13] Haskell,[14] Icon,[15]Java,[16] Lisp,[17] Modula-3,[11] PerlStandard ML[18]
Influenced
BooCobraCoffeeScript,[19] DF#FalconGenie,[20] GoApache GroovyJavaScript,[21][22] Julia,[23] NimRing,[24]Ruby,[25] Swift[26]



Polymorphism in Python

Polymorphism in Python

Sample code:-


class dog:
def swim (self):
      print("the dog is swimming")
def swim_backwards (self):
      print("the dog is swimming backwards")
def colour (self):
      print("the dog's colour is black")
class cat:
def swim (self):
      print("the cat is swimming")
def swim_backwards (self):
      print("the cat is swimming backwards")
def colour (self):
      print("the cat's colour is brown")
tom=dog()
tom.colour
tomy=cat()
tomy.colour
for animal in (tom,tomy):
      animal.swim()
      animal.swim_backwards()
      animal.colour()
def in_water(aqua):
      aqua.swim()
in_water(tom)
in_water(tomy)





Write a python program to find area of a rectangle using class and object. & Write a python program to find area of a circle using math module and class and object.


  • Write a python program to find area of a rectangle using class and object.
N.B:- Indentation is most important for python programing.

class rectangle:
def_ _init_ _(self,length,breadth):
      self.length=length
      self.breadth
def area(self):
      return self.length*self.breadth
a=int(input("enter length:"))
b=int(input("enter breadth:"))
obj=rectangle(a,b)
print("area of rectangle:",obj.area())



LOOP (Patterns)

Patterns

  • Python program to print following patterns.
* * * *                 >>>for i in range (1,6):
* * * *                              print (" ")
* * * *                             for j in range (1,5):
* * * *                                   print "*",

                            
*                            >>>for i in range (1,5):
* *                                      print (" ")
* * *                                   for j in range(i):
* * * *                                      print "*",


 
1                          >>>for i in range (1,6):
 1 2                                    print (" ")
 1 2 3                                 for j in range (1,i):
 1 2 3 4                                    print j,


1                                >>>num=1
2 3                             >>>for i in range (1,5):
4 5 6                                       print(" ")
7 8 9 10                                  for j in range(0,i):
                                                     print num,
                                                     num=num+1

Write a Python program to find whether an entered number is positive, negative or zero using nested is statements


  • Write a Python program to find whether an entered number is positive, negative or zero using nested is statements
N.B:- Indentation is most important for python programing.


>>>num1=float(input("enter number:"))
enter number: -19
>>>if (num1>0):
. . .     if (num1>0):
. . .        print ("positive")
. . .     else:
. . .        print("zero")
. . .     else:
. . .        print ("negative")
. . .
negative(output)

Write a Python program to find smallest of three values using "and" logical operator.

  • Write a Python program to find smallest of three values using "and" logical operator.
N.B:- Indentation is most important for python programing.

>>>num=10
>>>num=20
>>>num=30
>>>if((num1<num2)and(num1<num3)):
. . .       smallest=num1
. . .  elif((num2<num1)and(num2<num3)):
. . .       smallest=num2
. . .  else:
. . .       smallest=num3
. . .
>>>print " the smallest number between ",num1,",",num2,"and",num3,"is",smallest
The smallest number between 10,20 and 30 is 10(output)

Example of string constructor in Python

String constructor

>>>char1="he"
>>>char2="llo"
>>>print(char1+char2)
hello(output)

Example of summation of two values in Python.

Summation of two values

>>>num1=float(input("enter no:"))
enter no: 10
>>>num2=float(input("enter next no:"))
enter next no: 20
>>>print(num1+num2)
30.3(output)





Python interactive mode

Example:-                



>>> 2+3

5(output)

>>>5-2

3(output)

>>>5*2

10(output)

>>>2**3

8(output)

>>>5*2+3

13(output)

>>>15//3

5(output)




Example python programs

This is the first video in AMEER FAZAL Python Tutorial Video Series. Python is a very popular programming language. In this introductory video AMEER FAZAL was discussing little history of the language to basic information about it and then basic arithmetic operations. The tutorial uses Python 3.5.0, the very latest version and the computer is running on an Ubuntu 14.04 LTS Operating System.


Stay with us for other python programing...


Multiplication table

MULTIPLICATION TABLE USING 'C' #include <stdio.h> int main()  {     int num, i = 1,j;     printf("Enter N...