GRADE 8 · COMPUTING · UNIT 1 · LESSON 1.38

Computational thinking and programming

Investigate random real values and review library use

Read a little. Try the workbook. Check your answers. Choose one section below to get started.

Topic 1.38 · Investigate random real values and review library use9 fillable worksheet pagesRead at your own pace

LET’S TRACE, REASON AND TEST

Investigate random real values and review library use

A real-valued random API has a documented interval. Python uniform(a, b) selects a floating-point value between its bounds; endpoint inclusion can depend on floating-point rounding. A few observations cannot establish the whole possible range.

Today’s two goals
  • Read uniform() documentation, generate a real value and consolidate import/call/return vocabulary.
  • Explain my method and support it with a labelled trace, example or test record.
Original PaxaKids illustration for Investigate random real values and review library use. Use the supplied program and data models for precise workbook facts.
An original PaxaKids workbook scene. Use the supplied programs and data for precise workbook facts.

Work through an example

For random.uniform(3.5, 6.5), an illustrative value such as 4.8 lies within the stated interval, while 7.0 lies outside it. This classifies candidate values; it is not a claim that a particular draw occurred.

Try before your workbook

Would seeing three values below 5.0 prove that uniform(3.5, 6.5) cannot produce values above 5.0?

Explore the clues

Tap one card to find out more.

Understand the idea

A real-valued random API has a documented interval. Python uniform(a, b) selects a floating-point value between its bounds; endpoint inclusion can depend on floating-point rounding. A few observations cannot establish the whole possible range.

Concept to practise: Investigate random real values and review library use.

Work through an example

For random.uniform(3.5, 6.5), an illustrative value such as 4.8 lies within the stated interval, while 7.0 lies outside it. This classifies candidate values; it is not a claim that a particular draw occurred.

Try before your workbook

Would seeing three values below 5.0 prove that uniform(3.5, 6.5) cannot produce values above 5.0?

Check my readiness thinking

No. Three observations are a small sample. Use the documented interval and label any actual samples honestly; do not infer the full range from a few draws.

Your original programs and learning models

These original PaxaKids program and data models support your workbook. Some examples deliberately contain faults to investigate. Follow their headings and preserve exact code case, punctuation and order. Traces and supplied records are not claims of physical testing.

Generate a random floating-point value

random.uniform(a, b) generates a floating-point value between the supplied bounds. Unlike randint, it is not limited to integers. A returned float may have a fractional part, but need not do so.

The official uniform documentation notes that the upper endpoint may or may not be included, depending on floating-point rounding. Do not promise that either endpoint will appear in a short sample.

Import, store and display a generated real value

This complete original program imports random, supplies bounds 2.5 and 5.5, stores the returned float in value and prints it. The marker on page 3 illustrates one in-range value; it is not a recorded execution.
Original Paxa uniform example
import random
value = random.uniform(2.5, 5.5)
print("Value:", value)

Check candidate values against the documented interval

For uniform(2.5, 5.5), classify whether each shown float lies within the documented boundaries. This is an interval check, not a claim that any particular candidate must occur in a run.
Check candidate values against the documented interval — original model
CandidateWithin 2.5 through 5.5?
2.5{'clue': 'True or False', 'prompt': 'Interval check 2.5', 'answers': ['True']}
5.5{'clue': 'True or False', 'prompt': 'Interval check 5.5', 'answers': ['True']}
2.49{'clue': 'True or False', 'prompt': 'Interval check 2.49', 'answers': ['False']}
5.51{'clue': 'True or False', 'prompt': 'Interval check 5.51', 'answers': ['False']}
Check candidate values against the documented interval — original labelled workbook model. The following text version gives its labels and values.
Check candidate values against the documented interval · original PaxaKids model.
Read this model’s labels and values

Use a return immediately or store it first

Version A stores a returned float before printing it with a label. Version B prints a return directly. Separate random calls are separate draws and need not show equal values, even with equal bounds.
A: store then print
import random
value = random.uniform(2.5, 5.5)
print("Value:", value)
B: print directly
import random
print(random.uniform(2.5, 5.5))

Review purpose, import and rounding vocabulary

Use what you have learned about library purpose and correct use. Choose the statement matching the documented behaviour; then write the complete import line.

Consolidate calls, outputs and inclusive integer bounds

Assume the relevant module has been imported. Give a complete call only in the first row; other rows ask for a result, module name or full possible-integer list. These are original review examples.
Consolidate calls, outputs and inclusive integer bounds — original model
RequestAnswer
Call floor with argument 46.7{'clue': 'Complete call', 'prompt': 'Complete floor call', 'answers': ['math.floor(46.7)']}
Return from math.ceil(46.7){'clue': 'Integer', 'prompt': 'Ceiling return for46.7', 'answers': ['47']}
Output of print(math.floor(1234.999)){'clue': 'Integer', 'prompt': 'Floor output for1234.999', 'answers': ['1234']}
Output of print(math.ceil(1234.999)){'clue': 'Integer', 'prompt': 'Ceiling output for1234.999', 'answers': ['1235']}
Module in random.randint(3, 9){'clue': 'Module name', 'prompt': 'Random library name', 'answers': ['random']}
Possible integers from randint(20, 23){'clue': 'Comma-separated list', 'prompt': 'Possible integer list20to23', 'answers': ['20, 21, 22, 23', '20,21,22,23']}

Gather evidence for six library skills

Use the following evidence prompts for your final review. Refer to an actual program, trace, correction or documented example for each skill. A claim of confidence alone is not evidence.
Gather evidence for six library skills — original model
SkillEvidence to look for
Describe a program libraryExplain reusable code and available features.
Explain why libraries are usedGive a purpose-related benefit and remaining check.
Identify a Python libraryName a suitable documented module or package.
Import it in a programShow a complete valid import statement.
Call a library functionIdentify the feature and supplied arguments.
Use its returned valueShow storage, output or use in a calculation.

Files for this activity

Use these original PaxaKids practice files with the matching workbook. Work on a local copy in the appropriate editor. Some examples deliberately contain faults to investigate; a downloaded file is not a completed practical test.

Paxa the Fox

Try one step with Paxa!

Trace code in the stated order and preserve exact spelling and case. Use fictional data. Label a prediction, paper trace, simulator run and physical-device test separately; an unperformed test stays Pending. Save personal responses before leaving.

Our Unit 1 learning path
  1. Lesson 1.1: Recall algorithms and representations
  2. Lesson 1.2: Purpose and conventions of pseudocode
  3. Lesson 1.3: Input, output and strings
  4. Lesson 1.4: Identifiers and assignment
  5. Lesson 1.5: Arithmetic and translation
  6. Lesson 1.6: Trace and review a sequence
  7. Lesson 1.7: Conditions and two-way flow
  8. Lesson 1.8: IF THEN and indentation
  9. Lesson 1.9: IF THEN ELSE and decision diagrams
  10. Lesson 1.10: Ordered ELSEIF and fallback ELSE
  11. Lesson 1.11: Match flowchart and pseudocode branches
  12. Lesson 1.12: AND, OR and NOT
  13. Lesson 1.13: Grouping, precedence and review
  14. Lesson 1.14: Why software searches
  15. Lesson 1.15: A successful linear search
  16. Lesson 1.16: An unsuccessful search and termination
  17. Lesson 1.17: Practise and communicate the search
  18. Lesson 1.18: Translate conditions into Python
  19. Lesson 1.19: One-branch IF programs
  20. Lesson 1.20: Two-way IF ELSE programs
  21. Lesson 1.21: Ordered ELIF choices
  22. Lesson 1.22: Ranges and independent decisions
  23. Lesson 1.23: Boolean operators in Python
  24. Lesson 1.24: Design and test recommendations
  25. Lesson 1.25: Trace, debug and reflect
  26. Lesson 1.26: Choose data types and recognise Boolean literals
  27. Lesson 1.27: Set and use Boolean flags
  28. Lesson 1.28: Explain and identify constants
  29. Lesson 1.29: Express constants in three algorithm forms
  30. Lesson 1.30: Use a fixed factor in a calculation
  31. Lesson 1.31: Cast to Boolean and validate an empty response
  32. Lesson 1.32: Recall calls and trace return values
  33. Lesson 1.33: Supply parameters and reuse library code
  34. Lesson 1.34: Choose and import libraries responsibly
  35. Lesson 1.35: Round with floor and ceiling
  36. Lesson 1.36: Use pi and investigate another mathematical feature
  37. Lesson 1.37: Generate random choices within bounds
  38. Lesson 1.38: Investigate random real values and review library use
  39. Lesson 1.39: Retrieve test tables and predict selection outcomes
  40. Lesson 1.40: Decompose everyday problems
  41. Lesson 1.41: Decompose programs and organise shared work
  42. Lesson 1.42: Develop through repeated build/test cycles
  43. Lesson 1.43: Predict and verify algorithm outcomes
  44. Lesson 1.44: Choose representative and boundary tests
  45. Lesson 1.45: Build, execute and review a test plan
  46. Lesson 1.46: Recall physical inputs and compare transmission media
  47. Lesson 1.47: Configure a radio group and agree a message scheme
  48. Lesson 1.48: Send and receive numbers and strings
  49. Lesson 1.49: Trace numeric message sequences
  50. Lesson 1.50: Transmit text and use received data in conditions
  51. Lesson 1.51: Diagnose and extend a message protocol
  52. Lesson 1.52: Review communication and evidence of testing
  53. Lesson 1.53: Project 1: Adventure story
  54. Lesson 1.54: Project 2: Fire, Water, Earth
  55. Lesson 1.55: Check your progress 1
For grown-ups: using this lesson

Your answers are checked in your browser. Open responses need grown-up review and are shown separately from the automatic score. Check your work, then use “Retry answers to practise” to revisit mistakes while keeping correct responses.

Read one explanation, discuss the model and try the readiness check before the workbook. Choose “Mark lesson finished” when ready. Optional account progress saves lesson position and completion across devices; save personal responses before leaving.

2. Fill in your workbook

Read the teaching and complete workbook instructions. Choose, write or draw; Answer list offers larger controls. Trace code precisely and distinguish predictions from actual tests. Review designs, explanations and drawings with a grown-up.

Investigate random real values and review library use9 student pages · original artwork

Opening your PDF…

Swipe sideways across the worksheet on a small screen, or use “Answer list” for larger controls.

TAKE YOUR PRACTICE OFFLINE

3. Download the student worksheet

All 9 original A4 student pages, ready for pencil-and-paper practice. Choose Review Answers to check your work on this webpage.

Student worksheet only · PDF · 8.4 MiB · No answer key included

Download worksheet PDF ↓

TRY FIRST, THEN CHECK TOGETHER

Download the student worksheet →

4. Answers & guidance

Finished your try? Open the guide and compare one worksheet at a time. Your own words may be different and still explain the right idea.

Shown on this webpage only. There is no answer-key download, and this guide is left out when printing the page.

Show answers for all 9 worksheets

Worksheet 1

  1. Question 1: What kind of value does uniform return in these examples? a float that may have a fractional part
  2. Question 2: Which statement about a short sample is accurate? it need not contain either endpoint

Worksheet 2

  1. Question 3: What is the lower supplied bound? 2.5
  2. Question 4: What is the upper supplied bound? 5.5
  3. Question 5: Which variable stores the returned float? value

Worksheet 3

  1. Question 6: Interval check 2.5 True
  2. Question 7: Interval check 5.5 True
  3. Question 8: Interval check 2.49 False
  4. Question 9: Interval check 5.51 False

Worksheet 4

  1. Question 10: Which version stores the generated value in a named variable? A
  2. Question 11: Must independent runs of A and B display the same number? no, they make separate random calls
  3. Question 12: What does random.uniform(4, 4) return? 4.0 / 4

Worksheet 5

  1. Question 13: Which description fits a program library? reusable code and features available for programs
  2. Question 14: Why use a suitable library? it can save development time and reuse established work
  3. Question 15: Why still check a library-based program? the feature or its arguments may be used incorrectly
  4. Question 16: What does math.ceil(x) return for an ordinary finite float? the smallest integer greater than or equal to x
  5. Question 17: Write the complete line to import math. import math

Worksheet 6

  1. Question 18: Complete floor call math.floor(46.7)
  2. Question 19: Ceiling return for46.7 47
  3. Question 20: Floor output for1234.999 1234
  4. Question 21: Ceiling output for1234.999 1235
  5. Question 22: Random library name random
  6. Question 23: Possible integer list20to23 20, 21, 22, 23 / 20,21,22,23

Worksheet 7

This page introduces the activity. There are no marked responses on this sheet.

Worksheet 8

  1. Question 24: Use the linked uniform documentation or identify the provided-source reading route. Write a complete program importing random, generating a float with bounds 2.5 and 5.5 and storing or directly outputting its return. Explain the arguments, result type and endpoint caveat. Predict the interval, then record five actual returned values or mark execution Pending; do not invent a sample. Compare uniform(4, 4) with randint(4, 4). If working with a partner, discuss work balance, leading/supporting roles and any disagreement and resolution; otherwise reflect individually and mark peer exchange Pending. Keep source, notes, evidence and one next step. Valid import random, call random.uniform(2.5,5.5), float return stored/printed; expected documented interval with upper endpoint inclusion dependent on floating-point rounding. A float may be integral-valued. Five genuine sample values and checks or truthful Pending, no proof of endpoint appearance or perfect frequencies from short sample. uniform(4,4) returns float4.0; randint(4,4) returns int4. Valid documentation title/URL/actual date or provided-reading route; genuine partner balance/roles/disagreement/resolution or individual review with Pending. Full source and actual observations, corrections/retests and next step; no invented execution. Grown-up review; personal evidence is required.

Worksheet 9

  1. Question 25: Build a short evidence portfolio for all six page 7 skills using your own work from this unit. Include at least one complete math example and one random example; the supplied original C06 toolkit and station picker may support your review. Identify imports, function arguments, returned values and how each is stored, output or used. Explain one earlier error, how it was resolved or what help remains needed, and one way to reuse a previous program in a future task. Cite source files, test records and actual results or Pending; explain your own contribution and a clear next step. Evidence addresses all six skills: definition, purpose, suitable library identification, valid import, call/arguments and returned-value use. Coherent complete math/random examples, appropriate claims: math.pi constant, floor/ceil int rules, randint inclusive, uniform float/caveat. C06 math toolkit includes custom circle_area return and output; station picker returns a mapped message then caller prints it. Distinguish reading provided code from learner execution. Cite actual source/test/evidence or Pending, explain a real correction/support need, help used, own contribution, future reuse and next step. No numerical self-rating, fabricated peer confirmation or hardware/GUI performance required. Grown-up review; personal evidence is required.
Back to my workbook ↑

Curriculum & workbook reference

Computing for your homeschool day

Explore Investigate random real values and review library use with this free Grade 8 Computing lesson. Read one idea together, try the fillable workbook and return to review at your own pace. Download the same student worksheet PDF for pencil-and-paper practice.

Fit learning around your family’s day. There is no timer and no sign-up is needed to use the lesson. An optional account saves your lesson position and completion across devices. Workbook responses and drawings stay in this tab; save a copy of your responses before leaving.

Understand your results

Closed answers are checked in your browser. Drawings and written explanations need grown-up review and are shown separately from the automatic score. Check your work, then use “Retry answers to practise” to revisit mistakes while keeping correct responses.

Choose Review Answers after trying the activity. The guide stays on the webpage; the worksheet download contains only the student pages.

For programme background, visit the Cambridge Lower Secondary Computing overview. PaxaKids provides independent original companion practice.

Book page references identify the related teaching topic. File-management and responsible-data preparation are original PaxaKids material; orientation or contents pages are not presented as teaching citations for those skills. The explanations, characters, programs and exercises here are original PaxaKids companion practice. Practical tasks require the appropriate editor and, where applicable, suitable equipment. A design or paper trace is not a verified hardware result. Only completed, reviewed lessons are listed.

Explore the Cambridge Lower Secondary Computing curriculum for programme background. PaxaKids is an independent learning resource.