Practical: 2 Aim 2.1: Check Whether The Number Is Armstrong or Not?
Practical: 2 Aim 2.1: Check Whether The Number Is Armstrong or Not?
Code:
sum = 0
temp = num
digit = temp % 10
sum += digit ** 3
temp //= 10
if num == sum:
else:
Output:
Code:
def test_prime(n):
if (n==1):
return False
elif (n==2):
return True;
else:
for x in range(2,n):
if(n % x==0):
return False
return True
print(test_prime(a))
Output:
False
True
Code:
if num > 0:
elif num == 0:
print("It is Zero")
else:
Output:
Input a number: -6
It is a negative number
Input a number: 0
It is Zero
It is positive number
Aim 2.4 : Create a list and perform the following methods.
Code:
My_list = [1, 2 , 3, 4, 6, 7, 8]
My_list.insert(0, 5)
My_list.remove(3)
My_list.append(6)
x = len(My_list)
print(x)
My_list.pop(4)
My_list.clear()
Output:
list is [5, 1, 2, 4, 6, 7, 8, 6]
list is [5, 1, 2, 4, 7, 8, 6]
list is []
Aim 2.5 : Create a dictionary and apply the following methods.
Code:
thisdict = {
"name": "Harsh",
"Lname": "More",
"Byear": 2001,
"Degree": "computer",
"erno": 191210107031
print(thisdict)
print(thisdict["name"])
x = thisdict["Byear"]
print(x)
x = thisdict.keys()
print(x)
thisdict["name"]= "ram"
print(thisdict)
print(len(thisdict))
Output:
{'name': 'Harsh', 'Lname': 'More', 'Byear': 2001, 'Degree': 'computer', 'erno': 191210107031}
Harsh
2001
{'name': 'Harsh', 'Lname': 'More', 'Byear': 2001, 'Degree': 'computer', 'erno': 191210107031}
5
Aim 2.6 : Create a tuple and perform the following methods.
4) access items
Code:
print(thistuple)
y = list(thistuple)
y.append("yash")
thistuple = tuple(y)
print(len(thistuple))
print(thistuple[3])
Output:
sahil
4) access items
Code:
print(thisset