Description
Part A – Waves
Create a simple program for landlocked surfers who just want to see some waves. The program should:
1. Create a variable equal to the string ‘v’;
2. Ask how many ‘waves’ the user would like printed;
3. Using a loop, concatenate as many v’s as necessary to the variable created in step 1;
4. After the loop has completed, print the variable from step 1.
Example (Part A):
How many waves would you like to ride?
>>20
vvvvvvvvvvvvvvvvvvvv
Part B – Game for Computer
Build a game for the computer to play. The user will enter a randomly selected letter, and the computer
will make 7 attempts to guess what letter was picked. The script should:
1. Create a list of any 7 letters you want the computer to ‘guess’ (like r, x, i, j, v, w, q);
2. Ask the user to enter a letter;
3. Using a for loop, iterate over the list created in step 1:
a. In each iteration, compare the computer’s attempt to the letter selected by the user;
b. Print if the computer is right or wrong.
Extra Challenge (not required):
Can you stop the loop from repeating once the correct answer has been selected?
Part B Example 1 (Computer wins):
Please select a letter:
>>r
Computer guesses a
The computer is wrong
Computer guesses r
The computer is wins!
Computer guesses t
The computer is wrong
Computer guesses l
The computer is wrong
Computer guesses m
The computer is wrong
Computer guesses x
The computer is wrong
Part B Example 2 (Computer loses)
Please select a letter:
>>v
Computer guesses a
The computer is wrong
Computer guesses r
The computer is wrong
Computer guesses t
The computer is wrong
Computer guesses l
The computer is wrong
Computer guesses m
The computer is wrong
Computer guesses x
The computer is wrong
Computer guesses z
The computer is wrong
Part C – Password
Create a password verification process. The script should:
1. Select any password and save it to a variable (should not be a password you actually use);
2. Ask the user to make a password attempt;
3. If the password is not correct, enter a loop to allow the user 2 more attempts:
a. Inform the user that the attempt is incorrect and ask the user to try again;
b. If the new attempt is correct or the user has tried 3 times total, the loop should end;
4. End the script by informing the user if access is granted or not.
Extra challenge (not required for credit):
Can you also inform the user of how many attempts are left?
Part C Example 1:
Please enter the password:
>>Sojourner
That is incorrect, please try again:
>>Beauvoir
Access granted
Part C Example 2 (Access denied):
Please enter the password:
>>Soujourner
That is incorrect, please try again:
>>Anthony
That is incorrect, please try again:
>>Wollstonecraft
Access denied
Part C Example 3 (Extra challenge):
Please enter the password:
>>Soujourner
That is incorrect, please try again (2 attempts left):
>>Beauvoir
Access granted
Part D – Mean Bargain
A user would like to purchase a product. However, each time the user makes an offer below the price
for which you’re willing to sell, you get mad, and increase the price by 1 dollar. This script should:
1. Create a price variable equal to a number between 1 and 20;
2. Ask the user how much she/he is willing to pay;
3. If the amount from step 2 is less than the amount from step 1:
a. Increase the price by 1;
b. Tell the user you’re unwilling to sell for the amount offered and ask for another amount;
4. Repeat step 3 until the user enters a price greater than or equal to the price;
5. Print ‘It’s a deal! The price is [price]’.
Extra Challenge (not required):
Can you inform the user how much she/he overpaid? This number should the price paid minus
your original asking price (before the price increases).
Part D Example (Original price = 15):
How much will you pay?
>>11
Nope! Try offering more:
>>15
Nope! Try offering more:
>>17
It’s a deal! The price is 17
Part D Extra Challenge Example:
[After output from example above]
You overpaid by 2. I was originally willing to sell for 15.