top of page
Image by Alexander Grey

Subroutines

Unit 2 Summary - part 4

Image by Nareeta Martin
Image by Annie Spratt
Random Number.png
  • Line 1 is to import random number.

​​

  • Line 2 is to set the numbers used should be from 1 - 100 (number 1 and 100 are also included).​

Image by Kenrick Mills

Subroutine coding:​

Subroutines 78-79.png
  • Line 1 is a subroutine to enter password, line 11 is to call/execute it.

​​

  • ​Line 6 is a subroutine to display a welcome screen, line 12 is to call/execute it.

​​

​Sometimes we need to check some parts of coding, we don't want to execute all parts.

With def, the coding will not be executed without your permission.

(If we don't need it, we don't call it. So def is used to break down big coding.)​

Image by Scott Webb
Subroutines 80-81.png
  • Line 1 is a subroutine to create a line, line 15 is to call/execute it.

It only has 1 parameter called length.​

​​

  • ​Line 4 is a subroutine to display a welcome screen, line 16 is to call/execute it.

It only has 1 parameter called word.​

​

  • Line 8 is a subroutine to divide whole numbers, line 17 is to call/execute it.

It only has 1 parameter called number.​​

Candy Cotton
Subroutines 82-83.png
  • Line 1 is a subroutine to create a simple drawing with symbols, line 14 is to call/execute it.

It has multiple parameters called height & symbol.​

​

  • ​Line 5 is a subroutine to divide whole numbers, line 15 is to call/execute it.

It has multiple parameters called dividend & divisor.​

​

  • Line 8 is a subroutine to create a box art / box drawing, line 16 is to call/execute it.

It has multiple parameters called width & height.​​​​​

Image by Krystal Ng
Subroutines 86.png
Image by Adrian Infernus
  • Line 1 is a subroutine to roll a dice

It only has 1 parameter called dice.​

​

  • ​Line 3 uses for loop to roll the dice.

​

  • Line 4 uses random numbers between 1 - 6, because a dice has 6 sides (1 and 6 are included).

​

  • Line 7 is to keep the result. Without return, the number is gone from computer's memory after the procedure is executed/over.

​​

  • Line 9 is to roll the dice 3 times to get a random strength for hero.

​​

  • Line 10 is to roll the dice 3 times to get a random strength for monster.

​

  • Line 11 - 16 are used to show who gets the most strength. If the hero gets a bigger strength, they win, or vice versa, or a draw if both get the same strength.

Image by J Lee
Subroutines 87.png
Image by Pawel Czerwinski
  • Line 1 is a subroutine to convert miles per hour into kilometres per second.

The parameter is mph.

​

  • ​Line 5 is to capture the returned value so you can call it.

​​

  • Line 7 is to call/execute line 1.

Image by Wengang Zhai
Visconsio Nekoland Logo.jpg
PT. Visconsio Kaya Jaya Masyhur

© 2020-2023 by Miana Kitty

bottom of page