Friday, 26 May 2023

Write a Shell script to find sum of two given numbers

CODE 


n1=10

n2=20

sum=`expr $n1 + $n2`

echo " SUM = " $sum

Write a shell script to display system date in following format:

 Output :

 Today is September 24 2009

 Today is Thursday

 Time is in hh: mm: ss AM/PM


Code :


NOW=$(date +"%B %C %Y")

 echo "Today is" $NOW

 NNOW=$(date +"%A")

 echo "Today is" $NNOW

 TTIME=$(date +"%r")

 echo "Time is " $TTIME

Output :

$ sy1.sh

Today is March 01 2021

Today is Monday

Time is 10:44:12 AM

Wednesday, 10 August 2022

WRITE A JAVASCRIPT TO CHECK ENTERED STRING BEGIN AND END ITH OR NOT

Check whether the entered string begins and ends with X or not (X is any character of your choice) 


<!DOCTYPE html>

<html>

<body>


<p>Click the button to check where if the string starts with the specified value.</p>


Enter Name: <input type="text" name="txt_name" id="name"/> <br/>

//<input type="text" name="txt_name1" id="name1" size="1" maxlength="1"/>


<button onclick="myFunction()">Try it</button>


<p id="demo"></p>


<p><strong>Note:</strong> The startsWith() method is not supported in IE 11 (and earlier versions).</p>


<script>

function myFunction() {

  var str = document.getElementById("name").value;

  //var test = document.getElementById("name1").value;

  var n = str.startsWith

  //document.getElementById("demo").innerHTML = n + n1;

  

  if(n == true) {

document.getElementById("demo").innerHTML = "Valid String";

  }

  else {

document.getElementById("demo").innerHTML = "Invalid String";

  }

}

</script>


</body>

</html>

WRITE A JAVASCRIPT TO READ TWO NUMBER AND PERFORM AIRTHMETIC OPERATIONS

 <html>

<head>

<title>math</title>

   <script type= "text/javascript ">

  <!--

    function oper()

    {

        var ch=parseInt(prompt( "Enter your choice 1.Addition 2.Subtraction 3.Multiplication 4.Division "));

                switch(ch)

    {

        case 1:var v1=parseInt(prompt( "Enter the first value "));

                   var v2=parseInt(prompt( "Enter the second value "));

                   var v3=v1+v2;

                   document.writeln( "<br> "+ "Addition: "+v3);

                   break;

        case 2:var v4=parseInt(prompt( "Enter the first value "));

                   var v5=parseInt(prompt( "Enter the second value "));

                   var v6=v4-v5;

                   document.writeln( "<br> "+ "Subtraction: "+v6);

                   break;

        case 3:var v7=parseInt(prompt( "Enter the first value "));

                   var v8=parseInt(prompt( "Enter the second value "));

                   var v9=v7*v8;

                   document.writeln( "<br> "+ "Multiplication:  "+v9);

                   break;

        case 4:var v10=parseInt(prompt( "Enter the first value "));

                   var v11=parseInt(prompt( "Enter the second value "));

                   var v12=v10/v11;

                   document.writeln( "<br> "+ "Divison: "+v12);

                   break;

        case 5:var v13=parseInt(prompt( "Enter the first value "));

                   var v14=parseInt(prompt( "Enter the second value "));

                   var v15=v13%v14;

                   document.writeln( "<br> "+ "Modulus: "+v15);

                   break;

        default: document.writeln( "Enter choice correctly ");

    }

 

}

</script>

</head>

<body onLoad= "oper()"></body>

</html>

WRITE A JAVASCRIPT TO CHECK WHETHER NUMBER IS POSITIVE NEGATIVE AND ZERO



<html>

<style>


</style> 

<body>

<h3> Positive and Negative Number Checker </h3>

<br/>Enter a Number 

<input type="text" id="num_value" name="num_value" size="5">

<br><br>

<input type="submit" onclick="check_number()" value="Check Number"/>

<br><br>


<script>

 function check_number() {

var num_value= document.getElementById("num_value").value;

if (num_value >0 ) {

document.write("Number is Positive");

}

else if(num_value < 0){

document.write("Number is Negative");

}

else {

document.write("Number is zero");

}




 }

</script>

</body>

</html>

Friday, 4 March 2022

Python Program to find Area of Rectangle

 CODE

def main() : 

    print ("This program computes the area of Rectangle") 

    length = float (input ("Enter length: ") )

    width = float (input ("Enter width: ") ) 

    ans = length * width

    print ("Area of Rectangle: ", ans) 

main()

save above file as areaofrectangle.py

SCREENSHOT



Python Program to Find Area of Cylinder

 CODE

def main() : 

    print ("This program computes the area of Cylinder") 

    rd = float (input ("Enter Radius of Cylinder: ") )

    h = float (input ("Enter Height of Cylinder: ") ) 

    ans = 2 * 3.14 * rd * h + 2 * 3.14 * rd *rd

    print ("Area of Cyclinder: ", ans) 

main()

save file as areaofcylinder.py


SCREENSHOT



Python program to find Area of Circle

 CODE

def main() : 

    print ("This program computes the area of circle") 

    rd = float (input ("Enter Radius of Circle: ") ) 

    ans = 3.14 * rd *rd

    print ("Area of Circle: ", ans) 

main()

save above file as : areaofcircle.py

SCREENSHOT




Wednesday, 2 March 2022

Python Program To Draw a Line segment using Line Object

 SCREENSHOT



CODE

#Draw a line Segment using a Line object 


from graphics import *

def main():

    win = GraphWin('Draw Square',300,300)

    

    center = Point(100,100) 

    line=Line(Point(20,30),Point(180,165))

    line.draw(win)


main()

Python Program to Draw Square using Rectangle Object

 SCREENSHOT

CODE

#Draw a square using a Rectangle object 

from graphics import *

def main():

    win = GraphWin('Draw Square',300,300)

    center = Point(100,100) 

    rect = Rectangle(Point(30,30), Point(150,150))

    rect.setFill("yellow")

    rect.draw(win) 

main()



Python Program Put a Textual Label inside red circle

SCREENSHOT



CODE

 #Draw a red circle centered at point (100,100) with radius 50 and with text Red Circle

from graphics import *

def main():

    win = GraphWin('Draw Circle',300,300)

    

    center = Point(100,100) 

    circ = Circle(center, 50) 

    circ.setFill('red') 

    circ.draw(win)


    label = Text(center, "Red Circle") 

    label.draw(win)

main()


Python Program Draw a red circle centered at point (100,100) with radius 30

SCREENSHOT



CODE

 #Draw a red circle centered at point (100,100) with radius 30

from graphics import *

def main():

    win = GraphWin('Draw Circle',300,300)

    center = Point(100,100) 

    circ = Circle(center, 30) 

    circ.setFill('red') 

    circ.draw(win)

main()

An archery target consists of a central circle of yellow surrounded by concentric rings of red, blue, black and white

 CODE :

An archery target consists of a central circle of yellow surrounded by concentric rings of red, blue, black and white. Each ring has the same width, which is the same as the radius of the yellow circle. Write a program called target.py that draws this target.

o Use a list of colors and a for loop to draw the target

o Hint: objects drawn later will appear on top of objects drawn earlier

o The output of the program should look like this:

SCREENSHOT



SAVE this file as target.py

from graphics import *

def main():

    win = GraphWin('Archery Target',300,300)

    center = Point(150,150)


    w = Circle(center, 100)

    w.setFill('white')

    w.draw(win)


    bl = Circle(center, 80)

    bl.setFill('black')

    bl.draw(win)


    b = Circle(center, 60)

    b.setFill('blue')

    b.draw(win)


    r = Circle(center, 40)

    r.setFill('red')

    r.draw(win)


    y = Circle(center, 20)

    y.setFill('yellow')

    y.draw(win)


    win.getMouse() # pause for click in window

    win.close()


main()