0% found this document useful (0 votes)
110 views3 pages

Python Basics for Pet Monster Rescue

The document outlines a programming mission to create a Pet Monster Rescue program that matches people with ideal pets using logical reasoning and Python coding. It introduces key programming concepts such as strings, integers, and variables, providing examples and exercises for each. Additionally, it emphasizes the importance of meaningful variable names and proper syntax in Python.

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)
110 views3 pages

Python Basics for Pet Monster Rescue

The document outlines a programming mission to create a Pet Monster Rescue program that matches people with ideal pets using logical reasoning and Python coding. It introduces key programming concepts such as strings, integers, and variables, providing examples and exercises for each. Additionally, it emphasizes the importance of meaningful variable names and proper syntax in Python.

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

Prepare for the Pet Monster Rescue Mission


It is time for a new programming mission. You are going to
create a program for the Pet Monster Rescue. Pet Monster
Rescue is a group that finds loving homes for monsters.
The program will match people to their ideal pet. It will ask
questions, store answers, and use logic to determine if there is a
monster that meets the person's needs.
To successfully complete the mission, you must think logically.
This is a valued trait in a programmer. People who are logical:
• carefully watch what is happening
• pay attention to details
• outline ideas clearly by breaking them down into parts
• study facts to determine if a statement is True or False

To complete the task, aside from being logical, you also need to know more about Python.
Follow the instructions to write code to learn about strings, integers, and variables.

Open the Python Shell


1.  Open IDLE (Python).

 View the Python Shell:

What is a String?

A string is text. It can be a word, phrase, or sentence. In Python, str is short for string.
To learn about strings, type each line of code and then press ENTER to study the output.
2.  A string must have brackets and quotes around it:
>>> print('a string is text')

 A string can have single or double quotes around it:


>>> print("it must have quotes")

 Use double quotes if you want to use an apostrophe in the string:


>>> print("let's code")
A string can have
either double or
 Use single quotes if you want to show someone talking in the string: single quotes
around it.
>>> print('he said "okay"')

 If you want both, you need to put a slash before the apostrophe:
>>> print('she said "let\'s start now"')

 Be logical. Study the above code to determine how to complete each task:
 it's fun  I said "wow"  I said "wow, it's fun"

Copyright © TechnoKids Inc. 23 TechnoPython | Python


Session 2

What is an Integer?

An integer is a whole number such as 10 or 42. In Python, int is short for integer.
To learn about integers, type each line of code and then press ENTER to study the output.
3.  An integer must have brackets around it:
>>> print(5)
A string cannot
5
be calculated
but an integer
 An integer can be used to calculate values: can.
>>> print(6+4)
10

 If you put quotes around a number, it becomes a string:


>>> print('6+4')
6+4

 Think logically! Study the above code to determine how to complete each task:
 show 10  calculate 3+2  show the equation 3+2=

What is a Variable?

A variable stores a value that can change. It can be text, a number, or a list of items.
To learn about variables, type each line of code and then press ENTER to study the output.
4.  A variable has two parts – name and value:
>>> name=('value')
>>> print(name)
value
The print command lets you show
the stored value of the variable.

 The variable value can change:


>>> name=('Student Name')
>>> print(name)
Student Name
The variable now has a new
value. It is your name.

 The variable is case specific. Type a capital N in the variable name:


>>> print(Name)
Traceback (most recent call last):
File "<pyshell#11>", line 1, in <module>
print(Name)
NameError: name 'Name' is not defined
Always check your spelling. The case of the letters matter.
Python treats NAME, Name, and name as different variables.

 A variable can store a string or integer. Think logically! Show the value using print:
 weather=('sunny')  mood=('happy')  count=(5)

Copyright © TechnoKids Inc. 24 TechnoPython | Python


Session 2

Input a Variable Value

Sometimes the programmer will input a value for a variable. However, other times the user can
input a value. This is done using the input command.

5.  Ask the user a question:


>>>food=input('What food do you like?')
What food do you like?pizza

Type in an answer.

 The input is stored by the computer:


>>> print(food)
pizza

 The input can be used to have the program talk to the user:
>>> print('I also like', food)
I also like pizza

 Think logically! Study the above code to determine how to ask each question:
 What music do you like?  What is your age?  Do you like sports?

Name a Variable

A variable name must be meaningful. It should describe its purpose. There are rules you must
follow when assigning a variable name. To learn them, type each line of code and then press
ENTER. Does the variable name follow the rules, or do you get an error?

6.  A variable name must start with a letter or underscore, but not a symbol or number.
Put a checkmark ✓ beside the variable names that work:

 color=('red')  2color=('red')  _color=('red')  !color=('red')

If a variable name does not follow the rules


you will get a SyntaxError: invalid syntax error.

 A variable name must be one word with no spaces.


Put a checkmark ✓ beside the variable names that work:

 game_score=(0)  game score=(0)  gamescore=0

 A variable name cannot be a Python keyword. Keywords are color-coded.


Put a checkmark ✓ beside the variable name that works:

 answer=('yes')  True=('yes')  import=('yes')

Python keywords are a colored. They can


be orange or purple. Use this as a clue.

Close the Python Shell

Copyright © TechnoKids Inc. 25 TechnoPython | Python

Common questions

Powered by AI

The print function assists debugging by displaying variable values and outputs of expressions, making it easier to trace and inspect code execution and logic visually. It helps identify incorrect values or statement forms by providing real-time data and variable state feedback during development .

Understanding data types like strings and integers is crucial because they determine how data is stored, manipulated, and utilized in programs. Strings represent text data, while integers represent whole numbers capable of arithmetic operations without quotes, as they are evaluated as numbers rather than text .

Logical thinking aids programming in breaking down tasks into systematic steps, predicting outcomes of code, verifying conditions as true or false, and organizing inputs and outputs effectively to match persons to ideal pets according to their needs. It ensures that solutions are well-structured and clear .

Successfully completing the Pet Monster Rescue programming mission requires logical thinking as it enables programmers to carefully watch events, pay attention to details, outline ideas clearly by breaking them down into parts, and study facts to determine if a statement is true or false .

Input commands significantly enhance user interaction by allowing real-time data entry. They enable the program to solicit data directly from users, process this input, and provide responses, thus making the program adaptive and user-focused, aligning functionalities with users' needs dynamically .

Variables enhance the functionality by allowing the storage of changing values, whether text, numbers, or lists. They serve as placeholders for data inputs and outputs, which can dynamically affect a program's behavior by updating or storing user input or results of calculations for later use .

Constraints on naming variables include starting with a letter or underscore, avoiding symbols and numbers at the beginning, not using spaces, and avoiding Python reserved keywords which are color-coded in the environment. Names must be descriptive to ensure clarity of their purpose .

Single and double quotes determine the boundaries of text strings, allowing embedded quotes without confusion. Escape characters, like backslashes, enable inclusion of both quote types within strings by bypassing their typical functional roles, thereby preserving textual integrity while avoiding syntax errors .

Programmers should check for syntax errors to ensure program stability and correctness. Common mistakes include starting variable names with numbers or symbols, using spaces, and using reserved keywords as names, which can lead to SyntaxError. Recognizing and correcting these errors ensures smooth program execution .

Case sensitivity impacts variable naming in Python such that 'name', 'Name', and 'NAME' are recognized as distinct variables. This case specification means incorrect casing during code execution can lead to errors like NameError, highlighting the importance of accurately maintaining variable naming conventions .

You might also like