Professional Documents
Culture Documents
x
With Linux :-D
What we learn is Python 2.x. All the linux distros use Python 2.x.
To get the python version of your pc, open the terminal and enter
$
python
>> well learn Command-line mode. Read the given notes and learn
how to use the interactive mode.
60
hihi
$ python code.py
$ python code.py
Enter input : (1+5)*10
(1+5)*10
[0,4,8,12,16]
Arithmetic - % , ** , //
Comparison - <>
Assignment - **= , //=
Logical and, or, not
Membership in , not in
Identify is , is not
Conditional Statements
if(bla bla):
Do this
else:
Do something
LOOPS
While loop
while expression:
statement(s)
For loop
for <iterating_variable> in <sequence>
statement(s)
**
*****
*****
*****
*****
*****
***
****
*****
x=0
y=0
while x<5:
y=0;
while y<x+1:
print "*",
y+=1
print ""
x += 1
The syntax range is useful when moving to for loops and Lists
>> range(5)
[0,1,2,3,4]
>> range(2,6)
[2,3,4,5]
>> range(0,10,2)
[0,2,4,6,8]
for loops
Write a code to Take a String by input,
then print the letters of the input one by one.
Eg: Input : Indika
Output : I n d i k a
Utopian tree!
The Utopian tree goes through 2 cycles of growth every
year. The first growth cycle of the tree is during the
monsoon season when it doubles in height. The second
growth cycle is during the summer when it increases in
height by 1 meter. If a new Utopian tree sapling of height
1 meter is planted just before the onset of the monsoon
season, can you find the height of the tree after N cycles?
samples :
Input : 3 Output : 6
Input : 4 Output : 7
Source : www.hackerrank.com