Skip to content

Instantly share code, notes, and snippets.

@jedrzejme
Last active August 13, 2023 03:05
Show Gist options
  • Save jedrzejme/6a135d7d7cd20128dc48df81571bd10b to your computer and use it in GitHub Desktop.
Save jedrzejme/6a135d7d7cd20128dc48df81571bd10b to your computer and use it in GitHub Desktop.
Calculate the probability of getting 100% in a test containg only singe choise quiestions
# this program is used to calculate the probability of getting 100% in a test containg only single choice quiestions
# x - amount of answers per question
# y - amount of questions
# formula of the function: x^0 + x^1 + x^2 + x^3 + ... + x^y
def probability(x, y):
i = 0
z = 0
while(i <= y):
z += x ** i
i += 1
z = f"{z:,}".replace(",", " ")
return(f"1:{z}")
# 1st example of usage:
print(probability(int(input("How many answers per question? ")), int(input("How many questions? "))))
# 2nd example of usage:
print(probability(4, 10))
# 3rd example of usage:
x = 4
y = 10
print(probability(x, y))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment