python practical
python practical
print("Hello, world!")
import math
num = 153
sum = 0
temp = num
digit = temp % 10
sum += digit ** 3
temp //= 10
if num == sum:
else:
num = 4
if num % 2 == 0:
else:
year = 2020
else:
a=5
b = 10
c=8
largest = max(a, b, c)
num = 29
if num > 1:
if (num % i) == 0:
break
else:
else:
def is_list_empty(lst):
return not lst
my_list = []
print("Is the list empty?", is_list_empty(my_list))
my_list = [1, 2, 3, 4, 5]
sliced_list = my_list[1:4]
print("Sliced List:", sliced_list)
list1 = [1, 2, 3]
list2 = [4, 5, 6]
my_list = [1, 2, 2, 3, 4, 4, 5]
unique_list = list(set(my_list))
if 'b' in my_dict:
del my_dict['b']
key_to_check = 'b'
if key_to_check in my_dict:
else:
def is_palindrome(s):
return s == s[::-1]
my_string = "radar"
capitalized_string = my_string.capitalize()
my_string = "abc"
import time
def countdown(seconds):
while seconds:
print(timer, end="\r")
time.sleep(1)
seconds -= 1
print("Time's up!")
countdown(10)
char_to_count = 'o'
count = my_string.count(char_to_count)
my_tuple = (1, 2, 3, 4, 5)
print("Size of the tuple:", len(my_tuple))
my_list = [1, 2, 3]
my_tuple = (4, 5, 6)
3. Python program to sort a list of tuples in increasing order by the last element in each
tuple
my_tuple = (1, 2, 2, 3, 3, 3, 4, 4, 4, 4)
frequency = Counter(my_tuple)
my_list = [5, 6, 7]
my_tuple = (1, 2, 3, 4, 5)