seven said:
my answer : http://dpaste.com/hold/835640/
This course will become read-only in the near future. Tell us at community.p2pu.org if that is a problem.
Lets look at three components of many programming languages.
Three primary tools we will be working with are:
These three aspects are fundamental to programming in general and will be explored throughout this course.
Examples:
In Python, statements can take many forms and work with many programming elements such as names and operators.
Names are labels that point to a specific item in the computer's memory. Assignment statements are statements where we assign a name to a value, or memory location. Below, a_name points to the memory location of a_value.
>>> a_name = 'a_value'
Names, technically called identifiers, must start with an underscore (the "_" character) or a letter. Names can contain any sequence of letters, numbers, and underscores. Names cannot contain spaces or other special characters. Names are case sensetive, so 'Sunshine' and 'SUNSHINE' are two different names.
There are 33 reserved words that may not be used as names. The following table outlines Python's reserved words.
False | None | True | and | assert |
break | class | continue | def | del |
else | except | finally | for | from |
global | import | in | is | lambda |
nonlocal | not | pass | raise | return |
try | while | with | ||
Expressions typically return some result. The result can then be assigned a name.
In the following example, the expression on the right hand side will be evaluated and then assigned to the name to the left of the '=' assignment operator.
>>> total = 35.9 + 24.29 >>> total 60.19
Basic examples of expressions include arithmetic operations. Operators are included in expressions and consist of symbols such as:
+ | - | / | * | ** |
Here are some operators in action:
>>> 2 + 3 # Addition 5 >>> 3 - 2 # Subtraction 1 >>> 5 * 5 # Multiplication 25 >>> 10 / 5 # Division 2 >>> 3 ** 3 # Exponent 27
If you have any questions or difficulties post them here and we will work together to make sure that everyone has a positive learning experience. Please also post ideas and insights into these concepts. We can learn a lot from each others' perspectives and experience :-)
Answer to the unit 2 exercises
http://dpaste.com/hold/835550/
My answers to the exercises: http://pastebin.com/DtYKA0dy
excuse me i just find one exercise .. can anyone help me???
If you download the 'Python for Informatics' pdf from the link under Learning Resources in this task, the four exercises are on pages 28 and 29. edit: that link isn't working for me now. In the version at http://www.pythonlearn.com/book_006.pdf , the pages are numbered differently. Just look at the end of ch 2.
The exercises are in the book.pdf, chapter 2.15.
http://dpaste.com/hold/794084/
Below is my attempt:
I found it difficult locating where the exercises are.
If python 3 changes are added, it would be great.
exercise : http://dpaste.com/783038/plain/
completed
Hi Folks,
Here are my solutions:
http://dpaste.com/hold/745255/