In [1]:

```
age=int(raw_input("Enter your age: "))
if(age>12 and age<20):
print "you are a teen-aged person. good!"
```

In [2]:

```
age=int(raw_input("Enter your age: "))
if(age<0):
print "I am sorry!"
print "age can never be negative"
if(age>12 and age<20):
print "you are a teen-aged person. good!"
```

In [1]:

```
big=float
a, b, c=[float(x) for x in raw_input("Enter three floating-point numbers: ").split()] #taking input in single line separated by white space
big=a
if(b>big):
big=b
if(c>big):
big=c
print "Largest of the three numbers =", big
```

In [3]:

```
age=int(raw_input("Enter your age: "))
if(age>12 and age<20):
print "you are a teen-aged person. good!"
else:
print "you are not a teen-aged person."
```

In [2]:

```
years=float(raw_input("Enter your age in years: "))
if(years<0):
print "I am sorry! age can never be negative"
else:
secs=years*365*24*60*60
print "You have lived for %.4g seconds" %(secs)
```

In [3]:

```
age=int(raw_input("Enter your age: "))
if(age>12 and age<20):
print "you are a teen-aged person. good!"
else:
if(age<13):
print "you will surely reach teen-age."
else:
print "you have crossed teen-age!"
```

In [1]:

```
n=int(raw_input("How many integers to be displayed: "))
for i in range(n):
print i
```

In [1]:

```
Sum=0
sum_of_squares=0
for i in range(2, 31, 2):
Sum+=i
sum_of_squares+=i*i
print "Sum of first 15 positive even numbers =", Sum
print "Sum of their squares =", sum_of_squares
```

In [2]:

```
Sum=0
sum_of_squares=0
for i in range(30, 0, -2):
Sum+=i
sum_of_squares+=i*i
print "Sum of first 15 positive even numbers =", Sum
print "Sum of their squares =", sum_of_squares
```

In [3]:

```
i=1
for i in range(i, 11):
print i*5,
```

In [4]:

```
n=int(raw_input("Enter the number of lines: "))
for p in range(1, n+1):
for q in range(1, n-p+1):
print "\t",
m=p
for q in range (1, p+1):
print "\t", m,
m+=1
m=m-2
for q in range(1, p):
print "\t", m,
m-=1
print ''
```

In [5]:

```
n=int(raw_input("How many integers to be displayed: "))
i=0
while i<n:
print i
i+=1
```

In [6]:

```
Sum=0
count=0
print "Enter the marks, -1 at the end..."
marks=int(raw_input())
while marks!=-1:
Sum+=marks
count+=1
marks=int(raw_input())
average=Sum/count
print "The average is", average
```

In [7]:

```
decimal=0
position=0
binary=int(raw_input("Enter the binary number: "))
while binary:
digit=binary%10
decimal+=digit<<position
binary/=10
position+=1
print "Its decimal equivalent =", decimal
```

In [2]:

```
n=int(raw_input("How many integers to be displayed: "))
i=0
while 1: #do while loop
print i
i+=1
if i>=n:
break
```

In [3]:

```
while 1: #do-while loop
inchar=raw_input("Enter your sex (m/f): ")
if(inchar=='m' or inchar=='f'):
break
if inchar=='m':
print "so you are male. good!"
else:
print "so you are female. good!"
```

In [5]:

```
rev=0
num=int(raw_input("Enter the number: "))
n=num
while 1:
digit=num%10
rev=rev*10 + digit
num/=10
if num==0:
break
print "Reverse of the number =", rev
if n==rev:
print "The number is a palindrome"
else:
print "The number is not a palindrome"
```

In [4]:

```
Sum=0
count=0
print "Enter the marks, -1 at the end..."
while 1:
marks=int(raw_input())
if marks==-1:
break
Sum+=marks
count+=1
average=Sum/count
print "The average is", average
```

In [5]:

```
ch=raw_input("Enter your sex (m/f): ")
if ch=='m':
print "So you are male. good!"
elif ch=='f':
print "So you are female. good!"
else:
print "Error: Invalid sex code!"
```

In [1]:

```
print "------------------Basic Calculator------------------"
print "Choose an option:"
print "Add"
print "Subtract"
print "Multiply"
print "Divide"
ch=raw_input()
num1, num2=[int(x) for x in raw_input("Enter the value of the operands: ").split()]
if ch=='1':
print num1+num2
elif ch=='2':
print num1-num2
elif ch=='3':
print num1*num2
elif ch=='4':
print num1/num2
else:
print "Incorrect choice: "
```

In [6]:

```
total=0
while 1:
num=int(raw_input("Enter a number (0 to quit): "))
if num==0:
print "end of data entry."
break
if num<0:
print "skipping this number."
continue
total+=num
print "Total of all +ve numbers is ", total
```

In [2]:

```
total=0
while 1:
num=int(raw_input("Enter a number (0 to quit): "))
if num==0:
print "end of data entry."
print "Total of all +ve numbers is", total #no goto in python
break
if num<0:
print "skipping this number."
continue
total+=num
```

In [3]:

```
age=int(raw_input("Enter your age: "))
if(age>12 and age<20):
pass
print "you are a teen-aged person. good!"
```

In [1]:

```
myage=25
print "Hi! my age is ", myage
yourage=int(raw_input("What is your age? "))
if myage==yourage:
print "We are born on the same day. Are we twins!"
```

In [4]:

```
l1=int(raw_input("Enter the lower limit: "))
l2=int(raw_input("Enter the higher limit: "))
print "The prime numbers between", l1, "and", l2, "are: ",
for i in range(l1, l2+1):
if i<=3:
print i,"\t",
else:
for j in range(2, i/2+1):
if(i%j==0):
break
if(i%j==0):
continue #no goto
print i, "\t",
```