Lab Programs-1
Lab Programs-1
Source Code:
week1.py
Output:
Aim:
Write a program to perform different Arithmetic Operations on numbers in Python.
Source Code:
week2.py
Output:
Aim:
Write a python script to print the current date in the following format “Sun May 29
02:26:23 IST 2017”
Source Code:
week4.py
'''Aim: . Write a python script to print the current date in the follo
wing format Sun May 29
02:26:23 IST 2017 '''
import time;
ltime=time.localtime();
print(time.strftime("%a %b %d %H:%M:%S %Z %Y",ltime)); #returns the f
ormatted time
'''
%a : Abbreviated weekday name.
%b : Abbreviated month name.
%d : Day of the month as a decimal number [01,31].
%H : Hour (24-hour clock) as a decimal number [00,23].
%M : Minute as a decimal number [00,59].
%S : Second as a decimal number [00,61].
%Z : Time zone name (no characters if no time zone exists).
%Y : Year with century as a decimal number.'''
Output:
Aim:
Write a program to create, append, and remove lists in python.
Source Code:
week5.py
Output:
Aim:
Write a python program to find largest of three numbers.
Source Code:
week8.py
Output:
Aim:
Write a Python program to construct the stars(*) pattern, using a nested for loop
Source Code:
week10.py
for i in range(n,0,-1):
for j in range(i):
print('* ', end="")
print('')
Output:
Aim:
Write a Python program to convert temperatures to and from Celsius, Fahrenheit.
[Formula: c/5 = f-32/9]
Source Code:
week9.py
Output:
Aim:
Write a Python class to convert an integer to a roman numeral.
Source Code:
week18.py
class irconvert:
num_map = [(1000, 'M'), (900, 'CM'), (500, 'D'), (400, 'CD'), (100
, 'C'), (90, 'XC'),(50, 'L'), (40, 'XL'), (10, 'X'), (9, 'IX'), (5, 'V
'), (4, 'IV'), (1, 'I')]
def num2roman(self,num):
roman = ''
while num > 0:
for i, r in self.num_map:
while num >= i:
roman += r
num -= i
return roman
Output: