This is a machine-translated text that may contain errors!
Task 1 - “Login”
Create a simple program that asks the user for a password. If the password matches the correct password, the program prints a message.
Hint: Store the correct password in a variable and compare it to the variable.
Eksempel Utskrift
Enter password: password123
That is the correct password!
Tips til framgangsmåte
- How to retrieve text from the user 👉[Python 1, Level 1]
- How to check if the text is equal to something.
- You must use
ifhere. - Feel free to use
elseto print if the password does not match.
Task 2a
Ask the user for a color, then print a message based on which color they chose.
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 similar to something.
- Here you must use
if,elifandelse. - Hint: You can have more than one
elif.
Task 2b
One thing worth considering is that, for a computer
Modify the code to work regardless of what you enter for the color.
Example: If you write røD, it should still give you the message for red.
New concept! lower() function!
To solve this, you must use something not mentioned in Level 1:
lower(). This function converts all text to “lowercase”, i.e., only lowercase letters.
It can be used like this:
tekst = "hELlo WoRLd!"
sma_bokstaver = tekst.lower()
print(sma_bokstaver) # prints out "hello world!"
There is also upper() to convert everything to UPPERCASE letters.
Eksempel Utskrift
Write a color: red
Red is a warm color!
Tips til framgangsmåte
- After you have extracted the text from the user, convert it to lowercase first before checking the colors.
Task 3
Is it warm outside or is it cold outside? Ask the user for a temperature in Celsius. Then, provide a message based on whether it is warm or cold.
Eksempel Utskrift
What is the temperature: 30
It is hot outside!
Tips til framgangsmåte
- How to retrieve 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 - Compare Two Numbers
Create a program that asks the user for two numbers. Compare these two numbers to each other and give a message about whether the “first” or “second” number is larger.
Tips til framgangsmåte
- How do we compare two variables?
Task 5 - Is it the weekend?
Create a program that asks the user for a day of the week, then checks if it is the weekend or not. Print a message if it is the weekend, or a message if it is not the weekend!
New concept! or the keyword!
In this assignment, it may 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 is correct!")
There is 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 achieve this with only one if and one else, how can you do it?
Task 6 - Grading System
Create a program that takes a score between 0 and 100 and returns 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 for an “operator” for the calculation. Start with plus + and minus -. Perform the calculation and print the answer to the user.
Eksempel Utskrift
Write a number: 14
Write another number: 18
Write an operator: +
The answer is: 32
Tips til framgangsmåte
- First, find out how do we add two numbers together?
- How do we retrieve numbers from the user?
- How do we add two variables together?
- Now also retrieve the operator.
- How do we check which operator has been written?