1649321220_PYTHON
1649321220_PYTHON
I YEAR II SEMESTER
2018 - 19
Prepared by:
Smt.CH.Suguna Latha
Assistant Professor
Sri. T.Balaji
Assistant Professor
Institute Vision:
To be a leading institution of engineering education and research, preparing students for leadership in
their fields in a caring and challenging learning environment.
Institute Mission:
VISION
MISSION
➢ To provide an academic environment in which students are given the essential resources for
solving real-world problems and work in multidisciplinary teams.
➢ To impart value based education and research among students, particularly belonging to rural
areas, for their sustained growth in technological aspects and leadership.
➢ To collaborate with the industry for making the students adoptable to evolving changes in
Information Technology and related areas.
PEO1:To exhibit analytical skills in modeling and solving computing problems by applying
mathematical, scientific and engineering knowledge and to pursue their higher studies.
PEO3: To address industry and societal needs for the growth of global economy using emerging
technologies by following professional ethics.
.
PROGRAM OUTCOMES (POs)
1. Engineering knowledge: Apply the knowledge of mathematics, science, engineering fundamentals, and
an engineering specialization to the solution of complex engineering problems.
2. Problem analysis: Identify, formulate, review research literature, and analyze complex engineering
problems reaching substantiated conclusions using first principles of mathematics, natural sciences,
and engineering sciences.
3. Design/development of solutions: Design solutions for complex engineering problems and design
system components or processes that meet the specified needs with appropriate consideration for the
public health and safety, and the cultural, societal, and environmental considerations.
4. Conduct investigations of complex problems: Use research-based knowledge and research methods
including design of experiments, analysis and interpretation of data, and synthesis of the information to
provide valid conclusions.
5. Modern tool usage: Create, select, and apply appropriate techniques, resources, and modern
engineering and IT tools including prediction and modeling to complex engineering activities with an
understanding of the limitations.
6. The engineer and society: Apply reasoning informed by the contextual knowledge to assess societal,
health, safety, legal and cultural issues and the consequent responsibilities relevant to the professional
engineering practice.
7. Environment and sustainability: Understand the impact of the professional engineering solutions in
societal and environmental contexts, and demonstrate the knowledge of, and need for sustainable
development.
8. Ethics: Apply ethical principles and commit to professional ethics and responsibilities and norms of the
engineering practice.
9. Individual and team work: Function effectively as an individual, and as a member or leader in diverse
teams, and in multidisciplinary settings.
10. Communication: Communicate effectively on complex engineering activities with the engineering
community and with society at large, such as, being able to comprehend and write effective reports
and design documentation, make effective presentations, and give and receive clear instructions.
11. Project management and finance: Demonstrate knowledge and understanding of the engineering and
management principles and apply these to one’s own work, as a member and leader in a team, to
manage projects and in multidisciplinary environments.
12. Life-long learning: Recognize the need for, and have the preparation and ability to engage in
independent and life-long learning in the broadest context of technological change.
PROGRAM SPECIFIC OUTCOMES
PSO2: Design and Develop web, mobile, and smart apps based software solutions to the real
SNO NAME OF PROGRAMS Page
Nos.
1 Write a python program to print “Hello World!” on the screen.
2 Write a Python program to find sum of two numbers.
3 Write a Python program to compute distance between two points
taking input from the user. (use Pythagorean Theorem).
4 Write a python program to test whether a given number is even or odd.
5 Write a Python Program to print out the decimal equivalents of 1/2,
1/3, 1/4, . . . ,1/10, using a for loop.
6 Write a Python Program to print a countdown from the given number
to zero. Using a while loop.
7 Write a Python Program to find the sum of all the primes below
hundred.
8 Write a Python program to find the factorial of a given number
9 Write a function cumulative_product to compute cumulative product
of a list of numbers
10 Write function to compute gcd, lcm of two numbers. Each function
shouldn’t exceed one line.
11 Find the sum of the even-valued terms in the Fibonacci sequence
whose values do not exceed ten thousand.
12 Write a program that accepts a string from a user and re-displays the
same after removing vowels from it.
13 Write a program to calculate the length of a string.
14 Write a function to reverse a given string.
15 Creating Python Lists and deleting some elements, creating and
accessing Python tuple elements.
16 write a program to swap two values using Tuple assignments
17 Write a program to sort a Tuple of values
18 Write program that scans an email address and forms a tuple of user
name and domain name.
19 Write a program to print sum and average of the elements present in
the list.
20 Write a program that forms a list of first character of every word
present in another list.
21 Write a program to count the number of characters in the string and
store them in a dictionary.
22 Write a program to sort keys of a dictionary.
23 Write a program that prints maximum and minimum value in a
dictionary.
24 Write a program to print each line of a file in reverse order
25 Write a program to compute the number of characters, words and
lines in a file.
26 Write a program to copy contents of one file into another file.
1.Aim:- Write a Python program to print Hello-World
>>>print(“Hello-World”)
Output :- Hello-World
(Or)
Program :- >>>a=”Hello”
>>>a+=”-World”
>>>print(a)
Output :-Hello-world
2. Aim :-Write a Python program to add two-numbers
Program:- >>>a=5
>>>b=10
>>>c=a+b
>>>print(c)
Output:- 15
(Or)
s=int(input(“Enter b:”))
c=h+s
print(c)
Program:-x1=int(input("Enter x1:"))
x2=int(input("Enter x2:"))
y1=int(input("Enter y1:"))
y2=int(input("Enter y2:"))
distance=((x2-x1)**2+(y2-y1)**2)**0.5
Output:-Enter x1:2
Enter x2:3
Enter y1:4
Enter y2:6
4. Aim: Write a python program to Test whether a given number is even or odd.
A) num = int(input("Enter a number: "))
if num % 2==0:
print("This is an even number.")
else:
print("This is an odd number.")
Output:
Enter a number: 5
This is an odd number.
5. Aim:. Write a python program to Print out the decimal equivalents of ½, 1/3
,1/4........1/10,using for a loop.
A) i=1
for i in range(1,11):
value=1.0/i
print"1/",i,"=",value
output:
1/ 1 = 1.0
1/ 2 = 0.5
1/ 3 = 0.333333333333
1/ 4 = 0.25
1/ 5 = 0.2
1/ 6 = 0.166666666667
1/ 7 = 0.142857142857
1/ 8 = 0.125
1/ 9 = 0.111111111111
1/ 10 = 0.1
6. Aim: Write a python program to Print a count down from the given number to zero using a
while loop.
A) num=int(input("enter a number"))
print "count down from ",num,"to 0:"
while (num>=0):
print num
num=num-1
output:
enter a number6
count down from 6 to 0:
6
5
4
3
2
1
0
7. Aim: Write a python program to Find the sum of all the primes below hundred.
A) sum=0
for j in range(1,100):
for i in range(2,j):
if (j% i) == 0:
break
else:
sum=sum+j #where j is a prime number
print "sum of prime numbers up to 100 is", sum
output:
sum of prime numbers up to 100 is 1061
8. Aim: Write a python program to find the factorial of a given number.
A) num=int(input("enter a number"))
fact=1
while (num>0):
fact=fact*num
num=num-1
print "factorial of a given number is",fact
output:
Enter a number 6
Factorial of a given number is 720
9. Aim: Write a function cumulative product to compute cumulative product of a list of numbers.
Program:
defcumulative_product():
list=[1,2,3,4]
prod=1
fori in list:
prod=prod*i
print(prod)
cumulative_product()
Output:
24
10. Aim: Write function to compute gcd, lcm of two numbers. Each function shouldn’t exceed one
line.
Program:
from fractions import gcd
print(gcd(5,25))
def lcm(a,b):
#a=60
#b=40
print((a * b) // gcd(a, b))
lcm(5,25)
output:
5
25
11. Aim:Find the sum of the even-valued terms in the Fibonacci sequence whose values do not
exceed ten thousand.
program:
i=0
j=1
sum=0
while(i<10000):
i=i+j
j=i-j
if(i%2==0):
sum+=i
print(sum)
output:
14328
12.Aim: Write a program that accepts a string from a user and re-displays the same after removing
vowels from it.
Program:
while True:
print('Enter x for exit.')
string = input('Enter any string: ')
if string == 'x':
break
else:
newstr = string
print("\n Removing vowels from the given string...")
vowels = ('a', 'e', 'i', 'o', 'u')
for x in string.lower():
if x in vowels:
newstr = newstr.replace(x,"")
print("New string after successfully removing all vowels!")
print(newstr,"\n")
output:
>>>
Enter x for exit.
Enter any string: programming
Program:
def reverse(text):
lst = []
count = 1
fori in range(0,len(text)):
lst.append(text[len(text)-count])
count += 1
lst = ''.join(lst)
returnlst
print reverse('Python Programming')
output:
gnimmargorPnohtyP
15. Aim: Creating Python Lists and deleting some elements, creating and
accessing Python tuple elements.
Creating tuple:
# Empty tuple
my_tuple = ()
print(my_tuple) # Output: ()
my_tuple = (1, 2, 3)
# nested tuple
print(my_tuple)
Deleting Tuple:
my_tuple = ('p','r','o','g','r','a','m','i','z')
# del my_tuple[3]
del my_tuple
print(my_tuple)
16.Aim Write a program to swap two values using Tuple assignments.
Program: (val1,val2,val3)=(1,2,3)
(tup1,tup2,tup3)=(4,5,6)
(a,b,c)=(val1,val2,val3)
(val1,val2,val3)=(tup1,tup2,tup3)
(tup1,tup2,tup3)=(a,b,c)
print (val1,val2,val3)
print (tup1,tup2,tup3)
Output:
Program:
addr =input('Enter email address:')
(uname, domain) = addr.split('@')
print('Username:',uname)
print('domain name:',domain)
Output:
19.Aim: Write a program to print sum and average of the elements present in the list.
Program:
lst = [ ]
num = int(input('How many numbers: '))
for n in range(num):
numbers = int(input('Enter number '))
lst.append(numbers)
print("Sum of elements in given list is :", sum(lst))
avg=sum(lst)/num
print(avg)
Output:
20.Aim: Write a program that forms a list of first character of every word present in another list.
Program:
b= [ ]
l= ["gudlavalleru","engineering","college"]
for item in l:
b.append(item[0])
print(b)
Output: [‘g’,’e’,’c’]
21.Aim: Write a program to count the number of characters in the string and
store them in a dictionary.
n=int(input("enter number"))
dict={}
i=0
while(i<n):
str=input("enter string")
length=len(str)
dict[str]=length
i=i+1
print("dictionary is:",dict)
output:
enter number2
enter stringsuguna
enter stringraghu
dict={'name':'suguna','course':'M.Tech'}
print("{%s:%s}"%(key, dict[key]))
output:
{course:M.Tech}
{name:suguna}
23. Aim: Write a program that prints maximum and minimum value in a
dictionary.
dict={'name':'suguna','course':'M.Tech'}
output:
24. Aim: Write a program to print each line of a file in reverse order
print(line[::-1])
output:
ih
olleh
u r woh
25. Aim: Write a program to compute the number of characters, words and
lines in a file.
num_line=0
num_words=0
num_char=0
words=line.split()
num_line+=1
num_words+=len(words)
num_char+=len(line)
print("no.of line=",num_line)
print("no.of characters:",num_char)
print("no.of words=",num_words)
output:
no.of line= 3
no.of characters: 17
no.of words= 5
26. Aim: Write a program to copy contents of one file into another file.
f1.write(line)
output:
Input.txt
hi
hello
how r u