how to save and run your python script later in Andriod and pc.
ON ANDRIOD FOLLOW THIS SIMPLE STEPS :
first of all download this app on playstore "python for andriod",
secondly open the app and type in your code or copy and paste, thirdly
on the top you will see a save button , click it input a name and save
it with ".py" example "pnt.py" .
Now tap the "Menu" button in the left top of the app select open click on the name of the file you want to test and run it.
Storing Values in Variables
A variable
is like a box in the computer’s memory where you can store a single
value. If you want to use the result of an evaluated expression later in
your program, you can save it inside a variable.
Assignment Statements
You’ll store values in variables with an assignment statement. An assignment statement consists of a variable name, an equal sign (called the assignment operator), and the value to be stored. If you enter the assignment statement
spam = 42
, then a variable named spam
will have the integer value 42
stored in it.
Think of a variable as a labeled box that a value is placed in.
spam = 42 is like telling the program, “The variable spam now has the integer value 42 in it.”
For example, enter the following into the interactive shell:
1 >>> spam = 40
>>> spam
40
>>> eggs = 2 2 >>> spam + eggs
42
>>> spam + eggs + spam
82
③ >>> spam = spam + 2
>>> spam
42
A variable is initialized
(or created) the first time a value is stored in it 1. After that, you
can use it in expressions with other variables and values 2. When a
variable is assigned a new value ③, the old value is forgotten, which is
why
spam
evaluated to 42
instead of 40
at the end of the example. This is called overwriting the variable. Enter the following code into the interactive shell to try overwriting a string:
>>> spam = 'Hello'
>>> spam
'Hello'
>>> spam = 'Goodbye'
>>> spam
'Goodbye'
the
spam
variable in this example stores 'Hello'
until you replace it with 'Goodbye'
.
When a new value is assigned to a variable, the old one is forgotten.
Variable Names
Table 1-3 has examples of legal variable names. You can name a variable anything as long as it obeys the following three rules:
-
It can be only one word.
-
It can use only letters, numbers, and the underscore (
_
) character.
-
It can’t begin with a number.
Table 1-3. Valid and Invalid Variable Names
Valid variable names
|
Invalid variable names
|
---|
balance |
current-balance (hyphens are not allowed) |
currentBalance |
current balance (spaces are not allowed) |
current_balance |
4account (can’t begin with a number) |
_spam |
42 (can’t begin with a number) |
SPAM |
total_$um (special characters like $ are not allowed) |
account4 |
'hello' (special characters like ' are not allowed) |
Variable names are case-sensitive, meaning that
spam
, SPAM
, Spam
, and sPaM
are four different variables. It is a Python convention to start your variables with a lowercase letter.
This book uses camel-case for variable names instead of underscores; that is, variables
lookalikes
instead of looking_like_this
.
Some experienced programmers may point out that the official Python
code style, PEP 8, says that underscores should be used. I unapologetic ally prefer camel-case and point to “A Foolish Consistency Is
the Hobgoblin of Little Minds” in PEP 8 itself:“Consistency with the style guide is important. But most importantly: know when to be inconsistent—sometimes the style guide just doesn’t apply. When in doubt, use your best judgment.”
A good variable name describes the data it contains.
Imagine that you moved to a new house and labeled all of your moving
boxes as Stuff. You’d never find anything! The variable names
spam
, eggs
, and bacon
are used as generic names for the examples in this book and in much of
Python’s documentation (inspired by the Monty Python “Spam” sketch), but
in your programs, a descriptive name will help make your code more
readable.
Comments
The following line is called a comment.
# This program says hello and asks for my name.
Python ignores comments, and you can use them to
write notes or remind yourself what the code is trying to do. Any text
for the rest of the line following a hash mark (
#
) is part of a comment.
Sometimes, programmers will put a
#
in front of a line of code to temporarily remove it while testing a program. This is called commenting out code, and it can be useful when you’re trying to figure out why a program doesn’t work. You can remove the #
later when you are ready to put the line back in.
Python also ignores the blank line after the comment. You can add as many blank lines to your program as you want.
check out this Expressions
The print() Function
The
print()
function displays the string value inside the parentheses on the screen.
print('Hello world!')
print('What is your name?') # ask for their name
The line
print('Hello world!')
means “Print out the text in the string 'Hello world!'
.” When Python executes this line, you say that Python is calling the print()
function and the string value is being passed to the function. A value that is passed to a function call is an argument.
Notice that the quotes are not printed to the screen. They just mark
where the string begins and ends; they are not part of the string value.
Note
You can also use this function to put a blank line on the screen; just call
print()
with nothing in between the parentheses.
When writing a function name, the opening and
closing parentheses at the end identify it as the name of a function.
This is why you’ll see
print()
rather than print
Here is another program:
print "2 + 2 is", 2 + 2
print "3 * 4 is", 3 * 4
print "100 - 1 is", 100 - 1
print "(33 + 2) / 5 + 11.5 is", (33 + 2) / 5 + 11.5
And here is the output when the program is run:
2 + 2 is 4
3 * 4 is 12
100 - 1 is 99
(33 + 2) / 5 + 11.5 is 18.5
print "Something‚s rotten in the state of Denmark."
print " -- Shakespeare"
Output:
Something's rotten in the state of Denmark.
-- Shakespeare
print " -- Shakespeare"
Output:
Something's rotten in the state of Denmark.
-- Shakespeare
........................................................................................................................................
how to save and run your python script later in Android and pc.
ON ANDROID FOLLOW THIS SIMPLE STEPS :
first of all download this app on play store "python for android", secondly open the app and type in your code or copy and paste, thirdly on the top you will see a save button , click it input a name and save it with ".py" example "pnt.py" .
Now tap the "Menu" button in the left top of the app select open click on the name of the file you want to test and run it.
................................................................................................................................................................
Now test this code
# This is not quite true outside of USA
# and is based on my dim memories of my younger years
print "First Grade"
print "1 + 1 =", 1 + 1
print "2 + 4 =", 2 + 4
print "5 - 2 =", 5 - 2
print
print "Third Grade"
print "243 - 23 =", 243 - 23
print "12 * 4 =", 12 * 4
print "12 / 3 =", 12 / 3
print "13 / 3 =", 13 / 3, "R", 13 % 3
print
print "Junior High"
print "123.56 - 62.12 =", 123.56 - 62.12
print "(4 + 3) * 2 =", (4 + 3) * 2
print "4 + 3 * 2 =", 4 + 3 * 2
print "3 ** 2 =", 3 ** 2
print
# and is based on my dim memories of my younger years
print "First Grade"
print "1 + 1 =", 1 + 1
print "2 + 4 =", 2 + 4
print "5 - 2 =", 5 - 2
print "Third Grade"
print "243 - 23 =", 243 - 23
print "12 * 4 =", 12 * 4
print "12 / 3 =", 12 / 3
print "13 / 3 =", 13 / 3, "R", 13 % 3
print "Junior High"
print "123.56 - 62.12 =", 123.56 - 62.12
print "(4 + 3) * 2 =", (4 + 3) * 2
print "4 + 3 * 2 =", 4 + 3 * 2
print "3 ** 2 =", 3 ** 2
save on your android and run it.
......................................................................................................................
Now for PC follow this simple step:
download python 2.7 latest version on your pc and install it.
now search your for "IDLE(python GUI)" open the app click on "file" >> Select "New Windows" >>
and an editor will pop-up.
Now type your code or copy and paste, ?Now click "Run" on the top of the >>Select "Run Module"
click "Ok" type a name and end it with .py example; lany.py and click save.
the file will be saved in the python directory you can click on it later to run it again from the python directory.
.......................................................................................................................................................
HAPPY CODING SEASON
0 comments:
Post a Comment