'Calculate probability within a loop - Python3

Good evening! I have just picked up Python last month and I am having a lot of fun with it!

I am writing my first program ever in order to determine what are the probability of 2 songs of a same album playing back to back in a Spotify shuffled playlist: Sbotify! I have the use input sorted out but I cannot find a way to apply the probability formula for a value.

The formula used will be to multiply the probabilities of each separate event by one another as described in this article (method 2-3). I need to multiply an imputed value int() by itself -1 on repeat until this value reaches 0 and then do the same thing for another value and so on and so forth.

I have tried:

  • for loops
  • Map() function
  • Range() to bypass the int cannot be integrate error

But nothing seem to work. I've looked for an answer for hours and I cannot seem to find anything that fits my purpose. Any link, resource, or knowledge is much welcomed! 😊

Here is my code,

import math
import statistics

print("\nHey user! Sbotify has for purpose to tell you the probability of \n
playing a song of the same album in a shuffled Spotify playlist. \n\n")
total_songs = int(input("\nEnter the total of your songs:"))

lst = []
num = int(input('Enter a number of albums: '))
for n in range(num):
    numbers = int(input('Enter number of song for each album: '))
    lst.append(numbers)
print("Sum of songs belonging to an album is :", sum(lst))
print(lst)

print("\nLet's find out the songs that don't belong to any album. This will be handy later:")

solo_songs = total_songs - sum(lst)
print(int(solo_songs))

# I'm afraid we need to use... **MATH**

print("Nice! Now we need to find out the probabilities of 2 songs of the same album playing back to back in shuffle mode")

#Each album needs to be considered 1 entity and to that, the solo_songs value needs to be multiplied by itself -1 until 0
#to respect the probability formula

let me know if anything is correct, over complicated or to be redone completely!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source