Aim:
Write a program to demonstrate different number data types in Python.
Source Code:
week1.py
'''Aim:Write a program to demonstrate different number data types in P
ython.'''
a=10; #Integer Datatype
b=11.5; #Float Datatype
c=2.05j; #Complex Number
print("a is Type of",type(a)); #prints type of variable a
print("b is Type of",type(b)); #prints type of variable b
print("c is Type of",type(c)); #prints type of variable c
Output:
Aim:
Write a program to perform different Arithmetic Operations on numbers in Python.
Source Code:
week2.py
'''Aim:Write a program to perform different Arithmetic Operations on n
umbers in Python.'''
a=int(input("Enter a value")); #input() takes data from console at run
time as string.
b=int(input("Enter b value")); #typecast the input string to int.
print("Addition of a and b ",a+b);
print("Subtraction of a and b ",a-b);
print("Multiplication of a and b ",a*b);
print("Division of a and b ",a/b);
print("Remainder of a and b ",a%b);
print("Exponent of a and b ",a**b); #exponent operator (a^b)
print("Floar division of a and b ",a//b); # floar division
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
'''Aim: Write a program to create, append, and remove lists in python.
'''
pets = ['cat', 'dog', 'rat', 'pig', 'tiger']
snakes=['python','anaconda','fish','cobra','mamba']
print("Pets are :",pets)
print("Snakes are :",snakes)
animals=pets+snakes
print("Animals are :",animals)
snakes.remove("fish")
print("updated Snakes are :",snakes)
Output:
Aim:
Write a python program to find largest of three numbers.
Source Code:
week8.py
''' Write a python program to find largest of three numbers '''
num1 = int(input("Enter first number: "))
num2 = int(input("Enter second number: "))
num3 = int(input("Enter third number: "))
if (num1 > num2) and (num1 > num3):
largest = num1
elif (num2 > num1) and (num2 > num3):
largest = num2
else:
largest = num3
print("The largest number is",largest)
Output:
Aim:
Write a Python program to construct the stars(*) pattern, using a nested for loop
Source Code:
week10.py
'''Write a Python program to construct the following pattern, using a
nested for loop
*
* *
* * *
* * * *
* * * * *
* * * *
* * *
* *
*
'''
n=5;
for i in range(n):
for j in range(i):
print ('* ', end="")
print('')
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
''' Write a Python program to convert temperatures to and from Celsius
, Fahrenheit.
[ Formula: c/5 = f-32/9] '''
print("Options are \n")
print("1.Convert temperatures from Celsius to Fahrenheit \n")
print("2.Convert temperatures from Fahrenheit to Celsius \n")
opt=int(input("Choose any Option(1 or 2) : "))
if opt == 1:
print("Convert temperatures from Celsius to Fahrenheit \n")
cel = float(input("Enter Temperature in Celsius: "))
fahr = (cel*9/5)+32
print("Temperature in Fahrenheit =",fahr)
elif opt == 2:
print("Convert temperatures from Fahrenheit to Celsius \n")
fahr = float(input("Enter Temperature in Fahrenheit: "))
cel=(fahr-32)*5/9;
print("Temperature in Celsius =",cel)
else:
print("Invalid Option")
Output:
Aim:
Write a Python class to convert an integer to a roman numeral.
Source Code:
week18.py
'''Write a Python class to convert an integer to a roman numeral.'''
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
num=int(input("Enter any Number :"))
print("Roman Number is : ",irconvert().num2roman(num))
Output: