0% found this document useful (0 votes)
21 views4 pages

Python A6

The document outlines a programming mission to create a Pet Monster Rescue program using Python. It provides step-by-step instructions on how to use strings and variables to interact with users, including asking for their name and describing their home. Additionally, it offers coding challenges to enhance the program's functionality and readability.

Uploaded by

biji
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views4 pages

Python A6

The document outlines a programming mission to create a Pet Monster Rescue program using Python. It provides step-by-step instructions on how to use strings and variables to interact with users, including asking for their name and describing their home. Additionally, it offers coding challenges to enhance the program's functionality and readability.

Uploaded by

biji
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Session 2

About the Pet Monster Rescue Mission


In this programming mission, you design a program for the Pet Monster Rescue. It is a group that
helps people adopt pet monsters in need of loving homes.

To start, you will apply what you know about strings and
variables to inform others about the Pet Monster Rescue. Be logical. Write the
To personalize the adoption process, you will ask questions. program one part at a
time. Test it as you go.
To interact with the user, you will use the following code:

CODE PURPOSE
print('Type text here.') show text
print("Let's use an apostrophe.") use double quotes around text to show an apostrophe
name=('value') create a variable and set the value to text
name=input('What is the question?') create a variable that has the user input the value
print('Type text', name) make a sentence that includes the variable value
print('Type text', name+'.') remove the space between the variable value and text

Open IDLE and Create a New File


1.  Open IDLE (Python).

 From the File menu, select New File.

 From the File menu, select Save.


Type monster as the file name. Click Save.

Inform Others About the Pet Monster Rescue


2.  A comment is a note to the programmer. Organize your code:
#about

Comments divide a program into logical parts.

 Tell others about the Pet Monster Rescue program:


#about
print('Answer questions to find a pet.')
print("Let's get started.")

Use "double quotes" if you have an apostrophe in a word.

3.  From the File menu, select Save or press CTRL + S.

 From the Run menu, select Run Module.

 Read the text:


Answer questions to find a pet.
Let's get started.
>>>
 Close the Python Shell.

Copyright © TechnoKids Inc. 26 TechnoPython | Python


Session 2

Create a Variable to Store the Value 'Pet Monster Rescue'

4.  At the top of the program add a section for variables:


#variables

#about
print('Answer questions to find a pet.')
print("Let's get started.")

 Create a variable to store the name of the place:


#variables
place=('Pet Monster Rescue')

 Use the variable to show a title in the about section:


#variables
place=('Pet Monster Rescue')
A variable can save you
time and make things
#about
easier. You can use it
print(place) again and again.
print('Answer questions to find a pet.')
print("Let's get started.")

 Save the changes. From the Run menu, select Run Module.
 When done, close the Python Shell.

Use the Variable Value in Sentences

5.  You can include the value of a variable in a sentence:


#about
print(place) The comma adds a space
print('Welcome to', place) between the text and the
print('Answer questions to find a pet.') value of the variable.
print("Let's get started.")

 Apply your skills to view the changes.


Pet Monster Rescue
Welcome to Pet Monster Rescue
Answer questions to find a pet.
Let's get started.
>>>

6.  You can include the value of a variable in the middle of a sentence:


print("Let's get started.")
print('Thanks for visiting', place, 'where pets are family.')

The program will show a syntax error if you


forget the commas around the variable.

 Apply your skills to view the changes.

Copyright © TechnoKids Inc. 27 TechnoPython | Python


Session 2

Ask a Question to Get to Know the Pet Owner

7.  You can have the user input the value of a variable. Ask the person's name using input:
#variables
place=('Pet Monster Rescue')

#about
print(place)
print('Welcome to', place)
print('Answer questions to find a pet.')
print("Let's get started.")
print('Thanks for visiting', place, 'where pets are family.')

#pet owner
name=input('What is your name?')

 The answer can be used to have the program talk to the user:
#pet owner
name=input('What is your name?')
print('Hello', name)

 Apply your skills to view the changes. Type the answer to the question:
Pet Monster Rescue
Welcome to Pet Monster Rescue
Answer questions to find a pet.
Let's get started.
Thanks for visiting Pet Monster Rescue where pets are family.
What is your name?Alex
Hello Alex
>>>

To make it easier to read, you need a space between the question and
answer. You should also add a period after the name in the greeting.

Make the Text Easier to Read

8.  Add a space between the question and the answer:


#pet owner
name=input('What is your name? ') add a space before the
print('Hello', name) quote

 To add a period to a sentence you must use a plus sign:


#pet owner
add a plus sign + to
name=input('What is your name? ') remove space between a
print('Hello', name+'.') variable and text

A comma before or after a variable creates a space.


A plus sign before or after a variable removes any space.

 Apply your skills to view the changes.

Copyright © TechnoKids Inc. 28 TechnoPython | Python


Session 2

Ask Another Question

9.  Ask the person to describe their home:


#pet owner
name=input('What is your name? ')
print('Hello', name+'.')
home=input('Is your home calm or busy? ')
print('Okay. Your home is a', home,'place.')

 Apply your skills to view the changes. Type the answers to each question:
Pet Monster Rescue
Welcome to Pet Monster Rescue
Answer questions to find a pet.
Let's get started.
Thanks for visiting Pet Monster Rescue where pets are family.
What is your name? Alex
Hello Alex.
Is your home calm or busy? busy
Okay. Your home is a busy place.
>>>

Take the Coding Challenge

10. You know lots about how to show text on the screen, store variables, ask questions, and
use the answers in a sentence. Pick a challenge to improve the program.

 Add a decorative line around the title in the about section. For example:
-*-*-*-*-*-*-*-*-*-
Pet Monster Rescue
-*-*-*-*-*-*-*-*-*-
HINT: You need to add two print lines. One above and one below the title.

 Add a sentence after the welcome greeting:


You're going to love your new pet.
HINT: It has an apostrophe. You need double quotes around the string.

 Add a comma after the variable value Pet Monster Rescue:


Thanks for visiting Pet Monster Rescue, where pets are family.
HINT: You need to use a plus sign + after the variable.

 Ask the question How many pet monsters do you own?


Reply So you have _ .
How many pet monsters do you own? 2
So, you have 2.

HINT: You need to make a variable. Name it and use the command input to ask the question.

When testing a program, you can kill or stop


running it. To do this, click Close X. Click OK.

Close Python

Copyright © TechnoKids Inc. 29 TechnoPython | Python

You might also like