Avast ye, this be a machine-translated text an’ may contain errors, aye!
Task 1 - “Loggin’ In”
Forge a simple program that asks the scallywag for a password. If the password matches the true treasure, then the program shall shout out a message.
Hint: Stash the true password in a variable and compare it against the same!
Example Print
Write password: password123
That be the right password!
Tips til framgangsmåte
- How to pluck text from the landlubber 👉[Python 1, Level 1]
- How to check if the text be matchin’ somethin’.
- Ye must use
iffor this task. - Feel free to use
elseto print a message if the password doth not match.
Task 2a
Ask the scallywag for a colour, then print a message based on the colour they chose.
Add at least 4 colours to check. Examples: Red, Green, Blue, Yellow
Example Print
Write a color: red
Red be a warm color, matey!
Tips til framgangsmåte
- How to check if the text be matchin’ somethin’.
- Here ye must use
if,elif, andelse. - Hint: Ye can have more than one
elif.
Task 2b
One thing worth ponderin’, ye scallywag, be that for a computer…
Change the code so it works regardless o’ what ye type for the color!
Example: Ye write røD, and it still gives ye the message for red.
A new concept! lower() function!
To solve this ye must use somethin’ not mentioned in Level 1:
lower(). This function turns all the text to “lowercase”, meanin’ only small letters.
It can be used like this:
tekst = "hELlo WoRLd!"
sma_bokstaver = tekst.lower()
print(sma_bokstaver) # prints out "hello world!"
There be also upper() to turn everythin’ to CAPITAL letters.
Example Printin’
Write a color: rEd
Red be a warm color!
Tips til framgangsmåte
- After ye have plundered the text from the scallywag, turn it all into small letters first before ye check the colors.
Task 3
Behold, is the weather fair or foul? Ask the landlubber for a temperature in Celsius. Then, give ‘em a message dependin’ on whether ‘tis warm or cold.
Example Printin’
What be the temperature: 30
It be warm outside!
Tips til framgangsmåte
- How to plunder numbers from the scallywag 👉[Python 1, Level 1]
- Check if a number be above or below a certain bounty. 👍[Python 2, Level 1]
Task 4 - Compare Two Numbers
Create a program where ye ask the user for two numbers. Compare these two numbers to each other and give a message if the “first” or “second” number be larger.
Tips til framgangsmåte
- How be we comparin’ two variables, matey?
Task 5 - Be it Weekend, Aye?
Craft ye a program that asks the user for a day o’ the week, then checks if ‘tis the weekend or not. Print a message if ‘tis the weekend, or a message if ‘tis not!
A new concept! or the keyword!
In this task, it may be useful to employ or. We haven’t spoken about this yet, but it be very simple!
Ye can use this to compare two things at once!
if number == 2 or number == 3:
print("That be correct!")
There be also and, where both cases must match at once for it to work.
Example Print
Write a day o' the week: Saturday
It be the weekend! Woohoo!
Extra challenge
Ye can conquer this with nary an if and an else, how might ye pull this off?
Task 6 - The Grade System
Create a program that takes in a score between 0 and 100 and gives it a “Grade” back, ye scurvy dog!
| Score | Grade |
|---|---|
| Over 90 | 6 |
| Between 75 and 89 | 5 |
| Between 60 and 74 | 4 |
| Between 50 and 59 | 3 |
| Between 40 and 49 | 2 |
| Under 40 | 1 |
Tips til framgangsmåte
- How do we check if a number be exceedin’ a certain value, aye?
- Hint: We need never check if a value be below a given value here, so long as ye check in order from the highest grade to the lowest.
Task 7 - A Simple Calculator
Ask the landlubber for two numbers, then ask for an “operator” for the reckonin’. Start with addition + and subtraction -. Do the calculatin’ and print the answer to the scallywag.
Example Printin’
Write a number: 14
Write another number: 18
Write an operator: +
The booty be: 32
Tips til framgangsmåte
- First, let’s be learnin’ how do we add two numbers together, aye?
- How do we be gettin’ numbers from the user, savvy?
- How do we be addin’ two variables together, eh?
- Now, let’s be fetchin’ the operator as well.
- How do we be checkin’ which operator be writ, arr?