(IX) Ch-7 Python Programming

Ch-7 Python Programming 1. Answer these questions. a) Explain programming languages with its types. Ans: A programming language is a formal set of instructions used to communicate with a computer and create software. (1) Low-Level Languages: These are close to machine hardware. (i) Machine Language: Binary code (0s and 1s) that the CPU understands directly. (ii) Assembly Language: Uses "mnemonics" (like MOV or ADD) instead of binary. Requires an Assembler. (2) High-Level Languages: Designed to be human-readable and use English-like words (e.g., Python, Java, C++). They must be translated into machine code to run. b) Differentiate between compiler and interpreter. Ans:
CompilerInterpreter
Scans the entire program and translates it as a whole.Translates and executes the program line-by-line.
Faster execution but slower initial translation.Slower execution but starts immediately.
Debugging,Shows all errors at once after scanning."Stops at the first error, making it easier to debug."
Generates an intermediate object code (like an .exe).Does not generate intermediate object code.
c) Define algorithm and flowchart. Ans: Algorithm: A step-by-step logical procedure or set of rules to be followed in calculations or problem-solving. Flowchart: A visual or graphical representation of an algorithm using standard symbols. d) Write five symbols with their functions of flowchart. Ans: 1. Oval (Terminal): Indicates the Start or End of the process. 2. Parallelogram (Input/Output): Represents data being entered into or displayed from the system. 3. Rectangle (Process): Represents a calculation or a specific action. 4. Diamond (Decision): Used for "Yes/No" or "True/False" questions that branch the flow. 5. Arrows (Flow Lines): Show the direction of the process flow. e) Create an algorithm to find whether the given number is odd or even. Also make flowchart from the algorithm. Ans: Algorithm:Start.Input a number ($N$).Divide $N$ by 2.If the remainder is 0, the number is Even.Else, the number is Odd.Display the result.Stop.Flowchart: f) Explain Python programming with its features. Ans: g) Describe the use of input/output statements in Python. Ans: h) Define formatted string literals. Demonstrate its use in a simple program where the user inputs their name and the output is displayed “Hello (user_ name)! Welcome to our program”. Ans: i) Explain the data types with examples. Ans: j) Describe typecasting with its types. Ans: k) List the types of operators. Explain any one of them in detail with examples. Ans: l) Explain a conditional statement with an example. Ans: m) Define iteration. Differentiate for and while loop. Ans: n) Differentiate between list and dictionary. Ans: o) Given is the list elements. Ans: [Kathmandu, Biratnagar, Nepalgunj, Pokhara, Butwal, Birendranagar, Mahendranagar, Balefi ] a. Add list item Malangawa. b. Remove list item Balefi c. Print the list items one by one using a loop.