Saturday, October 10, 2020

write python turtle program to draw letter E

 import turtle

t=turtle.Turtle()

t.penup()

t.setpos(0,50)

t.pendown()

t.pensize(20)

t.pencolor("red")

t.forward(100)

t.backward(100)

t.right(90)

t.forward(100)

t.left(90)

t.forward(100)

t.backward(100)

t.right(90)

t.forward(100)

t.left(90)

t.forward(100)

write python turtle program for creating Archimedean spiral

 from turtle import *

from math import *

color("blue")

down()

for i in range(200):

    t = i / 20 * pi

    x = (1 + 5 * t) * cos(t)

    y = (1 + 5 * t) * sin(t)

    goto(x, y)

up()

done()

write a python program for creating a class Student with method and constructor

class student:

  def __init__(self,name,age):

        self.name=name

        self.age=age


  def myfunc(self,a,b):

        a=a+b

        return a


p1=student("john",23)

print("My names is",p1.name)

d=p1.myfunc(2,3)

print("sum is",d)

write a python program for creating class person with adding constructor, method

 class Person:

  def __init__(self, name, age):

    self.name = name

    self.age = age


  def myfunc(self):

    print("Hello my name is " + self.name)


p1 = Person("John", 36)

p1.myfunc()

write a java program for demonstration of Finally block

 class Finally1 

{

public static void main(String[] args) 

{

int data =20;

//case 4:finally block not exceuted when use the following method

System.exit(0);

try

{

int c=data/0;

System.out.println("c value is"+c);

}

finally

{

System.out.println("Finally block exceuted");

}

System.out.println("rest of the code exceuted");

}

}


write a java program for exception propagation

 class  Exceptionprop

{

static void s()

{

int data= 20/0;

}

static void  n()

{

        s();

}

static void  m()

{

n();

}

public static void main(String[] args) 

{

m();

System.out.println("Exception Caught at m()");

}

}


write a java program for creating own exception

class InvalidageExeption extends Exception 

{

InvalidageExeption(String s)

{

super(s);

}

}



class TestException 

{

static void validate(int age) throws InvalidageExeption

{

if(age<18)

throw new InvalidageExeption("not valid");

}

public static void main(String[] args) throws InvalidageExeption

{

validate(13);


}

}