0% found this document useful (0 votes)
24 views17 pages

Lab 2 Work

Uploaded by

rizwanshareef325
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)
24 views17 pages

Lab 2 Work

Uploaded by

rizwanshareef325
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
You are on page 1/ 17

Part A

A1 - Create a Process Flowchart

Step 1:

Answers:
1. If the player selects a number between 0 and 128—yes, the operation can catch.
The range is initially set at 0 to 128 with the average being determined at the
midway. The upper bound of the range (b) is lowered to 64 if the player indicates
that the midpoint (64 on the first guess) is too high. If the value is 0, then additional
guesses continue to half the range downward towards 0. With a few steps, this
approach guarantees that the range narrows enough to include 0.
In a similar vein, if 128 is selected, the estimates that follow half the remaining
range once more, but this time they do so in an upward direction toward 128 due to
the feedback that the midpoint is too low. The method is intended to effectively
narrow down on the desired number by iteratively modifying the range in response
to player input and recalculating the midpoint. This guarantees that, within the six
attempts permitted by the process's criteria, even the boundary values of 0 and 128
can be correctly estimated.

2. If 0 or 128 cannot be guess by the algorithm, then some modifications are


needed. Initially, the midpoint calculation should be adjusted to always round up
when increasing the lower limit and down when reducing the upper limit in order to
confirm that these boundary values are not ignored. Further, by positioning the
initial upper boundary b little above 128, say to 129, 128 can become an accessible
midpoint. The whole range including the extreme values would be more consistently
covered by implementing these changes.
A2 – Draw the Flowchart
Answer:

1. Significance of testing if t = 6 is that user can do maximum six attempts to


guess. If attempt reached to t=6 and algorithm has not successfully identified
then the program will be stopped and say it will not guess after 6 times. It will
only allow user to attempt only 6 times.
2. Test for 0 and 128 to be placed right after setting the “a” and “b” initial
values and also before entering into the loop. This can be done by two
additional nodes. First is after setting “a” and “b” initial values. Insert a node
to check the number is 0 or not and if the first condition is false then check
the number is 128 or not.

Part B
Basic Python Programming
B1 – Launch Python from Windows 10 or else
B2 – Python Basics
Step 1: Python programming in the interactive interpreter.
1.

2.

3.

4.
5.

6.

7.
8.

9.

B3 – IDLE for Python


1.

2.

3.
4.

5.
Part C
More Python Programming

1.

3.

4.
5.

6.
Saving and Executing your code
7, 8.

9,10,11

12.
13.

14.

Executing code from the Command Line


15, 16
Numbers and Expressions
18

19

20
21

22

23
25

26.
27.

28.

29, 30, 31, 32.


33.

34.

35.

36.
37.

You might also like