Q1. a) What does a cross platform language mean?
Cross platform language means that the language can run on different platforms like Windows, Linux, Unix, Macintosh, smartphones, etc.
b) What is a keyword?
A keyword is a special word that has a special meaning or purpose. It is a reserved word. Example: if, else, etc.
c) Differentiate between an interpreter and a compiler.
An interpreter converts a high-level language program into machine language by converting and executing it line by line. A compiler converts the entire high level language program in one go.
d) Out of the following, find those identifiers which cannot be used for naming a variable in a python program:
Myfile, FILE14, _BRS, Z2K89, break, bt-23, 29RSTS, assert.
break, bt-23, 29RSTS, assert are the identifiers that cannot be used for naming variables in a python program.
e) Write the escape sequence for:
(i) Horizontal tab (TAB)
(ii) Newline character
(iv) ASCII Bell (BELL)
f) What are comments? How to write single line comments in Python?
Comments are the additional readable information to clarify the source code. Single line comments begin with # symbol. Example:
#this is a comment
Q2. a) (i) (24.6)8 = (?)10
(ii) (266)10 = (?)8
b) (i) (1010100.011)2 = (?)10
(ii) (106.2)10 = (?)2
c) (i) (72905)10 = (?)16
(ii) (EB4A)16 = (?)10
d) (i) (11.01)2 + (101.11)2 = (?)2
(ii) (01010111)2 + (00110101)2 = (?)2
e) Represent (-25)10 in 8-bit signed binary form and 2’s complement form.
Signed binary form: 100110012
2’s complement form: 111001112
Q3. a) Draw a flowchart to find the maximum among three numbers.
b) Find the output of the following code fragment:
a = 49 b = math.sqrt(a) a += b print(a) print(b)
c) Write the corresponding python expressions for the following mathematical expressions:
(i) 5 – ye3y + 4y
5 – y * e ** (3 * y) + 4 * y
(ii) √(b2 – 4ac) / (2a)
math.sqrt((b * b – 4 * a * c) / (2 * a))
d) Find the output of the following code fragment:
x, y = 2, 6 x, y = x + y, y + 0 x, y = x + 0, x - y x, y = x - y, y + 0 print(x, y)
e) How many ways are there in python to represent integer literals? Write their names.
Python allows 3 types of integer literals: decimal, octal, and hexadecimal.
Q4. a) Write a program to swap two numbers without using a third variable.
a = int(input('First number: ')) b = int(input('Second number: ')) print('Initially a =', a, 'b =', b) a, b = b, a print('Now a =', a, 'b =', b)
b) Write a program to check whether a number is a buzz number or not. A buzz number is a number which is either divisible by 7 or its last digit is 7.
n = int(input("Enter the number: ")) if n % 7 == 0 or n % 10 == 7: print(n, "is a buzz number.") else: print(n, "is not a buzz number.")
c) Write a program to check whether a number is positive, negative or zero.
n = int(input("Enter the number: ")) if n > 0: print(n, "is positive.") elif n == 0: print(n, "is zero.") else: print(n, "is negative.")
d) Write a program to enter the marks in 5 subjects for a student. Find the total marks, average marks and grade. Calculate the grade as per the following criteria:
>= 80 A
60 to 79 B
50 to 59 C
< 50 D
math = int(input("Enter marks in math: ")) computer = int(input("Enter marks in computer: ")) physics = int(input("Enter marks in physics: ")) chemistry = int(input("Enter marks in chemistry: ")) biology = int(input("Enter marks in biology: ")) total = math + computer + physics + chemistry + biology average = total / 5 if average >= 80: print("Grade A") elif average >= 60: print("Grade B") elif average >= 50: print("Grade C") else: print("Grade D")
e) Write a program to enter the measure of three sides and check whether a triangle can be formed or not.
a = float(input('First side: ')) b = float(input('Second side: ')) c = float(input('Third side: ')) if a + b > c and b + c > a and c + a > b: print('Triangle can be formed.') else: print('Triangle cannot be formed.')