You are on page 1of 45

COMPUTER PRACTICAL FILE

PYTHON

MANAS LAHORA | PRACTICALS | June 9, 2020


SNO. PROGRAMMES DATE TEACHER’S SIGN

1 To calculate BMI and print the nutritional 9/06/2020


status

2 Write a program that inputs a student’s 9/06/2020


marks in three subjects (out of 100) and
print the
percentage marks and grades

3 To display even and odd from the list of 9/06/2020


10 numbers.

4 To display even and odd from the list of 9/06/2020


10 numbers.

6 To find the largest among three integers. 9/06/2020


7 To print the roots of a quadratic equation ax2 + bx 9/06/2020
+c=0 (where a≠0).

8 To print first n Natural numbers and their sum. 10/06/2020

9 To calculate the factorial of an integer using while 10/06/2020


loop.

10 Program to check whether the given number is 10/06/2020


palindrome or not.

11 Program to check whether the given number is 10/06/2020


palindrome or not.
12 To print the Fibonacci series. i.e. 0 1 1 2 3 5 8 ...till n 12/06/2020
numbers

13 Program to add the odd numbers up to(and including) 12/06/2020


a given value N

and print the result.

14 Compute the greatest common divisor and the least 12/06/2020


common multiple of

two integers.

15 Display the sum of natural numbers between 1 to 7. 13/06/2020


Print the sum progressively i.e. after adding

each natural number, print sum so far.


16 Test if a number is equal to the sum of the cubes of its 13/06/2020
digits (Armstrong number).

17 Write a program to obtain x, y, z from the user and 13/06/2020


calculate 4x+3y3+9z+6π.

18 . Write a program to find sum of series: 13/06/2020

s=1+x+x 2+x 3+x 4...+x n

19 Write a program to input a no. and print its square if it 13/06/2020


is odd ,otherwise print its square root

20 WORKSHEET 3 15/06/2020

21 CASE STUDY 15/06/2020

22
Write a program to read a list of n
integers (positive as well as
negative). Create two new lists, 
one having all positive numbers
and the other having all negative
numbers from the given list. Print
all three lists

23 Menu driven program lists

24 Finding max and min element

24 To find if max lies in first half or second half

25 Pattern I,II,III

26 PHONE NUMBER IN PARTICULAR ORDER

27 PROJECT

28

29

30
∞ TO CALCULATE BMI AND PRINT
NUTRITIONAL STATUS
PROGRAM THAT INPUTS A STUDENTS
MARKS AND PRINTS THE PERCENTAGE
MARKS AND GRADE
TO DISPLAY EVEN AND ODD FROM LIST OF
10 NUMBERS
TO FIND LARGEST AMOUNG ALL THREE
NO.S
TO FIND LOWEST AMOUNG THREE NO.S
TO PRINT THE ROOTS OF QUADRATIC
EQUATION ax2+bx+c=0(a≠0)
TO CALCULATE THE FACTORIAL OF AN
INTEGER USING WHILE LOOP
PROGRAM TO CHECK WHETHER THE
GIVEN NO. IS PALINDROME OR NOT
TO PRINT THE FIBONACCI SERIES i.e. 0 1 1 2
3 5……… TILL N NO.S
PROGRAM TO ADD THE ODD NO.S UPTO
GIVEN VALUE N AND PRINT THE RESULTS
COMPUTE THE GREATEST COMMON
DIVISOR AND THE LEAST COMMON
MULTIPLE OF TWO INTEGERS
DISPLAY THE SUM OF NATUIRAL NO. BTW 1
TO 7.PRINT THE SUM PROGRESSIVELY
TEST IF A NO. IS ARMSTRONG’S NO.
PROGRAM TO OBTAIN x,y AND z from the
user and calculate the value of 4x4+3y3+9z+6π
Program to obtain sum of series
PROGRAM TO INPUT A NO. AND PRINT ITS
SQUARE IF IT IS ODD OTHERWISE PRINT
ITS SQUARE ROOT IF EVEN
CONVERTING TEMPERATURE FROM
CELSIUS TO FAHRENHEIT
Worksheet 3

1 The variable definition of X is creating problem X = 0281.Why.

ANS:- The error is that the decimal literal cannot start with 0.                                 

2 What would the following code do:  X= Y= 7?

ANS:- The code will assign the value 7 to both X and Y.

4 What is the difference between else clause of if-else and else clause of
Python loop? Give programming examples to elaborate. 2
ANS:- The else of an if/else signifies the start of a code block which will only
execute if the conditional (after the if results in a False value.
The else after loops signify the start of a code block which is executed only when
the loop executes fully - i.e. there is no break, or return or anything else executed
within the loop.The else after a try/except signifies the start of a code block, which
is only executed if there is no exception raised within the try block.
Eg.   x=10
        If x>12:
        print(x)
       else :
       print(x)
AND
 For i in range (1,30,1)
 If i ==3:
   break 

5 Ask the user to enter a temperature in Celsius. Write a program in Python which
should print a message based on the temperature: 3 

(i) if the temperature is less than -273.15 print that the temperature is invalid
because it is 
below
absolute
zero : 

(ii) if is exactly -273.15 ,print that the temperature is


absolute 0 . 
(ii) if the temperature is between -273.15 and 0 ,print that the temperature is
below freezing . 

(iv) if it is 0 ,print that the temperature is at the


freezing point . 

(v) if it is between 0 and 100 , print that the temperature is in the


normal range . 

(vi) if it is 100 ,print that the temperature is at the


boiling point . 

(vii) if it above 100 , print that the temperature is above the


boiling point . 

Ans : IN PROJECT FILE

6 Two objects (say a and b) when compared using ==, return True. But Python gives
False when compared using is operator. Why (i.e, a == b is True but why is a is b
False?)        2 

ANS:-  The above happens because a==b means that the value of a is equal to b.
But, it does not mean that a is equal to b as they are distinct variables of a python
program and have different memory locations .

7 Differentiate between (555/222) ** 2 and (555.0/222) **2.

ANS”: We know that the division operator always returns float value .Therefore
there is no difference in the above values as the answer will be float type even if
the operands are integers.                                              2 

8 Given three Boolean variables a, b, c as : a= False , b = True , c = False.


Evaluate the following Boolean expressions:                                                            

(a) b and c :False
(b) b or c :true
(c) not a and b : true
(d) (a and b)or not c: true
(e) not b and not (a or c) false
(f) not ((not b or not a)and c )or a :true

9 Explain the range function in context with for loop. 3


Ans : The range() function in Python is often used in for statements to define the number
of loop iterations. This built-in function creates lists containing arithmetic progressions.
The syntax of the range() function is:
range(start, stop [, step])
The start argument is the starting number. The stop argument is the last number (which
is not included). The step argument is optional and defines the difference between each
number in the sequence.
 

10 What is the difference between pass, continue and break statements? 2 

Continue statement

This statement is used to skip over the execution part of the loop on a certain
condition. After that, it transfers the control to the beginning of the loop.

Pass statement

As the name suggests pass statement simply does nothing. We use pass
statement to write empty loops. Pass is also used for empty control statements,
functions and classes.

Continue statement is opposite to that of break statement, instead of terminating


the loop, it forces to execute the next iteration of the loop.

 
PROJECT

A 9-person crime, was registered under Sections 65, 66, 66A, C and D of
the Information 
Technology Act, along with Sections 419 and 420 of the Indian Penal
Code. Under the 
complaint of this cyber fraud case in India, a company representative in the
business of trading 
and distribution of petrochemicals in India and abroad had filed the report
against the 9 accused 
of using a similar looking website to carry
on the trade. 

The accused ran a defamation campaign against the company, causing them
crores of rupees of 
loss from their customers, suppliers and
even producers. 

Source taken from https://www.cyberralegalservices.com/detail-


casestudies.php 

1 Advances in technology are the primary driver for economic growth but have
also led to a higher incidence of cyber-attacks. Comment .

ANS: 
Our society, economy, and critical infrastructures have become largely dependent on
computer networks and information technology solutions. Cyber attacks  become more
attractive and potentially more disastrous as our dependence on information technology
increases. 
 Cyber attacks are more common because cyber attacks are cheaper, convenient and
less risky than physical attacks . Cyber criminals only require a few expenses beyond a
computer and an Internet connection. They are unconstrained by geography and
distance. They are difficult to identity and prosecute due to anonymous nature of the
Internet. Given that attacks against information technology systems are very attractive, it
is expected that the number and sophistication of cyber attacks will keep growing.It is
very clear that advances in technology and many pros and cons which include cyber
crimes.
2 What are different types of
cybercrimes? 
Ans:  Common forms of cybercrime include:
 Phishing: using fake email messages to get personal information from internet
users;
 Misusing personal information (identity theft);
 Hacking: shutting down or misusing websites or computer networks;
 Spreading hate and inciting terrorism
 Cyberstalking: online harassment where the user is subjected to a plethora of
online messages and emails.
 Identity theft:when a criminal gains access to a user’s personal information to
steal funds, access confidential information, or participate in tax or health
insurance fraud

3 How can someone steal online


identity?
   ANS:   Stealing someone online identity is known as identity theft.This cybercrime
occurs when a criminal gains access to a user’s personal information to steal funds,
access confidential information, or participate in tax or health insurance fraud. They can
also open a phone/internet account in your name, use your name to plan a criminal
activity and claim government benefits in your name. They may do this by finding out
user’s passwords through hacking, retrieving personal information from social media, or
sending phishing emails.

4.  Why it is advisable to check the security of the website before you enter personal and
credit 
card information while shopping? 
Your credit card isn't safe anywhere, especially the internet. When you're shopping
online with your credit card, it's important to follow some guidelines to avoid credit card
fraud and identity theft. It is advisable to check the security of the website before you
enter personal and credit 
card information while shopping because  if you don't so you could be a victim of
cybercrime.
Checking the websites security will assure us that no one can access our card details
and that we have a safe transaction online.We should avoid clicking on email links,
particularly in unsolicited emails, because these links could take you to a fake website
that's set up for the sole purpose of stealing your credit card information.  

5.  What are the usage rules while using social media?
Ans:-  RULES TO USE WHILE USING SOCIAL MEDIA:-
1. Use a strong password.  The longer it is, the more secure it will be.
2. Use a different password for each of your social media accounts.
3. Set up your security answers.  This option is available for most social media
sites.
4. If you have social media apps on your phone, be sure to password protect your
device.
5. Be selective with friend requests. If you don’t know the person, don’t accept their
request.  It could be a fake account.

6.  What is "pretexting"? 


ANS :Pretexting is a form of social engineering in which an individual lies to obtain
privileged data. A pretext is a false motive.
Pretexting often involves a scam where the liar pretends to need information in order to
confirm the identity of the person he is talking to. After establishing trust with the
targeted individual, the pretexter might ask a series of questions designed to gather key
individual identifiers such as confirmation of the individual's social security number,
mother's maiden name, place or date of birth or account number.
∞ LIST MANIPULATION

Write a program to read a list of n integers


(positive as well as negative). Create two new
lists,one having all positive numbers and the
other having all negative numbers from the
given list. Print all three lists.
Source code:
Output:
Program 4-1 Write a program to allow user to
perform any those list operation given in a
menu. The menu is:
1. Append an element
2. Insert an element
3. Append a list to the given list
4. Modify an existing element
5. Delete an existing element from its position
6. Delete an existing element with a given value
7. Sort the list in the ascending order
8. Sort the list in descending order
9. Display the list.
Source code:
OUTPUT:
PROGRAMME TO FIND MINIMUM AND
MAXIMUM MARKS OF A STUDENT

SOURCE CODE:

OUTPUT
TUPLE FUNCTIONS:
TO FIND THE POSITION OF THE MINIMUM
AND MAXIMUM ELEMENT
SOURCE CODE

OUTPUT:
TO CHECK IF THE ELEMENT WITH MAXIMUM
VALUE LIES IN THE FIRST HALF OF SERIES
OR THE SECOND HALF
SOURCE CODE

OUTPUT

PATTERN TYPE I
SOURCE CODE:

OUTPUT:

PATTERN QUESTION TYPE II


SOURCE CODE:

OUTPUT:

PATTERN QUESTION TYPE II


SOURCE CODE:

OUTPUT:
To ask user for valid phone no. of format aaa-
bbb-ccc
Source code:
OUTPUT:
PROJECT
Write a menu driven program having the following options
(use functions and appropriate data types):
Open a savings bank account
• Deposit money
• Withdraw money

 Show the balance amount


Output:

You might also like