Assignments

PYTHON EXAMPLES:-

1) WAP of percentage using user input.

per = int(input("enter your percentage "))
if per>60:
    print("First Division")

elif per>50 and per<60:
    print("Second Division")

elif per>40 and per<50:
    print("Third Division")

else:
    print("fail")

OUTPUT:-
enter your percentage 49
Third Division





2) WAP to print any no. of table using user input.

i = 8

while i<=80:

    print(i)

    i=i+8

OUTPUT:-

8

16

24

32

40

48

56

64

72

80





3) WAP of addition, multiply, subtract of any 2 nos.

a = int(input("enter any no."))

b = int(input("enter any no."))

print("Addition of two no. is ", a+b)

print("Subtraction of two no. is ", a-b)

print("Multiplication of two no. is ", a*b)

OR

print("Result of two no. is ", a+b, a-b, a*b)

OUTPUT:-

enter any no.15

enter any no.4

Addition of two no. is  19

Subtraction of two no. is  11

Multiplication of two no. is  60





4) WAP to input age from user choice and check age is greater than 18 then print

   you can vote otherwise you cannot vote.

age = int(input("Enter your age "))
if age>18:
    print("You are eligible to vote")

else:
    print("You are not eligible to vote. Your age is under 18")

OUTPUT:-
Enter your age 25
You are eligible to vote






 1) WAP to print data type of the given values

x = 1
y = 2.8
z = 1j
print(type(x))
print(type(y))
print(type(z))

output:-  
<class 'int'>
<class 'float'>
<class 'complex'>




2) WAP to input age from user and check age>18 then print  "You can vote" otherwise print " u can not vote"
age = int(input("Enter your Age "))
if age>18:
    print("You are eligible to Vote ")
    
else:
    print("You are not eligible to Vote. You are below 18")

output:- 
Enter your Age 12
You are not eligible to Vote. You are below 18




3) WAP to display 3rd position character 
a = "Hello, World!"

a = "Hello, World!"
x = a[3]
print(x)

output:-  l





4) WAP to display multiplication of this variable 
x = 5
y = 3

x = 5
y = 3
print("Multiplication of x and y is ",x*y)

output:-
Multiplication of x and y is  15




5) WAP to create list for 4 item and display all item using for loop

item = ["Cars", "Fruits", "Veggies", "Toys", "Cities"]
for i in item:
    print(i)

output:- 
Cars
Fruits
Veggies
Toys
Cities





6) WAP to create list and display the length of given list

item = ["Cars", "Fruits", "Veggies", "Toys", "Cities"]
x = len(item)
print(x)

output:-  5




7) WAP to input 3 number user choice and display greater number

a = int(input("Enter the first no."))
b = int(input("Enter the second no.")) 
c = int(input("Enter third no."))
if a > b and a > c:
    print("First no. is greater")
elif b > a and b > c:
    print("Second no. is greater")
else:
    print("Third no. is greater")
 
output:-
Enter the first no.9
Enter the second no.67
Enter third no.99
Third no. is greater




8) WAP to display sum of 1 to 5  number using while loop

i = 0         
while i<=5:
    print(i)
    i=i+1

output:-
0
1
2
3
4
5





1) WAP to display factorial number ?

n = int(input("Enter any no. "))
fact = 1
if n < 0:
   print("Factorial does not exist for negative numbers")
elif n == 0:
   print("The factorial of 0 is 1")
else:
   for i in range(1, n + 1):
       fact = fact*i
   print("The factorial of",n,"is",fact)
   
 output:-
Enter any no.5
The factorial of 5 is 120




2) WAP to display fibonacci series ?



3) WAP to display n number of table and display odd number in given table ?

ODD NO. :-
n = int(input("Enter any no."))
i = n     
while i<100:
    print(i)
    i=i+2
    
output:-
Enter any no.77
77
79
81
83
85
87
89
91
93
95
97
99





TO PRINT TABLE OF ANY NO. :-
n = int(input("Enter any no."))
i = n     
while i<100:
    print(i)
    i=i+n
    
output:-
Enter any no.12
24
36
48
60
72
84
96


4) WAP to display sum of 1 to n number ?
n = int(input("Enter any no."))
i = 1     
while i<=n:
    print(i)
    i=i+1

 output:-
Enter any no.17
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17




1/6

1)  WAP to input username and password and match 
username="admin"
password="admin123"
If match then open reg.html page in other window using - window.open()

- userpswd.html
<html>
<head>
<script language="JavaScript">
function display()
{
var u1=document.myform.uname1.value;
var u2=document.myform.uname2.value;
var p1=document.myform.pass1.value;
var p2=document.myform.pass2.value;

if(u1==u2 && p1==p2)
{
alert("Correct Information.");
window.open('jsreg.html');
return true;
}
else
{
alert("Incorrect Username and Password.");
return false;
}
}
</script>
</head>
<body>

<h2 align="center"> Login Credentials </h2>
<hr><br>
<form align="center" name="myform" onsubmit="return display()">
Username: <input type="textbox" name="uname1" required><br><br>
Confirm Username: <input type="textbox" name="uname2"><br><br><br><br>

Password: <input type="textbox" name="pass1" required><br><br>
Confirm Password: <input type="textbox" name="pass2"><br><br><br><br>

<input type="submit" value="Submit" onclick="display()">&nbsp;&nbsp;
</form>
</body>
</html>



2)  WAP to input any number from the user and display the table of given number in the following format 
Enter number : 2
2*1=2
2*2=4
2*3=6
'
'
'

- userinputtable.html
<html>
<head>
<script language="JavaScript">
function display()
{
var i;
var num=document.getElementById("num1").value;

for(i=1;i<=10;++i)
{
 document.write(num + " * " +i + " = " +num * i +"<br>");
}
}
</script>
</head>
<body>

Table of given no. is: <input type="textbox" id="num1"  required><br><br>
<input type="submit" value="Click" onclick="display()">
<body>
</html>



2/6

3)  Generate the sequence of  3 pages using auto-redirect method.
page_seq:- first.html ===>  redirect to second.html ===>  redirect to third.html

- seq_redirect_pg.html
<html>
<head>
<script language="JavaScript">
function redirect()
{
window.location="seq_page2.html";
}

setTimeout('redirect()',5000);
</script>
</head>
<body>
<h1>Welcome to Page One!</h1><hr><br>
<p> Page will automatically redirect after 5 seconds.</p><br>
OR <br><br>
<p> Click the below button.</p>
<input type="button" value="Click" onclick="redirect()">
</body>
</html>



- seq_page2.html
<html>
<head>
<script language="JavaScript">
function redirect1()
{
window.location="seq_page3.html";
}

setTimeout('redirect1()',5000);
</script>
</head>
<body>
<h1>Welcome to Page Two!</h1><hr><br>
<p>HELLO EVERYONE.</p>
<p> Page will automatically redirect after 5 seconds.</p>
<input type="button" value="Click" onclick="redirect1()">
</body>
</html>



- seq_page3.html
<html>
<body>
<h1>Welcome to Page Three!</h1><hr><br>
<h2>Hello Everybody.</h2>
<input type="button" value="Click" >
</body>
</html>



4/6

4)  Convert set into user input

- SETPRGM.html
<html>
<body>
<script>
var item = new Set();
var a=prompt("Enter string1");
var b=prompt("Enter string2");
var c=prompt("Enter string3");
var d=prompt("Enter string4");
var e=prompt("Enter string5");

item.add(a);
item.add(b);
item.add(c);
item.add(d);
item.add(e);

for(let elements of item)
{
document.write(elements +"<br>");
}

</script>
</body>
</html>

OUTPUT:-
pink
blue
orange
yellow
black



11/6

1. Implement JavaScript in marquee tag 

- marqueeJS.html
<html>
<head>
</head>
<body>
<h2>HTML Marquee Tag</h2>
<marquee behavior="alternate" scrolldelay="100">
<marquee width="300">
<h3 style="color:red; font-weight:bold; font-size:large;"> FLOATING TEXT </h3>
</marquee>
</marquee>
<h2> JavaScript </h2>
<p id="wordscroller" style="color:blue; font-weight:normal; font-size:x-large"></p>

<script language="JavaScript">
function show(pos)
{
var item="Fruits";
var output="";
var screen=document.getElementById("wordscroller");
for(var i=0;i<pos;i++)
{
output+=item.charAt(i);
}
output+=item.charAt(pos);
screen.innerHTML=output;
pos++;
if(pos!=item.length)
{
window.setTimeout(function () { scroll(pos); }, 300);
}
else
{
window.setTimeout(function () { scroll(0); }, 5000);
}
}
scroll(0);
</script>
</body>
</html>




2. Accept only uppercase letters in a textbox in JavaScript 

- uppercase.html
<html>
<head>
<script language="JavaScript">
function upperMe()
{
document.getElementById("output").value=document.getElementById("input").value.toUpperCase();
}
</script>
</head>
<body>

Enter your text: <input type="text" name="input" id="input" onchange="upperMe()"/><br><br>
Click here to see the change: <br>
<input type="button" value="Click Me"><br><br>
<input type="text" name="output" id="output" value="" />
</body>
</html>




3. Input marks of 5 subject using textbox and sum of all mark and calculate the percentage 
   if per > 60 then display First div 
   if per > 50 and < 60  display Second div 
   if per > 40 < 50  display Third div 
    otherwise Fail 

- result.html
<html>
<head>
<script type="text/javascript">
function submit_marks() {
var sub1 = parseInt(document.getElementById('s1').value);
var sub2 = parseInt(document.getElementById('s2').value);
var sub3 = parseInt(document.getElementById('s3').value);
var sub4 = parseInt(document.getElementById('s4').value);
var sub5 = parseInt(document.getElementById('s5').value);
var total = sub1+sub2+sub3+sub4+sub5;
var per  = total/5;
var res;
if (per>60) {
res = 'First Division';

else if(per>50 && per<=60){
res = 'Second Division';
}

else if(per>40 && per<=50){
res = 'Third Division';
}

else{
res = "Fail";
}
document.getElementById("demo").innerHTML = "Total Marks : "+total+"<br>Percentage : "+per+"<br>Result : "+res;
// document.write("Your Total Marks : "+total);
// document.write("<br>Your Percentage : "+per);
// document.write("<br>Your Grade : "+grade);
}
</script>
</head>
<body style="text-align:center;">
<h1>Marksheet</h1>
<hr><br>
Enter 1st subject marks: <input type="text" id="s1"><br><br>
Enter 2nd subject marks: <input type="text" id="s2"><br><br>
Enter 3rd subject marks: <input type="text" id="s3"><br><br>
Enter 4th subject marks: <input type="text" id="s4"><br><br>
Enter 5th subject marks: <input type="text" id="s5"><br><br><br><br>
<input type="submit" onclick="submit_marks()"><br><br>

<div id="demo"></div>
</body>
</html>




4. Factorial number program in Python or JavaScript

JAVASCRIPT PRGM
- factorial.html
<html>
<head>
<script language="JavaScript">
function fact()
{
var i,num,f=1;
num=document.getElementById("num").value;
for(i=1;i<=num;i++)
{
f=f*i;
}
i=i-1;
document.getElementById("res").innerHTML="Factorial of the number " +i +" is: " +f;
}
</script>
</head>
<body style="text-align:center">
<h1> Factorial of Number </h1>
<hr><br>
Enter a number: <input id="num"><br><br>
<input type="button" value="Click" onclick="fact();">
<p id="res"></p>
</body>
</html>



PYTHON ADVANCE

1) Create prgm using user input


class student:
    def __init__(self):
        self.fname=input("Enter the first name: ")
        self.lname=input("Enter the last name: ")
        
    def show(self):
        print("Hello " + self.fname + ' ' + self.lname)
s1=student()
s1.show()

Output:-
Enter the first name: tina
Enter the last name: roy
Hello tina roy


2) Using parameter inheritance

ex.1:-
class headoff:
    def display(self):
        print("This is a display function.")
        
class branchoff(headoff):
    def show(self,empname):
        self.empname=empname
        print("This is a show function. Employee name is " +self.empname)
        
d1=branchoff()
d1.show("Varun Sharma")
d1.display()

output:-
This is a show function. Employee name is Varun Sharma
This is a display function.


ex.2:-
class headoff:
    def display(self,empname):
        self.empname=empname
        print("This is a Head Office. Employee name is " +self.empname)
        
class branchoff(headoff):
    def show(self):
        print("This is a Branch Office.")
        
d1=branchoff()
d1.show()
d1.display("Varun Sharma")

output:-
This is a Branch Office.
This is a Head Office. Employee name is Varun Sharma


FILE HANDLING

1) File handling using user input

x=input("Enter any text ")
v=open("vidya.txt","w")
v.write(x)
NOTE:- Executed in PyCharm editor


DATABASE

1) Create a table from your choice and generate 15 questions queries with ans.


employee
empid                empname                 empage               empphn                empsal
               
   101                     Rohit                        25                       23456                   12,000/-
   102                     Priya                        27                       24598                    17,000/-
   103                     Tushar                      30                                                     25,000/-
   104                     Prerna                      25                       26579                    16,000/-
   105                     Mohan                     29                       29871                    20,000/-
   106                     Akash                      28                       20913                     17,000/-
   107                     Pooja                       24                       26795                     22,000/-
  



Queries:-
1) Create table query.
create table employee (empid int(10), empname varchar(30), empage int(10), empphn int(20), empsal int(10) )



2) Delete any one record from employee table.
delete from employee where id=105



3) Insert record in employee table.
insert into employee(empid, empname, empage, empphn, empsal) values(108, 'Sonam', 28, 28974, 17,000)


4) Alter table query.
alter table employee add empadd varchar(50)



5) Display all records. 
select * from employee


6) Drop query.
drop table employee


7) Truncate query. (deletes the record of table but does not delete its structure)
truncate table employee


8) Rename table query.
alter table employee rename to empdetails


9) Between query.
select * from employee where age between 20 to 35


10) and query.
select empname, empage from employee where empsal > 15,000 and empid=105


11) or query.
select * from employee where empid=103 or empid=105


12) IS NULL query.
select * from employee where empphn is null


13) Order by query.
select * from employee order by empname


14) Group by query.
select * from employee group by empsal


15) sum() query.
select sum(empsal) from employee







Comments

Popular posts from this blog

PyCharm Setup

JavaScript

Python Advance Concepts