Wa0004
Wa0004
Program :
a=10;
b=11.3;
c=20.7;
print("a is Type of",type(a));
print("b is Type of",type(b));
print("c is Type of",type(c));
2. Write a program to perform different arithmetic operations on numbers in python.
Program :
Program :
Program :
import time;
ltime=time.localtime();
print(time.strftime("%a %b %d %H:%M:%S %Z %Y",ltime));
'''
%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.'''
5.Write a python program to create, append and remove lists in python.
Program :
class check():
def __init__(self):
self.n=[]
def add(self,a):
return self.n.append(a)
def remove(self,b):
self.n.remove(b)
def dis(self):
return (self.n)
obj=check()
choice=1
while choice!=0:
print("0. Exit")
print("1. Add")
print("2. Delete")
print("3. Display")
if choice==1:
obj.add(n)
print("List: ",obj.dis())
elif choice==2:
obj.remove(n)
print("List: ",obj.dis())
elif choice==3:
print("List: ",obj.dis())
elif choice==0:
print("Exiting!")
else:
print("Invalid choice!!")
print()
Program :
T = ("apple", "banana", "cherry","mango","grape","orange")
print("\n Created tuple is :",T)
print("\n Second fruit is :",T[1])
print("\n From 3-6 fruits are :",T[3:6])
print("\n List of all items in Tuple :")
for x in T:
print(x)
if "apple" in T:
print("\n Yes, 'apple' is in the fruits tuple")
print("\n Length of Tuple is :",len(T))
7.Write a program to demonstrate working with dictionaries in python.
for x in dict1:
print(x)
for x in dict1:
print(dict1[x])
#Adding items
dict1["Phno"]=85457854
#Updated dictoinary
#Change values
dict1["StuName"]="Madhu"
#Updated dictoinary
#Removing Items
dict1.pop("StuAge");
#Updated dictoinary
#Length of Dictionary
#Copy a Dictionary
dict2=dict1.copy()
#New dictoinary
dict1.clear()
Program :
a=5
b=4
c=7
largest = 0
largest = a
largest = b
largest = c
Program :
celsius = 47
fahrenheit = (celsius * 1.8) + 32
print('%.2f Celsius is equivalent to: %.2f Fahrenheit'
% (celsius, fahrenheit))
10. Write a python program to construct the following pattern using nested for loop:
*
**
***
****
*****
****
***
**
*
Program :
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('')