LightReader

Chapter 21 - Chapter 21 — The Final Python Program

The computer screen brightened.

The system was almost completely unlocked.

The cursor blinked slowly.

_

Pran leaned forward.

The robot stood proudly beside the system panel.

[^_^]

/| |\

/ \

A new message appeared.

PYTHON MODULE PROGRESS: 95%

FINAL PROGRAM MODULE ACTIVATED

Pran smiled.

"So this is the final challenge."

The computer displayed another message.

COMBINE ALL PREVIOUS SYSTEMS

BUILD A COMPLETE PROGRAM

Pran reviewed everything he had learned in Python.

The program would need several parts:

input from the user

random numbers

a loop to keep the game running

conditions to check answers

The computer displayed the plan.

PROGRAM TYPE: NUMBER GUESSING GAME

Pran nodded.

"That sounds perfect."

The system displayed the first step.

import random

Pran recognized this immediately.

The program would use Python's random module.

Next, the program generated a secret number.

secret = random.randint(1,10)

This creates a number between 1 and 10.

The player must guess it.

The next step was creating a loop.

guess = 0

The loop would continue until the player guessed correctly.

The computer displayed the full program.

import random

secret = random.randint(1,10)

guess = 0

print("Welcome to the guessing game!")

while guess != secret:

guess = int(input("Guess the number (1-10): "))

if guess < secret:

print("Too low!")

elif guess > secret:

print("Too high!")

else:

print("Correct! You guessed the number!")

Pran typed the program carefully.

Then he pressed run.

The computer displayed:

Welcome to the guessing game!

Guess the number (1-10):

Pran typed:

4

The computer responded.

Too low!

He tried again.

7

The computer answered.

Too high!

He tried once more.

6

The screen printed:

Correct! You guessed the number!

Pran leaned back and smiled.

"That actually feels like a real program."

And it was.

This program used many of the core ideas of programming:

• variables• input• loops• conditions• random numbers

Programs do not need to be huge to be useful.

Even small programs teach powerful ideas.

The robot jumped happily.

[^O^]

/| |\

/ \

Another system message appeared.

FINAL PROGRAM VERIFIED

Then another.

PYTHON MODULE COMPLETE

Pran blinked.

"Complete?"

The computer screen flashed brightly.

A final message appeared.

CONGRATULATIONS PROGRAMMER

Pran stared at the words.

Programmer.

That word felt different now.

Not mysterious.

Not impossible.

Just a person who understands how to talk to computers.

The system printed one more message.

YOU HAVE MASTERED THE FOUNDATIONS OF PYTHON

The robot bowed dramatically.

[^_^]

/| |\

/ \

Then the screen dimmed slightly.

But before shutting down, a final message appeared.

THIS IS ONLY THE BEGINNING

Pran nodded slowly.

Programming wasn't just about learning a language.

It was about learning how to solve problems.

The cursor blinked one more time.

_

Waiting.

Ready for the next adventure.

More Chapters