This doth be a machine-wrought text which may contain errors!
Task 1 - “Login”
Craft ye a simple programme that doth inquire of the user for a password. Should the password accord with the true password, then shall the programme print forth a message.
Hint: Store the true password within a variable and compare it therewith.
Eksempel Utskrift
Write the password: passord123
'Tis the correct password, forsooth!
Tips til framgangsmåte
- How to fetch text from the user 👉[Python 1, Level 1]
- How to check if the text doth resemble somewhat.
- Here must thou employ
if. - Use freely
elseto print should the password not agree.
Task 2a
Pray, ask the user for a hue, and thereafter utter a message based upon which colour they didst choose.
Add at the least 4 colours to check. Forsooth, examples: Red, Green, Blue, Yellow.
Eksempel Utskrift
Write a colour: red
Red is a warm colour, forsooth!
Tips til framgangsmåte
- How to ascertain if the text doth resemble somewhat.
- Here must thou employ
if,elifandelse. - Hint: Thou mayest possess more than one
elif.
Task 2b
A matter worthy of contemplation doth present itself, that for a computing engine,
Amend the code such that it shall function whate’er hue thou dost input.
Forsooth: Shouldst thou write røD, yet still receive the message pertaining to red.
Nytt konsept! lower() funksjonen!
To resolve this matter, thou must employ a thing not mentioned in Level 1:
lower(). This function doth render all text to “lowercase”, that is to say, but small letters.
It may be used thus:
tekst = "hELlo WoRLd!"
sma_bokstaver = tekst.lower()
print(sma_bokstaver) # printer ut "hello world!"
There doth also exist upper() to transform all to GREAT letters.
Eksempel Utskrift
Write a colour: red
Red is a warm colour, forsooth!
Tips til framgangsmåte
- Anon, after thou hast drawn forth the text from the user, do transform it to lower-case letters first, ere thou dost check the colours.
Task the Third
Doth it wax warm abroad, or doth chill grip the air? Pray thee, ask the user for a temperature in Celsius. Thereafter, deliver a message based upon whether ‘tis warm or cold.
Eksempel Utskrift
What is the temperature: 30
'Tis a warm day, forsooth!
Tips til framgangsmåte
- How to fetch numbers from the user 👉[Python 1, Level 1]
- To check if a number doth exceed or fall short of a certain value. 👍[Python 2, Level 1]
Task the Fourth - To Compare Two Numbers
Craft ye a program wherein thou dost inquire of the user for two numbers. Compare these two numbers one with the other, and deliver a message declaring whether the “first” or “second” number doth exceed the other in magnitude.
Tips til framgangsmåte
- How do we compare two variables?
Task 5 - Is it Holyday?
Craft ye a programme that doth inquire of the user as to a day of the week, thereafter checking if ‘tis a holyday or nay. Print forth a message should it be a holyday, or a message should it not be so!
Nytt konsept! or nøkkelordet!
In this task, ‘tis perchance most helpful to employ or. We have not discoursed of this as yet, but ‘tis wondrous simple, I assure thee!
This mayst thou use to compare two things at once!
if number == 2 or number == 3:
print("Det er korrekt!")
There doth exist also and, where both cases must needs agree simultaneously for it to succeed.
Eksempel Utskrift
Write a day of the week: Saturday
'Tis the weekend! Woohoo!
Ekstra utfordring
Thou mayest achieve this with but one if and one else, pray tell, how may this be done?
Task the Sixth - A System of Grades
Craft ye a program that doth receive a score betwixt 0 and 100, and rendereth forth a “Grade” in return.
| Score | Grade |
|---|---|
| Above 90 | 6 |
| ‘Twixt 75 and 89 | 5 |
| ‘Twixt 60 and 74 | 4 |
| ‘Twixt 50 and 59 | 3 |
| ‘Twixt 40 and 49 | 2 |
| Under 40 | 1 |
Tips til framgangsmåte
- How do we ascertain if a number doth exceed a certain value?
- Hint: We need ne’er to check if a value be beneath a given value here, so long as thou dost check in order from the highest digit to the lowest.
Task the Seventh - A Simple Reckoning
Pray, ask of the user two numbers, and thereafter inquire as to an “operator” for their computation. Begin with the sign of addition + and subtraction -. Perform the reckoning and render the answer unto the user.
Eksempel Utskrift
Write thou a number: 14
Write yet another number: 18
Write an operator: +
The answer is: 32
Tips til framgangsmåte
- First, discover how do we add two numbers together?
- How do we obtain numbers from the user?
- How do we add two variables together?
- Now, fetch forth the operator also.
- How do we check which operator hath been writ?