More intricate tasks!

Skip to content

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.

Example Print
Write password: password123
The password be right!

Tips til framgangsmåte
  • How to fetch text from the user 👉[Python 1, Level 1]
  • How to check if the text doth match something.
  • Here thou must employ if.
  • Pray, use else to declare should the password not be true.

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.

Example Print
Write a colour: red
Red is a warm colour!

Tips til framgangsmåte
  • How to assay if the text doth matcheth aught.
  • Here thou must employ if, elif, and else.
  • Hint: Thou mayest possess more than one elif.

Task 2b

One thing worth pondering is that, for a machine

Alter the code so it doth function regardless of what thou writest for the colour.

Example: Thou writest røD, it yet yieldeth unto thee the message for red.

A new concept! The lower() function!

To solve this, thou must employ something which hath not been mentioned in Level 1:

lower(). This function doth render all text unto “lowercase,” that is to say, naught but small letters.

It may be used thus:

tekst = "hELlo WoRLd!"
sma_bokstaver = tekst.lower()
print(sma_bokstaver) # prints out "hello world!"

There existeth also upper() to transform all into GREAT letters.

Example Print
Write thou a colour: rEd
Red is a warm colour!

Tips til framgangsmåte
  • After thou hast extracted the text from the user, convert it unto lowercase letters first, ere thou checkest 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.

Example Print
What be the temperature: 30
'Tis warm without!

Tips til framgangsmåte
  • How to extract numbers from the user 👉[Python 1, Level 1]
  • To check if a number doth exceed or fall beneath 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.

Advice for thy procedure
  • How doth one 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!

A new concept! The or keyword!

In this task, it may be most useful to employ or. We have spoken not yet of this, but ‘tis passing simple!

This thou canst use to compare two things even as they stand!

if number == 2 or number == 3:
    print("It is correct!")     

There existeth also and, wherein both cases must hold true together for the deed to pass.

Example Print
Write thou a day of the week: Saturday
The weekend is upon us! 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 shall we assay if a number doth exceed a certain value?
  • Hint: We need never check if a value be beneath a given value herein, provided thou checkest in order from the highest character unto 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.

Example Print
Write thou a number: 14
Write yet another number: 18
Write an operator: +
The answer is: 32

Tips til framgangsmåte
  • First, determine, how do we sum two numbers together?
  • How shall we fetch numbers from the user?
  • How may we add two variables together?
  • Now, likewise, fetch the operator.
  • How shall we discern which operator hath been writ?