forked from adaptives/python-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython_control.py
More file actions
executable file
·40 lines (34 loc) · 1 KB
/
python_control.py
File metadata and controls
executable file
·40 lines (34 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/python
age = int(raw_input('Enter your age '))
#If else statements in Python
if age < 6:
print 'Hello little one'
elif age >= 6 and age < 10:
print 'Are you enjoying school?'
elif age >= 10 and age < 13:
print 'You are a Tween now'
elif age >= 13 and age < 20:
print 'Now you are officially a teenager'
else:
print 'Welcome to the real world'
#PYTHON DOES NOT HAVE A SWITCH STATEMENT
#Python while loop
number = age
fact = 1
st = 'abc'
while(age < 2):
fact = fact * age
age = age - 1
else:
print 'Python while loops have a redundant else'
print 'factorial of your age is: ', fact
#The for loop in Python essentially iterates over a sequence. This is very
#similar to the for(i : collection) loop in Java
print 'printing all integers from 1 to 5'
for i in range(1,5):
print i
#We can also have a stepping factpr in the iteration
print 'printing alternate numbers from 1 to 10'
for i in range(1,11, 2):
print i
#Python also has the break and continue statements which work just like in Java