Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Introduction to Problem Solving and Python Programming, Exercises of Computer Programming

A brief introduction to problem-solving and Python programming. It covers topics such as algorithms, programming languages, recursion, control flow statements, lists, and iteration. It also explains the concept of towers of Hanoi and how to assess problem-solving methods. useful for beginners who want to learn the basics of problem-solving and programming using Python.

Typology: Exercises

2022/2023

Available from 07/27/2023

dennis-durfort
dennis-durfort 🇺🇸

16 documents

1 / 5

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
QUESTIONS AND ANSWERS
PROBLEM SOLVING and PYTHON PROGRAMMING
Unit I
1. Define an algorithm
An algorithm is a procedure or formula for solving a problem, based
on conducting a sequence of specified actions
2. Specify any 5 programming
languages Java, C, C++,
Python, PHP
3. Distinguish between pseudo code and flowchart
Flowchart is usually a graphical representation, where as pseudo-code is
something written in a language. Note that they both show the step by
step procedure for solving a problem. One is graphical while one is text
based.
4. Define recursion
Recursion is the process of defining a problem (or the solution to a
problem) in terms of a simpler version of itself. A recursive procedure or
routine is one that has the ability to call itself.
5. Define control flow statement.
A program's control flow is the order in which the program's code
executes. The control flow of a Python program is regulated by conditional
statements, loops, and function calls.
6. What is the concept of towers of Hanoi.
The objective of the game is to move the entire stack of disks from
Tower 1 to Tower 3. You can move only one disk at a time. No disk may be
placed on top of a smaller disk. With 3 disks, the puzzle can be solved in 7
moves. The minimal number of moves required to solve a Tower of Hanoi
puzzle is 2n − 1, where n is the number of disks.
7. Explain list.
In computer science, a list or sequence is an abstract data type that
represents a countable number of ordered values, where the same value
may occur more than once. The name list is also used for several concrete
data structures that can be used to implement abstract lists, especially
pf3
pf4
pf5

Partial preview of the text

Download Introduction to Problem Solving and Python Programming and more Exercises Computer Programming in PDF only on Docsity!

PROBLEM SOLVING and PYTHON PROGRAMMING Unit I

  1. Define an algorithm An algorithm is a procedure or formula for solving a problem, based on conducting a sequence of specified actions
  2. Specify any 5 programming languages Java, C, C++, Python, PHP
  3. Distinguish between pseudo code and flowchart Flowchart is usually a graphical representation, where as pseudo-code is something written in a language. Note that they both show the step by step procedure for solving a problem. One is graphical while one is text based.
  4. Define recursion Recursion is the process of defining a problem (or the solution to a problem) in terms of a simpler version of itself. A recursive procedure or routine is one that has the ability to call itself.
  5. Define control flow statement. A program's control flow is the order in which the program's code executes. The control flow of a Python program is regulated by conditional statements, loops, and function calls.
  6. What is the concept of towers of Hanoi. The objective of the game is to move the entire stack of disks from Tower 1 to Tower 3. You can move only one disk at a time. No disk may be placed on top of a smaller disk. With 3 disks, the puzzle can be solved in 7 moves. The minimal number of moves required to solve a Tower of Hanoi puzzle is 2 n^ − 1, where n is the number of disks.
  7. Explain list. In computer science, a list or sequence is an abstract data type that represents a countable number of ordered values, where the same value may occur more than once. The name list is also used for several concrete data structures that can be used to implement abstract lists, especially

linked lists. Many programming languages provide support for list data types, and have special syntax and semantics for lists and list operations.

  1. What is Iteration? Iteration is the repetition of a process in a computer program, usually done with the help of loops. Many computer programs and programming languages use iterations to perform specific tasks, solve problems, and present solutions.
  2. Explain how do you assess problem solving method. The problem solving method is the process of working through details of a problem to reach a solution. Problem solving may include mathematical or systematic operations and can be a gauge of an individual's critical thinking skills. Methods for assessing problem-solving learning outcomes vary with the nature of the -problem. Problem solving processes are normally assessed by coding schemes. Based on that assumption, numerous models of problem solving have been suggested, most of which involve a sequence of steps, including:  Define the problem.  Analyze the problem (identify possible causes).

 Analysis of Algorithm  Implementation of Algorithm  Program testing  Documentation Preparation

  1. Give an example for recursion function #To find the factorial of a number def calc_factorial( x): if x == 1: return 1 else: return (x * calc_factorial(x-1)) num = 4 print("The factorial of", num, "is", calc_factorial(num))

output : The factorial of 4 is 24

  1. Discuss building blocks of algorithm. Any algorithm can be constructed from just three basic building blocks. These three building blocks are Sequence, Selection, and Iteration. Sequence is an action in which one or more instructions that the computer performs in sequential order (from first to last). Selection is a Decision making choice among several actions. Iteration can be a Loop in which one or more instructions that the computer performs repeatedly.
  2. Differentiate predefined function and user defined function. Predefined functions are part of the programming language. For eg. built-in C functions, like printf( ) and scanf( ). A user-defined function is a function which the programmer creates and uses in a program.