You are on page 1of 7

http://www.codeskulptor.

org/
http://www.programiz.com/python-programming/examples
Command LineL:

Python 2.7.9 (default, Dec 10 2014, 12:24:55) [MSC v.1500 32 bit (Intel)] on win
32
Type "help", "copyright", "credits" or "license" for more information.
>>> print "welcome"
welcome
>>> a=100
>>> print a
100

>>> a=100
>>> b=200
>>> c=a+b
>>> print c
300
>>>

GUI Module:

Program1:

print (raw_input('enter input'))


test123=input('enter input');
print test123

output:
>>>
enter input100
100
enter input400
400

Program2:
name=raw_input('enter input your namr:')
print name
deg=raw_input('enter input deg:')
print deg
dept=raw_input('enter input dept:')
print dept
college=raw_input('enter input college:')
print college
cellno=raw_input('enter input cellno:')
print cellno

output:
>>>
enter input your namr:k venkateswarlu
k venkateswarlu
enter input deg:asst.professor
asst.professor
enter input dept:cse
cse
enter input college:git
git
enter input deg:9492534181
9492534181

Program3:
name=raw_input('enter input your namr:')
s=raw_input('enter input your surnamr:')

print name + " " + str(s)

output:
>>>
enter input your namr:venkat
enter input your surnamr:K
venkat K

Program4:
a = 20
b = 30
c = 0
c = a+b
print "line1 - value of c is", c
c= a-b
print "line2 - value of c is", c

c = a*b
print "line3 - value of c is", c
c= a/b
print "line4 - value of c is", c
c= a%b
print "line5 - value of c is", c

a = 2
b = 3
c = a**b
print "line6 - value of c is", c

a = 10
b = 5
c = a//b

print "line6 - value of c is", c

output:
>>>
line1 - value of c is 50
line2 - value of c is -10
line3 - value of c is 600
line4 - value of c is 0
line5 - value of c is 20
line6 - value of c is 8
line6 - value of c is 2

Program5:

a = int (raw_input('Enter any number1:'))


b = int (raw_input('Enter any number2:'))

c = 0;
c = a+b
print "line1 - value of c is", c
c= a-b
print "line2 - value of c is", c

c = a*b
print "line3 - value of c is", c
c= a/b
print "line4 - value of c is", c
c= a%b
print "line5 - value of c is", c

a = 2
b = 3
c = a**b
print "line6 - value of c is", c

a = 10
b = 5
c = a//b

print "line6 - value of c is", c

output:

Enter any number1:10


Enter any number2:5
line1 - value of c is 15
line2 - value of c is 5
line3 - value of c is 50
line4 - value of c is 2
line5 - value of c is 0
line6 - value of c is 8
line6 - value of c is 2

program6:

a=0
while a < 5:
a += 1 # Same as a = a+1
print (a)

output:
>>>
1
2
3
4
5

program7:

for i in range(10):
print i,
print
for i in range(10,20):
print i,

list=[1,2,3,4,5,6]
for j in list:
print j
print list

output:

0
10 1
2
3
4
5
6
[1, 2, 3, 4, 5, 6]
11 1
2
3
4
5
6
[1, 2, 3, 4, 5, 6]
12 1
2
3
4
5
6
[1, 2, 3, 4, 5, 6]

Program8:

list = [2,4,6,8]
sum =0
for num in list:
sum = sum + num
print ("The sum is: %d" % sum)

ouput:
>>>
The sum is: 20

program9:

a = 1
b = 1
for c in range(1,10):
print (a)
n = a + b
a = b
b = n
print ("")

output:

2
3

13

21

34

program10:

def changeme( var):


" This changes a paases list into this function"
var=var+5
print var
return
var =10
changeme(var)
print var

output:
>>>
15
10

program11:

dict = {}
dict ['one'] = "this is One"
dict [2] = "this is two"
tinydict = {'name':'Venkat','code':143,'dept': 'sal'}

print dict['one']
print dict[2]
print tinydict
print tinydict.keys()
print tinydict.values()

output:
>>>
this is One
this is two
{'dept': 'sal', 'code': 143, 'name': 'Venkat'}
['dept', 'code', 'name']
['sal', 143, 'Venkat']

program12:

def calculateBill(prevUnits,currUnits):
c=currUnits - prevUnits
if c<100:
billAmt=c*2
elif c>100 and c<200:
billAmt=c*3
elif c>200 and c<300:
billAmt=c*5
elif c>300 and c<400:
billAmt=c*7
else:
billAmt=c*10

return billAmt

print "Enter previous and Current Units"


prUnits=input("Enter Previous month eading")
crUnits=input("Enter Current month Reading")

print "Enter consumer details"


consName=raw_input("Enter Name")

consmId=input("Enter Consumer Number")

consMonth=raw_input("Enter Month")

consYear=raw_input("Enter Year")

print "The bill Details are"


print "Consumer Name",consName
print "Consumer Id",consmId

print "Total Bill Amount is", calculateBill(prUnits,crUnits)

print "payment due date","30th " + consMonth + "," + consYear

output:

>>>
Enter previous and Current Units
Enter Previous month eading500
Enter Current month Reading750
Enter consumer details
Enter NameK Venkateswarlu
Enter Consumer Number1435
Enter MonthNov
Enter Year2015
The bill Details are
Consumer Name K Venkateswarlu
Consumer Id 1435
Total Bill Amount is 1250
payment due date 30th Nov,2015

program13:

# Open a file
fo = open("Test.txt", "wb")
print "Name of the file: ", fo.name
print "Closed or not : ", fo.closed
print "Opening mode : ", fo.mode
print "Soft space flag : ", fo.softspace
output:
>>>
Name of the file: Test.txt
Closed or not : False
Opening mode : wb
Soft space flag : 0

# Program to display the Fibonacci sequence up to n-th term where n is provided by


the user

# take input from the user


nterms = int(input("How many terms? "))

# first two terms


n1 = 0
n2 = 1
count = 2

# check if the number of terms is valid


if nterms <= 0:
print("Plese enter a positive integer")
elif nterms == 1:
print("Fibonacci sequence:")
print(n1)
else:
print("Fibonacci sequence:")
print(n1)
print(n2)
while count < nterms:
nth = n1 + n2
print(nth)
# update values
n1 = n2
n2 = nth
count += 1

You might also like