0% found this document useful (0 votes)
6 views2 pages

Python Logic & Programming Mock Exam

This document is a mock exam for Computer Science focusing on Python and logic, consisting of various sections including short questions, Python fundamentals, data handling, Python modules, flow of control, and string manipulation. It covers topics such as data representation, Boolean logic, problem-solving techniques, and practical programming tasks. The exam is structured to assess knowledge and skills with a total of 70 marks available over a 3-hour period.

Uploaded by

workabhi537
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)
6 views2 pages

Python Logic & Programming Mock Exam

This document is a mock exam for Computer Science focusing on Python and logic, consisting of various sections including short questions, Python fundamentals, data handling, Python modules, flow of control, and string manipulation. It covers topics such as data representation, Boolean logic, problem-solving techniques, and practical programming tasks. The exam is structured to assess knowledge and skills with a total of 70 marks available over a 3-hour period.

Uploaded by

workabhi537
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

Mock Exam – Computer Science (Python & Logic)

Maximum Marks: 70
Time: 3 Hours

Section A – Short Questions


Q1. Computer System (2 Marks)
a) Define hardware and software. (1M)
b) Give one example each of system software and application software. (1M)

Q2. Data Representation (4 Marks)


a) Convert (23)₁₀ to binary. (1M)
b) Convert (C4)₁₆ to binary. (1M)
c) Convert (56)₁₀ to binary. (2M)

Q3. Boolean Logic (3 Marks)


a) State the Boolean identity law A + 0 = A. (1M)
b) Construct truth table for A + B. (2M)

Q4. Problem Solving (3 Marks)


a) Write pseudo code to check whether a number is even or odd. (2M)
b) Draw flowchart to find sum of first 5 natural numbers. (1M)

Q5. Getting Started with Python (1 Mark)


a) Write the correct syntax to print “Hello Python” in Python. (1M)

Section B – Python Fundamentals (8 Marks)


Q6. Differentiate between mutable and immutable objects with examples. (2M)
Q7. Explain Python tokens with suitable examples. (3M)
Q8. Write a program to calculate simple interest. (3M)

Section C – Data Handling (7 Marks)


Q9. Write a program to input 5 numbers in a list and print their average. (3M)
Q10. Write a program to count number of even and odd elements in a list. (4M)
Section D – Python Modules (6 Marks)
Q11. Name two functions from the math module with examples. (2M)
Q12. Explain the use of random module with examples of randint() and choice(). (4M)

Section E – Flow of Control (17 Marks)


Q13. Write a Python code using if to check whether a number is positive or negative. (2M)
Q14. Write a Python program to find greatest among three numbers. (3M)
Q15. Write a program using for loop to compute sum of first 10 natural numbers. (4M)
Q16. Write a program to print Fibonacci series up to n terms. (4M)
Q17. A shop gives discount:
- Bill < 1000 → 5%
- 1000–5000 → 10%
- >5000 → 15%
Write Python program to display net payable amount. (4M)

Section F – String Manipulation (19 Marks)


Q18. Predict output: print("Python"*2) (2M)
Q19. Write Python code to check if a string is palindrome. (3M)
Q20. Given S="HELLO WORLD", write outputs of:
- S[:5]
- S[6:]
- S[::-1] (4M)
Q21. Write a menu-driven program to perform on a string:
- Reverse
- Count vowels
- Convert to uppercase (5M)
Q22. Write a program to count number of vowels, consonants, digits and spaces in a string.
(5M)

Common questions

Powered by AI

`randint()` is beneficial in scenarios requiring random integer values within a specified range, such as simulating dice rolls in a game. `choice()`, which selects a random element from a sequence, is useful for generating random choices from predefined options, like randomly assigning tasks to a list of employees. These functions enhance applications involving randomness, aiding in simulations, games, and random sampling .

The flow of control using a loop, such as a `for` loop, allows the program to iteratively execute statements to incrementally calculate the sum of numbers. In this scenario, a `for` loop iterates over a range of numbers from 1 to 10, continuously adding each number to an accumulator variable initialized to zero. This method ensures efficient, concise code that avoids redundancy and manual addition, significantly simplifying calculations and reducing the risk of errors .

When implementing a Fibonacci generator, consider the iterative approach for optimal time complexity (O(n)), which is more efficient than recursive methods that can lead to exponential time complexity due to repeated calculations. Efficient resource utilization requires using variables to store previous results, limiting memory use compared to recursive stack depth issues. Selecting an appropriate algorithm prevents bottlenecks in performance and enhances program efficiency, essential in resource-constrained environments .

Writing a menu-driven program poses challenges, such as ensuring user input is correctly processed and managing string operations like reversing, vowel counting, or case conversion without errors. Address these by implementing simple and clear user interfaces, validating inputs to avoid unexpected behavior, and using efficient string methods. Proper error handling and feedback mechanisms help guide users and prevent misuse or misinterpretation of the program's outcomes .

The `sqrt()` function from the math module is used to compute the square root of a number, while `factorial()` computes the factorial of an integer. These functions are important for mathematical calculations. Example usage: `import math; result = math.sqrt(16)` calculates the square root as 4.0. Similarly, `factorial_result = math.factorial(5)` computes 5! = 120. These functionalities simplify complex mathematical operations in programming .

Truth tables provide a systematic way to explore the values that logical expressions can take, by enumerating all possible input combinations. Constructing a truth table like for `A + B` enables a thorough understanding of how each operand affects the output, reinforcing comprehension of operation principles and facilitating proof of identities through visual representation. This method supports correctness verification in complex logical designs and improves problem-solving accuracy in logic circuits and programming .

A program using `if`, `elif`, and `else` statements checks the bill amount and applies corresponding discounts: 5% for bills under ₤1000, 10% for amounts from ₤1000-5000, and 15% for over ₤5000. This method dynamically adjusts the final amount, allowing scalability and adaptability. Using conditional logic avoids hardcoded values, improving flexibility and maintainability, making it easier to update policies without changing extensive code segments, essential for businesses for agile practice adjustments .

Boolean identity laws, such as A + 0 = A and A . 1 = A, are foundational rules that simplify logical expressions by removing unnecessary redundancy. They form the basis for constructing and optimizing more complex logical operations in circuits and algorithms by reducing expressions to their simplest forms. This reduction improves computational efficiency and is pivotal in both hardware design and software logic optimization .

The pseudo code for determining if a number is even or odd provides a structured, language-agnostic framework that guides the development of an algorithm to solve the problem. By evaluating the remainder when dividing the number by 2, it uses simple arithmetic operations for an efficient determination. This approach can be easily translated into any programming language, facilitating implementation and aiding in understanding the logic without needing specific syntax .

Mutable objects in Python, like lists and dictionaries, can be modified after they are created, meaning you can change their content without changing their identity. Immutable objects, such as tuples and strings, cannot be altered once created. This distinction is significant because immutability ensures the integrity of data, making it easier to track changes and debug programs. In multi-threaded programs, immutable objects are particularly useful as they avoid issues related to data changes by multiple threads.

You might also like