0% found this document useful (0 votes)
9 views16 pages

CS project

Uploaded by

mrzerogaming8
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views16 pages

CS project

Uploaded by

mrzerogaming8
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 16

BEDI

INTERN
ATIONA
Summer Project
L
Subject: Comp. Sci.
SCHOOL
Class: XI-A
Student Name: Shikhar
Kumar
Submitted To: Mrs. Amoli
Chakraborty

Date Of Submission: 03/07/2023


Questions:-

1. Who developed Python? State some advantages


and some disadvantages of Python.
2. Write a short note on tokens.
3. Differentiate between identifiers and keywords.
4. Write a program to input two numbers and print
their difference.
5. Evaluate the following expression:
A = 3*4//5+5//7+8-2+4//2
6. Write a Python program to input a number and
print its first five multiples.
7. Define type casting with an example.
8. Write a Python program to find the perimeter of
a rectangle.
9. What will be the value of the following if a=2?
(i) (12/+a)%3
(ii) (21*+a)%9
(iii) (21//+a)%3
10. Write a program that inputs three numbers
from the user and print the largest number.
Answers:-
1. The programming language Python was developed by
Dutch Programmer Guido Von Rossum. Some advantages
are:-
 Easy to use.
 Increased productivity.
 Flexibility.
 Extensive Library.
 Supportive community.
Some disadvantages are:-
 It is slower than other languages.
 Memory consumption.
 Mobile development.
 Runtime errors.
 Too simple causing difficulty with other
languages.

2. Tokens:-
A token is the smallest individual unit in a python program.
All statements and instructions in a program are built with
tokens. The various tokens in python are :
1. Keywords: Keywords are words that have some special
meaning or significance in a programming language.
They can’t be used as variable names, function names,
or any other random purpose. They are used for their
special features. In Python we have 33 keywords some
of them are: try, False, True, class, break, continue, and,
as, assert, while, for, in, raise, except, or, not, if, elif,
print, import, etc.

2. Identifiers: Identifiers are the names given to any


variable, function, class, list, methods, etc. for their
identification. Python is a case-sensitive language and it
has some rules and regulations to name an identifier.
Here are some rules to name an identifier:-
 As stated above, Python is case-sensitive. So case
matters in naming identifiers. And hence egg and Egg
are two different identifiers.
 Identifier starts with a capital letter (A-Z) , a small
letter (a-z) or an underscore( _ ). It can’t start with
any other character.
 Except for letters and underscore, digits can also be a
part of identifier but can’t be the first character of it.
 Any other special characters or whitespaces are
strictly prohibited in an identifier.
 An identifier can’t be a keyword.

3. Literals or Values: Literals are the fixed values or data


items used in a source code. Python supports different types
of literals such as:

(i) String Literals: The text written in single, double,


or triple quotes represents the string literals in
Python. For example: “Computer Science”,
‘zero’, etc. We can also use triple quotes to
write multi-line strings.

(ii) Character Literals: Character literal is also a


string literal type in which the character is
enclosed in single or double-quotes.

(iii) Numeric Literals: These are the literals written in


form of numbers. Python supports the following
numerical literals:
a. Integer Literal: It includes both positive and
negative numbers along with 0. It doesn’t
include fractional parts. It can also include
binary, decimal, octal, hexadecimal literal.
b. Float Literal: It includes both positive and
negative real numbers. It also includes fractional
parts.
c. Complex Literal: It includes a+bi numeral, here a
represents the real part and b represents the
complex part.
d. Boolean Literals: Boolean literals have only two
values in Python. These are True and False.
e. Special Literals: Python has a special literal
‘None’. It is used to denote nothing, no values,
or the absence of value.
f. Literals Collections: Literals collections in python
includes list, tuple, dictionary, and sets.
 List: It is a list of elements represented in square
brackets with commas in between. These
variables can be of any data type and can be
changed as well.
 Tuple: It is also a list of comma-separated
elements or values in round brackets. The values
can be of any data type but can’t be changed.
 Dictionary: It is the unordered set of key-value
pairs.
 Set: It is the unordered collection of elements in
curly braces ‘{}’.

4. Operators: These are the tokens responsible to perform an


operation in an expression. The variables on which operation
is applied are called operands. Operators can be unary or
binary. Unary operators are the ones acting on a single
operand like complement operator, etc. While binary
operators need two operands to operate.

5. Punctuators: These are the symbols that used in Python to


organize the structures, statements, and expressions. Some
of the Punctuators are: [ ] { } ( ) @ -= += *= //= **== = ,
etc.

3. Identifiers and keywords are both important components


of programming languages, but they serve different purposes
and have distinct characteristics. Here's how they can be
differentiated:

Identifiers:
 Identifiers are user-defined names used to represent
variables, functions, classes, objects, and other entities
in a program.
 They are created by programmers to provide a unique
and meaningful name to elements within their code.
 Identifiers must follow certain rules and conventions set
by the programming language, such as starting with a
letter or underscore, and consisting of letters, digits, or
underscores.
 Examples of identifiers: variableName, functionName,
ClassName.
Keywords:

 Keywords are reserved words in a programming


language that have predefined meanings and serve
specific purposes within the language.
 They are part of the language's syntax and cannot be
used as identifiers.
 Keywords are used to define control structures, data
types, access modifiers, loops, conditionals, and other
language-specific functionalities.
 Keywords are typically written in lowercase, but their
casing may vary depending on the programming
language.
 Examples of keywords: if, else, while, for, int, float, class,
return.
In summary, identifiers are user-defined names used to
represent programming elements, while keywords are
predefined reserved words that have specific meanings
within the programming language. Identifiers are flexible and
can be created by programmers, whereas keywords are fixed
and cannot be used as identifiers.

4. The program for taking two no. and printing their sum is:
A=float(input('Enter any real number:'))
B=float(input('Enter any other real number:'))
if A>B:
n=A-B
else:
n=B-A
x=int(n)
if n-x==0:
print('The difference between the given no.s is:', x)
else:
print('The difference between the given no.s is:', n)
Code:-

Output:-

5. A=3*4//5+5//7+8-2+4//2
=12//5+5//7+8-2+4//2
=2+0+8-2+2
=10
6. The program to give the first 5 multiples of a no. is:
n=int(input('Enter any- number:'))
print('The first 5 multiples are:', n, 2*n, 3*n, 4*n, 5*n)
Code-

Output-

7.
Type casting, also known as type conversion, is the process of
converting a value from one data type to another. It allows
you to change the interpretation or representation of data in
your program.
In Python, you can perform type casting using various built-in
functions. Here are a few examples:
Integer to Float Conversion:
integer_value = 5
float_value = float(integer_value)
print(float_value) # Output: 5.0
In this example, the float() function is used to convert an
integer value to a float value. The variable integer_value is
cast to a float using the float() function, resulting in the value
5.0.

Float to Integer Conversion:


float_value = 3.7
integer_value = int(float_value)
print(integer_value) # Output: 3
Here, the int() function is used to convert a float value to an
integer value. The variable float_value is cast to an integer
using the int() function, resulting in the value 3. The decimal
portion is truncated, effectively removing it.
String to Integer Conversion:
string_value = "10"
integer_value = int(string_value)
print(integer_value) # Output: 10
In this example, the int() function is used to convert a string
representation of an integer to an actual integer value. The
variable string_value holds the string "10", and by using
int(string_value), it is cast to an integer with the value 10.
These are just a few examples of type casting in Python.
There are other functions available, such as str(), bool(), and
list(), that allow you to convert values to string, boolean, or
list types, respectively.

8.
The program for the perimeter of a rectangle is:
l=float(input("Enter length of the rectangle:"))
b=float(input("Enter breadth of the rectangle:"))
P=2*(l+b)
p=int(P)
if P-p==0:
print("Perimeter of the rectangle is:", p, 'sq. cm.')
else:
print("Perimeter of the rectangle is:", P, 'sq. cm.')
Code-

Output-
9.
(i) (12/+a)%3 = 0
(ii) (21*+a)%9 = 6
(iii) (21//+a)%3 = 1

10. The program to detect and display the greatest out of 3


nos. is:
A=float(input('Enter any real number:'))
B=float(input('Enter any real number:'))
C=float(input('Enter any real number:'))
a=int(A)
b=int(B)
c=int(C)
if A>B and A>C:
if A-a==0:
print('The greatest no. is', a)
else:
print('The greatest no. is', A)
if B>A and B>C:
if B-b==0:
print('The greatest no. is', b)
else:
print('The greatest no. is', B)
if C>A and C>B:
if C-c==0:
print('The greatest no. is', c)
else:
print('The greatest no. is', C

Code-
Output-

You might also like