{}
See how a CS professor is using our compiler for class assignment.
Try Programiz PRO for Educators!
Learn DSA with step-by-step code visualization.
Try Programiz PRO for Educators!
run-icon
main.py
# Online Python compiler (interpreter) to run Python online. # Write Python 3 code in this online editor and run it. # 1. Create an empty tuple empty_tuple = () # 2. Create a tuple containing names of your sisters and your brothers sisters = ('Aanya', 'Riya') brothers = ('Aryan', 'Kabir') # 3. Join brothers and sisters tuples and assign it to siblings siblings = sisters + brothers # 4. How many siblings do you have? print("Number of siblings:", len(siblings)) # Output: 4 # 5. Modify the siblings tuple and add the name of your father and mother and assign it to family_members family_members = siblings + ('Father', 'Mother') print("Family Members:", family_members) # 6. Unpack siblings and parents from family_members a, b, c, d, father, mother = family_members print("Siblings:", (a, b, c, d)) print("Parents:", (father, mother)) # 7. Create fruits, vegetables and animal products tuples fruits = ('apple', 'banana', 'mango') vegetables = ('carrot', 'spinach', 'potato') animal_products = ('milk', 'cheese', 'egg') # Join the three tuples food_stuff_tp = fruits + vegetables + animal_products print("Food Stuff (Tuple):", food_stuff_tp) # 8. Change the food_stuff_tp tuple to a list food_stuff_lt = list(food_stuff_tp) print("Food Stuff (List):", food_stuff_lt) # 9. Slice out the middle item or items from the food_stuff_lt list middle_index = len(food_stuff_lt) // 2 if len(food_stuff_lt) % 2 == 0: middle_items = food_stuff_lt[middle_index - 1:middle_index + 1] else: middle_items = [food_stuff_lt[middle_index]] print("Middle item(s):", middle_items) # 10. Slice out the first three items and the last three items from food_stuff_lt list first_three = food_stuff_lt[:3] last_three = food_stuff_lt[-3:] print("First three items:", first_three) print("Last three items:", last_three) # 11. Delete the food_stuff_tp tuple completely del food_stuff_tp # print(food_stuff_tp) # Will raise an error if uncommented # 12. Check if 'Estonia' is a nordic country # 13. Check if 'Iceland' is a nordic country nordic_countries = ('Denmark', 'Finland', 'Iceland', 'Norway', 'Sweden') print("Is 'Estonia' a Nordic country?", 'Estonia' in nordic_countries) print("Is 'Iceland' a Nordic country?", 'Iceland' in nordic_countries)
Output