100% found this document useful (1 vote)
15 views2 pages

Python Programming Exam Guide

The document outlines an examination for a Python Programming course at Scope Global Skills University, consisting of three sections: Objective Type, Short Answer Type, and Long Answer Type. It includes various questions on Python syntax, data types, control structures, and functions. The total marks for the exam are 50, with specific marks allocated to each section.

Uploaded by

idikaco158
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
15 views2 pages

Python Programming Exam Guide

The document outlines an examination for a Python Programming course at Scope Global Skills University, consisting of three sections: Objective Type, Short Answer Type, and Long Answer Type. It includes various questions on Python syntax, data types, control structures, and functions. The total marks for the exam are 50, with specific marks allocated to each section.

Uploaded by

idikaco158
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Scope Global Skills University, BCA

Subject: Python Programming


Maximum Marks: 50 Time: 2 Hours

SECTION 'A' — Objective Type (8 Marks)


(8 Questions × 1 Mark each)
Q1. Which of the following is a valid variable name in Python? (c) my_name
Q2. Correct syntax to print 'Hello World'? (c) print('Hello World')
Q3. Which is a mutable data type? (b) List
Q4. Symbol for comment? (c) #
Q5. Output of a=5;b=2;print(a**b)? (b) 25
Q6. Comparison operator? (b) ==
Q7. Keyword to define a function? (c) def
Q8. Output of x='Hello';print(x[1])? (b) e

SECTION 'B' — Short Answer Type (12 Marks)


(Any 4 Questions × 3 Marks each)

Q1. Difference between '=' and '==' operators:


= assigns value, == compares values.
Example: x=5; print(x==5) → True

Q2. Data Types: int, float, str examples.

Q3. while vs for loop: while (unknown iterations), for (known range).

Q4. Indentation defines code blocks, comments start with #.

Q5. Logical Operators: and, or, not


Example: 5>2 and 3>1 → True

SECTION 'C' — Long Answer Type (30 Marks)


(Any 5 Questions × 6 Marks each)

Q1. Even or Odd:


num=int(input("Enter a number: "))
if num%2==0: print("Even")
else: print("Odd")

Q2. Table of 5 (while loop):


i=1
while i<=10:
print("5 x",i,"=",5*i)
i+=1
Q3. Largest of three:
if a>b and a>c: print(a)
elif b>c: print(b)
else: print(c)

Q4. 1–10 using for loop:


for i in range(1,11): print(i)

Q5. Factorial Function:


def factorial(n):
fact=1
for i in range(1,n+1):
fact*=i
return fact

Q6. Sum & Product:


a=int(input("a: "))
b=int(input("b: "))
print("Sum:",a+b)
print("Product:",a*b)

Common questions

Powered by AI

To determine if a number is even or odd in Python, the modulus operator '%' is utilized to check the remainder of the number when divided by 2. If the remainder is zero, the number is even; otherwise, it is odd. The logic involves inputting the number, employing the condition 'if num % 2 == 0', and printing 'Even' if true, otherwise printing 'Odd'. This logic is effectively captured as follows: num=int(input('Enter a number: ')); if num%2==0: print('Even'); else: print('Odd').

Comments in Python, denoted by the symbol #, are crucial as they help in making the code more readable by providing explanations, context, or notes for future reference. This assists not only the original coder but anyone else who might work with the code to understand the logic and functionality without executing it. Furthermore, comments enhance code maintenance by allowing developers to easily navigate and update code structures when necessary .

Functions in Python are beneficial for code reusability and modularity as they allow for the encapsulation of repetitive tasks in a single callable unit. For instance, in a data analysis script, calculating the average value of a dataset is a common requirement. By defining a function, say 'average(data)', this operation can be reused throughout the script without rewriting the logic each time it's needed. This improves code maintainability and readability, as the function can be adjusted independently if necessary, with all points of call automatically adopting the updated logic. Implementation typically involves defining the function with 'def', parameterizing inputs, and completing with a return statement to output results .

Logical operators such as 'and', 'or', and 'not' are used extensively in Python to build complex conditional statements that evaluate multiple conditions simultaneously. These applications are crucial in decision-making structures where multiple criteria must be satisfied or negated. For example, they can be used in authorization checks (e.g., verifying multiple user permissions), filtering data sets based on compound conditions, or in game development for level advancement logic. By effectively combining conditions, logical operators simplify the implementation of complex logic that would otherwise require nested if statements .

A while loop is preferred over a for loop when the number of iterations is not known prior to entering the loop, allowing for execution based on a condition rather than a predetermined range. This choice can impact program efficiency both positively and negatively. In cases where loop iterations depend on runtime conditions or user input, while loops provide necessary flexibility and control flow. However, they may also lead to inefficiency if conditions are not well-defined, potentially causing infinite loops if a breaking condition is never met .

Indentation in Python is used to define the level of nesting of code blocks, such as loops, conditionals, and functions. Unlike many other programming languages that utilize braces to define code scope, Python relies on indentation levels for this purpose. This strict requirement enforces a clearer and more consistent visual structure, which reduces the likelihood of errors related to mismatched braces and enhances code readability. Improper indentation will cause the Python interpreter to throw an IndentationError, demonstrating its critical role in code execution .

In Python, mutable data types like lists allow for in-place modifications without changing their identity, facilitating operations like element updates, deletions, or additions. Conversely, immutable data types such as tuples and strings cannot be altered after their creation, requiring the creation of new instances for any modification which may increase memory usage and processing time. Choosing between mutable and immutable types affects not just performance and efficiency but also the design considerations for algorithms, as immutability provides a safety mechanism in concurrent programming scenarios by preventing unintended side effects .

Understanding comparison operators such as '==', '!=', '<', '<=', '>', '>=' is crucial in Python because they form the basis of logical decision-making. These operators allow programmers to perform tests that result in Boolean values, which can be used in conditional statements and loops, directly influencing the flow of a program. Proper use of comparison operators ensures accurate program responses to varying input conditions and can prevent logical errors that might otherwise lead to incorrect or unexpected outcomes in complex programming tasks .

The '=' operator is used for assignment in Python, meaning it assigns the value on its right to the variable on its left. Conversely, '==' is a comparison operator that checks if the values on both sides are equal. In programming tasks, '=' is used to initialize variables or update their values, while '==' is crucial in conditional statements where evaluation of equality determines the flow of execution. Misuse of these operators can lead to bugs, such as using '=' instead of '==' in a conditional expression intended to check equality rather than to assign .

Python's rules for variable name validity require that identifiers begin with a letter (a-z, A-Z) or an underscore (_), followed by letters, digits, or underscores. Keywords of Python should not be used as variable names. Variable names are case-sensitive, meaning 'var', 'Var' and 'VAR' would all be considered separate identifiers. These rules ensure clarity and prevent errors in code recognition by differentiating between language-defined terms and user-defined identifiers .

You might also like