Test 1 Practice Questions - Programming

Summary

This document contains practice questions for a programming exam covering various topics, including algorithms, data types, functions, conditional statements, and iterations. The questions involve writing Python code to solve scenarios, such as calculating shopping cart totals, or analyzing grades.

Full Transcript

Section A: Short Answer Questions (40 marks) 1\. Define an algorithm. Why is it important in programming? (5 marks) 2\. What are the key differences between syntax and semantics in programming? Provide examples. (5 marks) 3\. Explain the purpose of variables in programming. How do they differ fro...

Section A: Short Answer Questions (40 marks) 1\. Define an algorithm. Why is it important in programming? (5 marks) 2\. What are the key differences between syntax and semantics in programming? Provide examples. (5 marks) 3\. Explain the purpose of variables in programming. How do they differ from constants? (5 marks) 4\. Describe three Python data types. Provide an example of how each can be used in a program. (10 marks) 5\. What are conditional statements? Write a simple Python example that demonstrates their use. (5 marks) 6\. Discuss the role of functions in programming. How do they contribute to code organization? (5 marks) 4\. Explain the use of iteration statements in Python. Provide an example of a loop that iterates over a list. (5 marks) \-\-- Section B: Scenario-Based Questions (60 marks) 7\. Scenario 1: You are tasked with creating a program that calculates the total cost of items in a shopping cart. a\. Describe the steps you would take to implement this program, including how you would handle user input for item prices and quantities. (15 marks) b\. Write a Python function that takes a list of item prices and a list of corresponding quantities, and returns the total cost. (10 marks) c\. Discuss how you would ensure that the program can handle invalid inputs gracefully, such as non-numeric values. (10 marks) 8\. Scenario 2: You need to develop a program that analyzes student grades to determine the average grade and the number of students who passed (defined as a grade of 60 or above). a\. Outline the steps you would take to implement this program. (10 marks) b\. Write a Python program snippet that calculates and prints the average grade and the number of students who passed, given a list of grades. (10 marks) c\. How would you modify your program to allow the user to input grades until they choose to stop? (5 marks) Total: 100 marks

Use Quizgecko on...
Browser
Browser