Skip to content
Snippets Groups Projects
Select Git revision
  • main default protected
1 result

tasks.md

Blame
  • tasks.md 7.81 KiB

    Week 9 Tasks for practicals

    Task 1

    1.1

    Just using conditionals and boolean algebra and print statements we can emulate the logic for some systems that might be used in a program. Consider a rudimentary user permissions system for example.

    role = input("Enter your role (student, lecturer, admin): ")
    
    # Check the role and print out the corresponding permission level 
    if role == "student": 
    	print("Permission level: Read-only") 
    elif role == "lecturer": 
    	print("Permission level: Read and write") 
    elif role == "admin": 
    	print("Permission level: Full access") 
    else: 
    	print("Invalid role entered!")

    1.2

    Snoop pets is looking to build a compatibility checker for their new GPS trackers which identify which of the their proposed three devices a pet owner should buy. For the following pets write the logic for a system like this. Make use of conditionals and boolean algebra.

    Pets:

    feline, canine, reptile, amphibian, fish, bird, equine

    Products:

    pet-tracks-L

    "The pet-tracks-L is snoop pets large form factor pet tracker, suitable for large pets it is splash resistant"

    pet-tracks-S

    "The pet-tracks-S is snoop pets small form factor pet tracker, suitable for smaller pets it is splash resistant and ultra light weight"

    pet-tracks-W

    "The pet-tracks-W is snoop pets waterproof pet tracker, suitable for full time underwater use in depths up to 5m"

    1.3

    Snoop pets user feedback suggests that users now want to be able to be more specific with their pets. They have provided a new list of pets but want to be able to easily add more pets in the future. The proposed solution is to take the following options and use them to map to the previous solution. You are free to use whatever python concepts you feel are appropriate here, but this is possible using just if/else and simple boolean algebra.

    New input options:

    persian, labrador, guppy, owl, bull dog, finch, gecko, clown fish, pony, skink, newt, maine coon, siamese, poodle, husky, snake, frog, goldfish, parrot, horse

    Task 2

    2.1

    We presented a very simple example of a permission system. In some systems we can imagine that more fine grained control is required.

    For Face Off's new e sports league, we can imagine that as they develop they need to provide various features to members of their fast growing team. As new roles are assigned to them they need access to different privileges in addition to those that certain users will have. Examples such as user account management, and team account management should be made available to users and team managers respectively. But other permissions are specific to internal roles at Face Off. Face off organises.

    Here we provide an example for player and team manager permissions, representing the features as a table.

    Change own password Change others passwords invite to team
    Player yes no no
    Team Manager yes only same team yes

    We can model this scenario in the following style.

    account_type = input('enter your account type ')
    team_id = input('enter your team id ')
    
    #Change own password
    if (account_type == "player" or account_type == "team-manager"):
        print('you can change your password')
    
    # Change other password
    target_team = input('enter the team id you want to change a password for ')
    
    if (account_type == "team-manager" and team_id == target_team):
        print('you can change that password')
    elif (account_type == "team-manager" and team_id != target_team):
        print('cant change the password for members of another team')
    else:
        print('cant change the password of others')
    

    Extend this to include a case for team invitation...

    2.2