PYTHON 37
4/22/2025 arrays/lists Guest on 23rd April 2025 12:45:51 AM
  1. from Song import Song
  2.  
  3.  
  4. def print_array(my_list, action):
  5.         for i in range(len(my_list)):
  6.                 print("I " + action + " a " + my_list[i] + ".")
  7.  
  8. my_fruit = ["apple", "banana", "orange", "kiwi", "pear"]
  9.  
  10.  
  11. # print(len(my_fruit))
  12. # print(my_fruit)
  13.  
  14. # print_array(my_fruit, "eat")
  15.  
  16. my_fruit[1] = "grape"
  17.  
  18. # print_array(my_fruit, "eat")
  19.  
  20. #
  21. # print(my_fruit[5])
  22. # print(len(my_fruit))
  23. # my_fruit[5] = "watermelon"
  24. #
  25. # print(my_fruit[5])
  26.  
  27. # ["apple", "banana", "orange", "kiwi", "pear"]
  28.  
  29. # my_fruit.append("mango")
  30. # my_fruit = ["apple", "banana", "orange", "kiwi", "pear", "mango"]
  31.  
  32. # print_array(my_fruit, "eat")
  33.  
  34. # print(my_fruit.pop())
  35.  
  36. # print_array(my_fruit, "ate")
  37.  
  38. my_fruit.insert(0, "peach")
  39.  
  40. # print_array(my_fruit, "will eat")
  41.  
  42.  
  43. # print_array(my_fruit, "didn't eat")
  44.  
  45.  
  46. def print_song(track, playlist):
  47.         print("Song: " + playlist[track][0] )
  48.         print("Artist: " + playlist[track][1])
  49.  
  50. def print_playlist(playlist):
  51.         for song in range(len(playlist)):
  52.                 print_song(song, playlist)
  53.  
  54. songs = [["Hello", "Adele"], ["Lithium", "Nirvana"]]
  55.  
  56. songs.append(["Dance", "Drake"])
  57. songs.append(["Happy", "Pharrell"])
  58. # print_song(2, songs)
  59. # print_playlist(songs)
  60. # print(songs[1][1])
  61.  
  62. my_song = Song("Dynamite", "BTS")
  63.  
  64. # print(my_song)
  65.  
  66.  
  67. # my_function()
  68.  
  69.  
  70. def print_add(a, b):
  71.         # stuff in the middle
  72.         # aka the BODY of the function
  73.         print(a + b)
  74.  
  75. # print_add(5, 7)
  76.  
  77. my_string_with_number = "hello CSIT 111"
  78. my_string_no_number = "ccbc is a school"
  79.  
  80. def remove_spaces(input_string: str):
  81.         filter = input_string.replace(" ", "")
  82.         return filter
  83.  
  84. # print(my_string_with_number.isalpha())
  85. print(my_string_no_number)
  86. print(remove_spaces(my_string_no_number))
  87. checking_this = remove_spaces(my_string_no_number)
  88. print(checking_this.isalpha())
  89.  
  90.  
  91. condition = True
  92. counter = 0
  93. while (condition):
  94.         if counter > 50:
  95.                 condition = False
  96.         counter += 1
  97.         print(counter)
  98.         # do stuff

Paste is for source code and general debugging text.

Login or Register to edit, delete and keep track of your pastes and more.

Raw Paste

Login or Register to edit or fork this paste. It's free.