0% found this document useful (0 votes)
58 views

Government College of Engineering, SALEM-11.: Programming

This document contains 10 Python programs written by A. Nivetha. The programs include: 1) Finding the largest number in a list, 2) Checking if a list is empty, 3) Shuffling and printing a list, 4) Converting a string to a list, 5) Accessing dictionary keys by index, 6) Getting OS information, 7) Reversing a tuple, 8) Printing numbers in a range except certain values, 9) Finding the maximum of three numbers, and 10) Checking if a number is within a given range.

Uploaded by

Kamalesh kss
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
58 views

Government College of Engineering, SALEM-11.: Programming

This document contains 10 Python programs written by A. Nivetha. The programs include: 1) Finding the largest number in a list, 2) Checking if a list is empty, 3) Shuffling and printing a list, 4) Converting a string to a list, 5) Accessing dictionary keys by index, 6) Getting OS information, 7) Reversing a tuple, 8) Printing numbers in a range except certain values, 9) Finding the maximum of three numbers, and 10) Checking if a number is within a given range.

Uploaded by

Kamalesh kss
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

GOVERNMENT COLLEGE OF

ENGINEERING,
SALEM- 11.

NAME : A.NIVETHA
REG NO : 1721031
SUBJECT : PYTHON
PROGRAMMING
DATE : 08.04.2020
ASSIGNMENT NO : 01
1)PYTHON PROGRAM TO GET LARGEST
NUMBERS FROM T HE LIST:
PROGRAM:
list1 = [20, 35, 81, 77, 76]
list1.sort()
print("Largest element is:", list1[-1])
OUTPUT:
Largest element is: 81
2)PYTHON PROGRAM TO CHECK WHETHER
THE LIST IS EMPTY OR NOT:
PROGRAM:
def Enquiry(lis1):
if len(lis1) == 0:
print("Empty List")
else:
print ("The list is not empty")
lis1 = []
Enquiry(lis1)
OUTPUT:
Empty List
3)PYTHON PROGRAM TO SHUFFLE AND
PRINT A SPECIFIED LIST:
PROGRAM:
from random import shuffle
color = ['Python', 'C++', 'C', 'java', 'Php', 'COBOL']
shuffle(color)
print(color)
OUTPUT:
['Php', 'C++', 'Python', 'COBOL', 'C', 'java']
4)PYTHON PROGRAM TO CONVERT A
STRING TO A LIST:
PROGRAM:
def Convert(string):
li = list(string.split(" "))
return li
str1 = "Nivetha Anbarasan"
print(Convert(str1))
OUTPUT:
['Nivetha', 'Anbarasan']
5)PYTHON PROGRAM TO ACCESS
DICTIONARY KEYS ELEMENT BY INDEX:
PROGRAM:
num = {'physics': 80, 'math': 90, 'chemistry': 86}
print(list(num)[0])
OUTPUT:
physics
6) PYTHON PROGRAM TO DISPLAY SOME
INFORMATION ABOUT THE OS WHERE THE
SCRIPT IS RUNNING:
PROGRAM:
import platform as pl
os_profile = [
'architecture',
'linux_distribution',
'mac_ver',
'machine',
'node',
'platform',
'processor',
'python_build',
'python_compiler',
'python_version',
'release',
'system',
'uname',
'version',
]
for key in os_profile:
if hasattr(pl, key):
print(key + ": " + str(getattr(pl, key)()))

OUTPUT:
architecture: ('64bit', 'ELF')
linux_distribution: ('Ubuntu', '16.04', 'xenial')
mac_ver: ('', ('', '', ''), '')
machine: x86_64
node: 9a911676793b
platform: Linux-4.4.0-57-generic-x86_64-with-Ubuntu-16.04-xenial
processor: x86_64
python_build: ('default', 'Nov 17 2016 17:05:23')
python_compiler: GCC 5.4.0 20160609
python_version: 3.5.2
release: 4.4.0-57-generic
system: Linux
uname: uname_result(system='Linux', node='9a911676793b',
release='4.4.0-57-generic', version='#78-Ubuntu SMP Fri Dec 9
23:50:32 UTC 2016', machine='x86_64', processor='x86_64')
version: #78-Ubuntu SMP Fri Dec 9 23:50:32 UTC 2016

7) PYTHON PROGRAM TO REVERSE A TUPLE:


PROGRAM:
def Reverse(tuples):
new_tup = tuples[::-1]
return new_tup
tuples = ('A','B','C','D','E','F','G','H')
print(Reverse(tuples))

OUTPUT:
('H', 'G', 'F', 'E', 'D', 'C', 'B', 'A')

8) PYTHON PROGRAM TO PRINT ALL THE


NUMBERS FROM 0 TO 6 EXCEPT 3 AND 6:
PROGRAM:
for x in range(6):
if (x == 3 or x==6):
continue
print(x,end=' ')
print("\n")

OUTPUT:
01245

9) PYTHON FUNCTION TO FIND THE MAX OF


THREE NUMBERS:
PROGRAM:
def max_of_two( x, y ):
if x > y:
return x
return y
def max_of_three( x, y, z ):
return max_of_two( x, max_of_two( y, z ) )
print(max_of_three(-1, 2, 10))

OUTPUT:
10

10) PYTHON PROGRAM TO CHECK WHETHER THE


NUMBER IS IN A GIVEN RANGE:
PROGRAM:
def test_range(n):
if n in range(3,9):
print( "The number is within the given range")
else :
print("The number is outside the given range.")
test_range(5)
OUTPUT:
The number is within the given range

You might also like