logo

Crowdly

24-25 CS1821/CS1822/DC1821: Programming Laboratory

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.

View this question

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:

  • the boolean expression <<expr1>> and <<expr2>> evaluates to true exactly when both <<expr1>> and <<expr2>> evaluate to true, and evaluates to false otherwise;
  • the boolean expression <<expr1>> or <<expr2>> evaluates to true when at least one of <<expr1>> and <<expr2>> evaluate to true, and evaluates to false otherwise; and
  • the boolean expression not <<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.

    View this question

    CT3: Computational Thinking Checkpoint 3 - Drawing the Nepalese Flag

    The flag of Nepal is unusual in that it is non-quadrilateral.

    • Think about how you would instruct someone to reproduce the shape of the flag.
    • Draw a flowchart that would allow someone to produce the flag's outline.
    • Write some pseudo code for your algorithm to draw the Nepalese flag.

    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.

    View this question

    CT2: Computational Thinking Checkpoint 2 - Maximum of a Set of Numbers

    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.

    View this question

    CT1: Computational Thinking Checkpoint 1 - Deciding Where To Eat

    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.

    • Founder’s Dining Hall
    • The Hub
    • Boilerhouse Cafe
    • KW’s
    • Tommy’s Kitchen
    • The Union Shop

    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:

    1. 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?

    2. Write down a flowchart corresponding to the series of decisions you identified in the previous step.

    3. 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.

    View this question

    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.

    View this question

    Draw a flowchart giving the design of a menu system that

    1. first asks the user for factual or fiction,
    2. presents a sub-menu allowing the user to choose

      • a category from their choice in Step 1
      • to return to Step 1

    3. prints the aisle of the chosen category.

    Upload your flowchart in the box below.

    View this question

    Want instant access to all verified answers on moodle.royalholloway.ac.uk?

    Get Unlimited Answers To Exam Questions - Install Crowdly Extension Now!