/**/ Python & MySQL: 2023

Tuesday, May 2, 2023

PYTHON PATTERN CODING

 PATTERN CODING (PYTHON)


# 1. Pyramid pattern of numbers

rows = 10

for i in range(1, rows + 1):

    for j in range(1, i + 1):

        print(j, end='  ')

    print(' ')

OUTPUT

1   

1  2   

1  2  3   

1  2  3  4   

1  2  3  4  5   

1  2  3  4  5  6   

1  2  3  4  5  6  7   

1  2  3  4  5  6  7  8   

1  2  3  4  5  6  7  8  9   

1  2  3  4  5  6  7  8  9  10   

# 2. Reverse pattern for loop from 7 to 1

rows = 7

n = 0

for i in range(rows, 0, -1):

    n += 1

    for j in range(1, i + 1):

        print(n, end=' ')

    print('\r')

OUTPUT

1 1 1 1 1 1 1 

2 2 2 2 2 2 

3 3 3 3 3 

4 4 4 4 

5 5 5 

6 6 


# 3. Inverted Pyramid pattern with the same digit

rows = 7 #You can use any number like 8, 9, 4 etc.

num = rows

# reverse for loop

for i in range(rows, 0, -1):

    for j in range(0, i):

        print(num, end=' ')

    print("\r")

OUTPUT

7 7 7 7 7 7 7 

7 7 7 7 7 7 

7 7 7 7 7 

7 7 7 7 

7 7 7 

7 7 

# 4. Another reverse number pattern (8 to 1)

rows = 8

for i in range(0, rows + 1):

    for j in range(rows - i, 0, -1):

        print(j, end=' ')

    print()

OUTPUT

8 7 6 5 4 3 2 1 

7 6 5 4 3 2 1 

6 5 4 3 2 1 

5 4 3 2 1 

4 3 2 1 

3 2 1 

2 1 

# 5. Print other reverse number from 10 to 1

start = 1

stop = 2

current_num = stop

for row in range(2, 6):

    for col in range(start, stop):

        current_num -= 1

        print(current_num, end=' ')

    print("")

    start = stop

    stop += row

    current_num = stop

OUTPUT

3 2 

6 5 4 

10 9 8 7 

# 6. Number triangle pattern

rows = 10

for i in range(1, rows):

    num = 1

    for j in range(rows, 0, -1):

        if j > i:

            print(" ", end=' ')

        else:

            print(num, end='  ')

            num += 1

    print(" ")

OUTPUT

                 1   

                1  2   

              1  2  3   

            1  2  3  4   

          1  2  3  4  5   

        1  2  3  4  5  6   

      1  2  3  4  5  6  7   

    1  2  3  4  5  6  7  8   

  1  2  3  4  5  6  7  8  9  

# 7. Pyramid pattern of stars in python


rows = 8

for i in range(0, rows):

    for j in range(0, i + 1):

       print("*", end=' ')

    print("\r")

OUTPUT

* * 

* * * 

* * * * 

* * * * * 

* * * * * * 

* * * * * * * 

* * * * * * * * 








Friday, April 28, 2023

Python Programs

Python Programs

 # 1. Simple Addition, Subtraction, Multiplication and Division in Python by Input Method

a=int(input('Enter the First Number :'))

b=int(input('Enter the Second Number :'))

# For Addition

sum = a + b

print('Sum of two numbers : ', sum)

# For Subtraction

sub = a - b

print('Subtraction :', sub)

# For Multiplication

mul=a*b

print('Multiply a and b :', mul)

# For Division

div = a/b

print('Division :', div)

Output:

Enter the First Number :10

Enter the Second Number :5

Sum of two numbers :  15

Subtraction : 5

Multiply a and b : 50

Division : 2.0


# 2. WAP to obtain three numbers and print their sum.

x = int(input('Enter the first number :'))

y = int(input('Enter the second number :'))

z = int(input('Enter the third number :'))

sum = x+y+z

print('Sum of thre numbers are : ', sum)

Output:

Enter the first number :50

Enter the second number :40

Enter the third number :60

Sum of thre numbers are :  150

# 3. WAP to obtain length and breadth of a rectangle and calculate its area.

length = float(input('Enter the length :'))

breadth = float(input('Enter the breadth :'))

Area = length * breadth

print('Area of Rectangle :', Area)

Output:

Enter the length :5.5

Enter the breadth :7.8

Area of Rectangle : 42.9


# 4.WAP to calculate Body Mass Index (BMI) of a person.

weight = float(input('Enter the person weight in kg. : '))

height = float(input('Enter the person height in meters :'))

#Formula

BMI = weight/(height*height)

print('BMI of a person is :', BMI)

Output:

Enter the person weight in kg. : 50

Enter the person height in meters :1.8

BMI of a person is : 15.432098765432098

# 5. WAP to input a number and print its cube.

a = int(input('Enter any number :'))

cube = a*a*a

print('Cube of', a, 'is :', cube)

Output:
Enter any number :5
Cube of 5 is : 125

# 6. WAP to input two numbers and swap them.

a = int(input('Enter the first number :'))

b= int(input('Enter the second number :'))

print('Your Original number  :', a , b)

a, b = b, a

print('After swapping:', a, b)

Output:

Enter the first number :10

Enter the second number :20

Your Original number  : 10 20

After swapping: 20 10

# 6. WAP to find the average of five numbers.

a = int(input('Enter the first number :'))

b = int(input('Enter the second number :'))

c = int(input('Enter the third number :'))

d = int(input('Enter the fourth number :'))

e = int(input('Enter the fifth number :'))

avg = (a+b+c+d+e)/5

print('Average of five numbers :', avg)

Output:

Enter the first number :60

Enter the second number :65

Enter the third number :70

Enter the fourth number :80

Enter the fifth number :82

Average of five numbers : 71.4

# 7.Print Multiplication Table

def print_multiplication_table(n):

    for i in range(1, 11):

        for j in range(1, n+1):

            print(i*j, end='\t')

        print()

mul = int(input("Enter the number you want the table for :"))

print_multiplication_table(mul)

Output:

Enter the number you want the table for :10

1 2 3 4 5 6 7 8 9 10

2 4 6 8 10 12 14 16 18 20

3 6 9 12 15 18 21 24 27 30

4 8 12 16 20 24 28 32 36 40

5 10 15 20 25 30 35 40 45 50

6 12 18 24 30 36 42 48 54 60

7 14 21 28 35 42 49 56 63 70

8 16 24 32 40 48 56 64 72 80

9 18 27 36 45 54 63 72 81 90

10 20 30 40 50 60 70 80 90 100





Friday, March 17, 2023

INFORMATICS PRACTICES (C-11) 2022-23

 CLASS - XI

INFORMATICS PRACTICES (065)

SAMPLE QUESTION PAPER (2022 – 23)

Max Marks: 70                                                                                                                                                                                  Time: 3 Hrs.

General Instructions:

  1. This question paper contains 3 parts A, B and C . Each part is compulsory.
  2. Section A contains 25 questions 1 mark each.
  3. Section B contains 10 questions 2 mark each.
  4. Section C contains 5 questions 5 mark each.

SECTION - A

1

Python use a/an _______ to convert source code to object code.

a. Interpreter

b. Compiler

c. Combination of Interpreter and compiler

d. Special virtual engine

Ans

(a) Interpreter

2

Fill in the blanks:

__________ refers to the ability of a machine or a computer program to think, learn and evolve.

  1. Big Data
  2. Grid Computing
  3. Artificial Intelligence
  4. Blockchain Technology

 

Ans

Artificial Intelligence

3

Which of the following is not a component of SQL?

a.       DDL

b.      DML

c.       TCL

d.      ADL

 

Ans

ADL

4

Number of attributes in a relation is called ___________.

  1. Size
  2. degree
  3. cardinality
  4. weight

Ans

degree

5

________ technology makes users feel as if they truly are in a virtual environment.

a.       NLP

b.      AR

c.       VR

d.      ML

 

Ans

VR

6

Intelligent sensors that can convert and process quantities digital are __________ sensors.

a.  Cloud

b. AI

c. Grid

d. Smart

 

Ans

AI

7

Which of the following is not a cloud service?

a. IaaS

b. PaaS

c. SaaS

d. DaaS

Ans

DaaS

8

Extremely large sets of data are________.

a. database

b. big data

c. cloud computers

d. None of these

Ans

Big data

9

Which of these is an example of cloud storage?

  1. Google Drive
  2. Microsoft Azure
  3. iCloud
  4. All of these

Ans

All of these

10

Data items having fixed value are called_______.

  1. Identifiers
  2. Functions
  3. Keywords
  4. Literals

Ans

(d) Literals

11

Which of the following attributes can be considered as a choice for primary key?

  1. Name
  2. Street
  3. Roll No
  4. Subject

 

Ans

Roll No

 

12

What does DDL stand for?

  1. Dynamic Data Language
  2. Detailed Data Language
  3. Data Definition Language
  4. Data Derivation Language

Ans

Data Definition Language

 

13

What will the following code produce?

a=8.6

b=2

print( a / / 2 )

 

(a) 4.3

(b) 4.0

(c) 4

(d) Compilation error

 

Ans

(b) 4.0

14

A file based system is also called

a. flat file

b. serial file

c. float database

d. unrelational file

 

Ans

Flat file

15

Which amongst the following is not an example of browser?

  1. Firefo
  2. Avast
  3. Edge
  4. Chrome

Ans

Avast

16

SQL stands for _________

 

Ans

Structured Query Language

17

To remove duplicate rows from the result of a query, specify the SQL qualifier _______ in select list.

 

Ans

DISTINCT

18

A data _________ is a set of rules that define valid data.

a. Constraint

b. Data Dictionary

c. Query

d. All of these

 

Ans

Constraint

19

Function range(3) is equivalent to:

(a) [0, 1, 2]

(b) [0, 1, 2, 3]

(c) [1, 2, 3]

(d) [0, 2]

 

Ans

(a) [0, 1, 2]

20

The term ________ is used to refer to a row.

a. Attribute

b. Tuple

c. Field

d. Instance

 

Ans

Tuple

 

21

What is the purpose of the SQL AS clause?

a. The AS SQL clause is used to change the name of a column in the result set or to assign a name to a derived column

b. The AS clause is used with the JOIN clause only

c. The AS clause defines a search condition

d. All of the mentioned.

Ans

(a)

22

Which of the following is a legal expression in SQL?

a. SELECT NULL FROM SALES ;

b. SELECT NAME FROM SALES ;

c. SELECT * FROM SALES WHEN PRICE = NULL ;

d. SELECT # FROM SALES ;

Ans

b. SELECT NAME FROM SALES ;

23.

The COUNT function in sql returns the number of ________

a. Value

b. Distinct Values

c. Group By

d. Columns

Ans

a. Value

24.

To obtain all columns, use a(n) …………………… instead of listing all the column names in the select list.

a. &

b. Dollar ($)

c. Hash (#)

d. Asterisk (*)

Ans

d. Asterisk (*)

25.

Write the output of the following SQL command:

SELECT ROUND(49.88) ;

a. 49.88

b. 49.8

c. 49.0

d. 50

Ans

d. 50

26

What will be the output of following code?

 

mysql> SELECT CONCAT (CONCAT (‘Inform’, ‘atics’), ‘Practices’) ;

 

Ans

Informatics Practices

27

Write commands to display the system date.

 

Ans

SELECT CURDATE() ;

28

What is the output produced when this code executes?

a=0

for i in range(4, 8) :

          if i%2:

                a=a+i

print(a)

 

Ans

12

29

Deepika wants to remove all rows from the table BANK. But she needs to maintain the structure of the table. Which command is used to implement the same?

 

Ans

DELETE FROM BANK ;

 

30

Create table ‘Employee’ with the following structure:

 

Name of column

ID

First_Name

Last_Name

User_ID

Salary

Type

Integer

Varchar(30)

Varchar(30)

Varchar(10)

Float

 

 

Ans

Create table employee(ID int(5), First_Name varchar(30), Last_Name varchar(30), User_ID varchar(10), Salary float);

 

 

31

Write a program to print the table of a given number. The number has to enter by the user.

Ans

n=int(input(‘Enter number:’))

for i in range(1, 11):

       print(n, ‘x’, ‘i', ‘=’, (n*i))

32

Program to obtain three number and print their sum.

Ans

a = int(input("Enter first number:"))

b = int(input("Enter Second number:"))

c = int(input("Enter Third number:"))

sum = a + b + c

print("Three numbers are: ", a, b, c)

print("Sum is :", sum)

 

33

Differentiate between CHAR and VARCHAR?

Ans

 The difference b/w CHAR and VARCHAR is that of fixed length and variable length. The CHAR datatype specifies a fixed length character string. When a column is given datatype as CHAR(n), then MySQL ensures that all values stored in that column have this length i.e., n bytes. If a value is shorter than this length n then blanks are added, but the size of value remains n bytes.

VARCHAR, on the other hand, specifies a variable length string. When a column is given datatype as VARCHAR(n), then the maximum size a value in this column can have is n bytes. Each value that is stored in this column stores exactly as you specify it i.e., no blank are added if the length is shorter than maximum length n. However, if you exceed the maximum length n, then an error message is displayed.

34

Define Data types. What are the main objectives of datatypes?

Ans

Data types is defined as a set of values along with the operations that can be performed on those values. Some common data types are : Integer, float, varchar, char, string etc.

Main objectives of data types are:

·         Optimum usage of storage space.

·         Represent all possible values.

·         Improve data integrity.

 

35

What is foreign key?

Ans

A foreign key is a column or group of columns in a relational database table that provides a link between data in two tables.

36

Program to print elements of a list [‘q’, ‘w’, ‘e’, ‘r’, ‘t’, ‘y’] in separate lines along with element’s both indexes (positive and negative).

 

Ans

 L =  [‘q’, ‘w’, ‘e’, ‘r’, ‘t’, ‘y’]

length = leng(L)

for a in range(length):

     print("At indexes", a,  "and", (a-length), "element:", L[a])

37

Table “Order” is shown below. Write commands in SQL for (i) to (iv) and output for (v).

Table: Orders

ORDERID

ORDERDATE

SALESPERSON

ORDERAMOUNT

O101

2015-09-12

Ravi Kumar

34000

O102

2015—08-15

Rashmi Arora

50000

O103

2015-11-01

Ravi Kumar

55000

O104

2015-12-09

Manjeet Singh

60000

O105

2015-11-10

Rashmi Arora

50000

 

Solve the following queries:

        i.To display names of SalesPersons (without duplicates)

        ii. To list orderedID and respective OrderAmont in descending order of OrderAmount.

        iii. To count the number of orders booked by SalesPerson with names starting with ‘R’.

         iv.   To list order ids, order dates and order amounts that were booked after 1st September 2015.

        v.  SELECT ORDERID, ORDERAMOUNT FROM ORDER WHERE ORDERAMOUNT BETWEEN 50000 to 70000.             

Ans

 Check blog MySQL questions


38

Consider the following table ‘GAMES’.

Table : GAMES

GCode

GameName

Type

Number

PrizeMoney

ScheduleDate

101

Carrom Board

Indoor

2

5000

23-Jan-2004

102

Badminton

Outdoor

2

12000

12-Dec-2003

103

Table Tennis

Indoor

4

8000

14-Feb-2004

105

Chess

Indoor

2

9000

01-Jan-2004

108

Lawn Tennis

Outdoor

4

25000

10-Mar-2004

 

Write SQL commands to:

  1. To display the name of all GAMES with their GCodes.
  2. To display the content of the GAMES table in ascending order of ScheduleDate.
  3. To display sum of PrizeMoney for each type of GAMES.

 

Ans

  1. SELECT GAMENAME, GCODE FROM GAMES ;
  2. SELECT *  FROM GAMES ORDER BY SCHEDULEDATE ;
  3. SELECT SUM(PRIZEMONEY), TYPE FROM GAMES GROUP BY TYPE ;

 

39

What is cloud computing? Explain.

Ans

Cloud computing describes the act of storing managing and processing data online, as opposed to on a physical computer or network. In other words, cloud computing is the delivery of computing services such as servers, storage, database, networking, software, analytics etc. over the Internet. 

40

Write a program to create a phone dictionary for all your friends and print each key value pair in separate lines.

Ans:

PhoneDict = {"Manav" : 548545, "Sumit" : 745856, 

                  "Dipendra" : 548545, "Ravi" : 549584 }

for name in PhoneDict :

     print(name, " : ", PhoneDict[name])


CLASS XI HALF YEARLY QP WTH MS 2024

  Half Yearly Examination: 2024-25 Informatics Practices (065) Class- XI       Time Allowed: 3hrs                                     ...