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

Python_A5

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

Python_A5

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
You are on page 1/ 3

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

You might also like