a

Friday 17 June 2016





I am here to help you all. This site will provide you with free Python codes. All the codes are written

in Python 2.7.11 version .

1. Program to obtain numbers from user and store it in a list. 




 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
a=''

list=[]

while a!='done':

    a=raw_input('Enter a number:  ')

    if a!='done':

        list.append(a)

print'List =',list
output:  
Enter a number:  2
Enter a number:  5
Enter a number:  6
Enter a number:  4
Enter a number:  done
List = ['2', '5', '6', '4']

2. Program to open a Text file and print data as output.
    (Hint: if text file is not present at Python folder input the path along with file name)

1
2
3
4
5
var1=raw_input('Enter the file name:  ')

f=open(var1,'r')

print f.read()




output:
Enter the file name:

3.


 

No comments:

Post a Comment