Looking for 24-25 CS1821/CS1822/DC1821: Programming Laboratory test answers and solutions? Browse our comprehensive collection of verified answers for 24-25 CS1821/CS1822/DC1821: Programming Laboratory at moodle.royalholloway.ac.uk.
Get instant access to accurate answers and detailed explanations for your course questions. Our community-driven platform helps students succeed!
What is the value computed by each of the following expressions?
Test your answers by writing a python program expressions.py
that prints out the value of each of these expressions. Make sure that you run your program using the Python 3 interpreter.
$ python3 expressions.py
What do you notice about the output of your program?
Python distinguishes between two kinds of numbers: whole numbers (1
, 2
, 3
, etc.) are called integers, and fractional numbers (3.14
, 2.78
, etc.) are called floating point.
The boolean constants in Python are True
and False
, and the operators for combining boolean expressions are and
, or
, and not
. If <<expr1>>
and <<expr2>>
are two boolean expressions, then:
<<expr1>> and <<expr2>>
evaluates to true exactly when both <<expr1>>
and <<expr2>>
evaluate to true, and evaluates to false otherwise;<<expr1>> or <<expr2>>
evaluates to true when at least one of <<expr1>>
and <<expr2>>
evaluate to true, and evaluates to false otherwise; andnot <<expr1>>
evaluates to true exactly when <<expr1>>
evaluates to false, and vice-versa.What do you think the order of precedence is between and
, or
and not
? You can check the answers by extending your program in expressions.py
to print out the result of evaluating the following boolean expressions.
The flag of Nepal is unusual in that it is non-quadrilateral.
The flag is also interesting in that its shape is actually specified in the Nepalese constitution using an algorithm (with pseudo code)!
Compare your algorithm with that given in steps (1) through (5) of Schedule 1 of the Nepalese constitution.
Can you write some source code for the pencil code website https://pencilcode.net/edit/untitled , from Checkpoint #3 in last week's lab, to implement the pseudo code and draw the outline of the Nepalese flag?
[Extra (Not for Credit)]: Can you also write some pencil code for drawing the sun? The pseudo code can be found in points (19) through (22) of the Schedule mentioned above.
Write or upload your answers below. You can produce a flowchart using any software you are comfortable with, or by photographing a handwritten page.
If you have the ability to compare two numbers and say which one is bigger, how do you find the maximum of a set of three numbers?
Write a flow chart, and some pseudo code, giving an algorithm for finding the larger of three given numbers.
Can you extend your algorithm to work for a set of four numbers, and a set of five?
Can you give a flowchart and pseudo code that works for a set of any size?
Write or upload your answers below. You can produce a flowchart using any software, or by photographing a handwritten page.
Imagine that it is lunch time and you and your friends are hungry. There are several options for where you might get lunch on campus, e.g.
How would you go about choosing where to eat? There might be a number of different factors that might influence your decision. For example: how far away each venue is; how expensive it is (you might be able to get a discount!); what different kinds of food you each prefer; etc.
Go through the following steps to come up with an algorithm for deciding where to get lunch:
Think about the different criteria that are relevant, and the different possible options that are available; can you identify a series of questions you can answer which will determine the best place?
Write down a flowchart corresponding to the series of decisions you identified in the previous step.
Produce some pseudo code that expresses the process described by your flowchart.
Write or upload your answers below. You can produce your flowchart as an image and upload it: either by using software or photographing a handwritten page.
To complete the checkpoint you need to discuss your solution with a teaching assistant during the checkpoint sessions. Use the box below to make any notes that will be useful.
Draw a flowchart giving the design of a menu system that
presents a sub-menu allowing the user to choose
Upload your flowchart in the box below.
Get Unlimited Answers To Exam Questions - Install Crowdly Extension Now!