External Exam Download Resources Web Applications Games Recycle Bin

Exercises D

  1. Generate a Python script that performs the following behaviour when run:

    Username: joe
    invalid username
    Username: sue
    Password: 123
    invalid password
    Username: sue
    Password: abc
    access granted
  2. Generate a Python script that inputs a positive integer n, and for each number between n and 1, the script will count backwards to 1. For example:

    enter n: 4
    4
    3
    2
    1
    3
    2
    1
    2
    1
    1
  3. Monty Hall problem - simulate the Monty Hall gameshow using 3 doors, as shown in the following output:

    choose door 1, 2 or 3: 1
    door 3 is empty
    would you like to switch to door 2? N
    door 1 is empty
    choose door 1, 2 or 3: 1
    door 2 is empty
    would you like to switch to door 3? Y
    door 3 is prize
    choose door 1, 2 or 3: 3
    door 1 is empty
    would you like to switch to door 2? N
    door 3 is empty
  4. Let's Make a Deal gameshow [modified] - Five briefcases labelled A through E, randomly contain $1, $20, $300, $4000 and $50000 respectively. Implement your most eloquent and sophisticated solution to produce the following output:

    Version 1:
    choose briefcase A, B, C, D or E: C
    briefcase C contains $20
    Version 2:
    choose briefcase to hold ['A','B','C','D','E']: C
    choose briefcase to open from remaining ['A','B','D','E']: D
    briefcase D contains $1
    choose briefcase to open from remaining ['A','B','E']: A
    briefcase A contains $50000
    choose briefcase to open from remaining ['B','E']: E
    briefcase E contains $20
    choose briefcase to open from remaining ['B']: E
    invalid selection
    choose briefcase to open from remaining ['B']: B
    briefcase B contains $4000
    briefcase C contains $300