This here’s a machine-translated text that might contain some errors!
Task 1 - “Loggin’ In”
Build a simple program that asks the user for a password. If the password matches the right password, the program prints a message.
Hint: Store the right password in a variable and compare it to that variable.
Eksempel Utskrift
Type in yer password: passord123
That there's the right password!
Tips til framgangsmåte
- How to get text from the user 👉[Python 1, Level 1]
- How to check if the text is the same as somethin’.
- You gotta use
ifhere. - Feel free to use
elseto print somethin’ out if the password don’t match.
Task 2a
Ask the user for a color, then print a message dependin’ on which color they picked.
Add at least 4 colors to check. Examples: Red, Green, Blue, Yellow
Eksempel Utskrift
Write a color: red
Red is a warm color!
Tips til framgangsmåte
- How to check if the text is the same as somethin’.
- Here ya gotta use
if,elifandelse. - Hint: Ya can have more’n one
elif.
Task 2b
Now, somethin’ worth ponderin’ on is that, for a computin’ machine
Alter the code so’n it works no matter what ya type in for the color.
Fer instance: Ya type in røD, it still gives ya the message fer red.
New concept! lower() function!
To solve this you gotta use somethin’ that weren’t mentioned in Level 1:
lower(). This function makes all the text “lowercase”, meanin’ just little letters.
You can use it like this:
tekst = "hELlo WoRLd!"
sma_bokstaver = tekst.lower()
print(sma_bokstaver) # prints out "hello world!"
There’s also upper() to make everything BIG letters.
Eksempel Utskrift
Write a color: red
Red is a warm color!
Tips til framgangsmåte
- After ya wrangle the text outta the user, make it all lowercase first afore checkin’ the colors.
Task 3
Is it warm out there or is it cold out there? Ask the user for a temperature in Celsius. Then give a message based on whether it’s warm or cold.
Eksempel Utskrift
What's the temperature: 30
It's hot out there!
Tips til framgangsmåte
- How to get numbers from the user 👉[Python 1, Level 1]
- Check if a number is above or below a certain value. 👍[Python 2, Level 1]
Task 4 - Comparin’ Two Numbers
Write a program where ya ask the user for two numbers. Compare these two numbers to each other and give a message ‘bout whether the “first” or “second” number is bigger.
Tips til framgangsmåte
- How do we compare two variables?
Task 5 - Is it the Weekend?
Write a program that asks the user for a day of the week, then checks if it’s the weekend or not. Print a message if it is the weekend, or a message if it ain’t the weekend!
New concept! or the keyword!
In this task it might be useful to start using or. We haven’t talked about this yet, but it’s very simple!
You can use this to compare two things at the same time!
if number == 2 or number == 3:
print("That's correct!")
There’s also and, where both cases must be true at the same time for it to work.
Eksempel Utskrift
Write a weekday: Saturday
It's the weekend! Woohoo!
Ekstra utfordring
You can do this with just an if and an else, how can you do it?
Task 6 - Grade System
Make a program that takes a score between 0 and 100 and gives back a “Grade”.
| 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 is above a certain value?
- Hint: We never need to check if a value is below a given value here, as long as you check in order from the highest grade to the lowest.
Task 7 - Simple Calculator
Ask the user for two numbers, then ask ‘em for an “operator” to do the reckonin’. Start with addition + and subtraction -. Do the calculation and write out the answer to the user.
Eksempel Utskrift
Type in a number: 14
Type in another number: 18
Type in an operator: +
The answer is: 32
Tips til framgangsmåte
- First, figure out how do we add two numbers together?
- How do we get numbers from the user?
- How do we add two variables together?
- Now also get the operator.
- How do we check which operator has been written?