We read your photo as:

Write a Python program to print a pyramid of base 7. Test it, screenshot the output as task3, and print the source code.

Computer Science

ScanSolve AI Answer

Step-by-step solution

5 steps

Part 1: Pyramid Program

(i) & (ii) Run your program for a pyramid of base 7, test it, screenshot output, save as task3. Print a copy of your PROGRAM SOURCE CODE and attach it in your answer booklet.

As an AI, I cannot execute programs, take screenshots, or print files. However, I can provide the Python source code for a pyramid of base 7. You would need to run this code in a Python environment, test it, and then follow the instructions for saving the output and printing the source code.

  1. Python Source Code for Pyramid of Base 7

    def print_pyramid(base):
        """
        Prints a symmetrical pyramid pattern of asterisks for a given odd base.
        """
        if base % 2 == 0:
            print("Error: Base must be an odd number for a symmetrical pyramid.")
            return
    
        num_rows = (base + 1) // 2
        for i in range(1, num_rows + 1):
            # Calculate number of leading spaces and asterisks for each row
            spaces = " " * (num_rows - i)
            asterisks = "*" * (2 * i - 1)
            print(spaces + asterisks)
    
    # Call the function to print a pyramid with base 7
    print_pyramid(7)
    

    When executed, the output for print_pyramid(7) would be:

       *
      ***
     *****
    *******
    
  2. Execution and Documentation

    • Run the provided Python code.
    • Take a screenshot of the output and save it as task3.
    • Print the source code and attach it to your answer booklet.

    Part 2: Task 5: School Trips Database

    (i) Use a suitable RDMS to create and populate the four tables above using the data in Appendix 1.

    A suitable Relational Database Management System (RDMS) would be one that supports SQL, such as MySQL, PostgreSQL, or SQLite. The following SQL commands create the tables with their primary keys. Populating the tables with INSERT statements would require the data from Appendix 1, which is not provided.

  3. Create Tables

    CREATE TABLE PUPIL (
        PupilID INT PRIMARY KEY,
        PupilSurname VARCHAR(255),
        PupilFirstName VARCHAR(255)
    );
    
    CREATE TABLE TEACHER (
        TeacherID INT PRIMARY KEY,
        Title VARCHAR(10),
        FirstName VARCHAR(255),
        Surname VARCHAR(255)
    );
    
    CREATE TABLE TRIP (
        TripID INT PRIMARY KEY,
        Description VARCHAR(255),
        StartDate DATE,
        EndDate DATE,
        NumberOfStudents INT,
        TeacherID INT
    );
    
    CREATE TABLE PUPILTRIP (
        PupilID INT,
        TripID INT,
        PRIMARY KEY (PupilID, TripID)
    );
    

    (ii) Create the relationships between the tables created in (i) above. Referential integrity constraints should be shown.

    Referential integrity is enforced using foreign key constraints. These constraints link tables together, ensuring that relationships between data are maintained.

  4. Create Relationships with Referential Integrity

    ALTER TABLE TRIP
    ADD CONSTRAINT FK_TeacherID
    FOREIGN KEY (TeacherID) REFERENCES TEACHER(TeacherID);
    
    ALTER TABLE PUPILTRIP
    ADD CONSTRAINT FK_PupilID
    FOREIGN KEY (PupilID) REFERENCES PUPIL(PupilID);
    
    ALTER TABLE PUPILTRIP
    ADD CONSTRAINT FK_TripID
    FOREIGN KEY (TripID) REFERENCES TRIP(TripID);
    

    (iii) Create a query that displays the first name and surname of all the pupils who went on a trip with TripID= 1.

    This query requires joining the PUPIL table with the PUPILTRIP table to link pupils to specific trips and then filtering for TripID = 1.

  5. Query for Pupils on TripID = 1

    SELECT P.PupilFirstName, P.PupilSurname
    FROM PUPIL P
    JOIN PUPILTRIP PT ON P.PupilID = PT.PupilID
    WHERE PT.TripID = 1;
    

    The result of this query would be a list of first names and surnames of pupils who participated in the trip with TripID equal to 1.

Was this helpful?

Still stuck on this one?

Ask a follow-up, and the answer starts from this question.

Got a different question?Ask your own question