



















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
Python programs for mathematical operations, string manipulation, list manipulation, tuple manipulation, and set operations. Includes arithmetic operations with integers and conversion from binary, hexadecimal, and octal. Demonstrates creating, concatenating, indexing, slicing, and manipulating strings. Reverses, concatenates index-wise, squares items, removes empty strings, extends nested lists, replaces items, removes occurrences, and more in lists. Covers reversing, accessing values, creating single-item tuples, unpacking, swapping, copying, modifying, sorting, counting occurrences, and checking equality in tuples. Gets unique items, checks for common elements, updates sets, and removes non-common items. Demonstrates conditional statements.
Typology: Lab Reports
1 / 27
This page cannot be seen from the preview
Don't miss anything!
Python Programming code: 1) SQUARE PATTERN : side = int(input("Please Enter any Side of a Square : ")) input is converted to an integer using int() and stored in the variable side. i = 0 Variable I initialized by 0 print("Square Star Pattern") while(i < side): j = 0 while(j < side): j = j + 1 print('', end = ' ') i = i + 1 print('') OUTPUT:* Please Enter any Side of a Square : 12 Square Star Pattern
**4) FLOAT Program: my_float = 3.14 Define a float variable another_float = 2.0 arithmetic operations with float variables result = my_float + another_float print(result)
parts complex_number1 = complex(3.0, 4.0) # 3.0 + 4.0j print(complex_number1)
part defaults to 0.0) complex_number2 = complex(2.0) # 2.0 + 0.0j print(complex_number2)
part defaults to 0.0) complex_number3 = complex(imag=1.5) # 0.0 + 1.5j print(complex_number3)
7) Print characters from a string that are present at an even index number
user_input = input("Enter a string: ")
length_of_string = len(user_input) print("Length of the string:", length_of_string)
print("Characters at even indices:") for i in range(0, length_of_string, 2): print(user_input[i])
word = input('Enter a word: ') print("Original String:", word) 7)a) Print characters using slicing
characters_at_even_indices = list(word[0::2])
print("Characters at even indices:") for char in characters_at_even_indices: print(char)
def add_item_after(lst, item_to_find, new_item): index = lst.index(item_to_find) lst.insert(index + 1, new_item) return lst
def extend_nested_list(nested_list, sublist): nested_list.extend(sublist) return nested_list
def replace_item(lst, old_value, new_value): for i in range(len(lst)): if lst[i] == old_value: lst[i] = new_value return lst
def remove_all_occurrences(lst, item_to_remove): return [x for x in lst if x != item_to_remove]
my_list = [1, 2, 3, 4, 5] other_list = [6, 7, 8, 9, 10] nested_list = [[11, 12], [13, 14]] print("1:", reverse_list(my_list)) print(“ 2:", concatenate_index_wise(my_list, other_list)) print(“ 3:", square_elements(my_list)) print(“ 4:", concatenate_order(my_list, other_list)) print(“ 5:") iterate_simultaneously(my_list, other_list) print(" 6:", remove_empty_strings(["", "hello", "", "world", ""])) print(“ 7:", add_item_after(my_list, 3, 100)) print(“8:", extend_nested_list(nested_list, [15, 16])) print(“9:", replace_item(my_list, 3, 300)) print(“ 10:", remove_all_occurrences(my_list + other_list, 5))