Skip to content

Instantly share code, notes, and snippets.

@aaditkamat
Created June 20, 2026 02:53
Show Gist options
  • Select an option

  • Save aaditkamat/d7cacfb24b093a83adee85276f640843 to your computer and use it in GitHub Desktop.

Select an option

Save aaditkamat/d7cacfb24b093a83adee85276f640843 to your computer and use it in GitHub Desktop.
Simple Python script for coin toss simulation
import random
def coin_toss():
n = int(
input(
'Enter number of coin tosses (must be an integer greater than 0): '
))
options = ['Option 1', 'Option 2']
options[0] = input('Enter option 1: ')
options[1] = input('Enter option 2: ')
positions = ['Heads', 'Tails']
count_heads = 0
for i in range(n):
chosen_position = random.choice(positions)
print(f'Coin toss #{i + 1}: {chosen_position}')
if chosen_position == 'Head':
count_heads += 1
if count_heads > n // 2:
print(f'Choose {options[0]}')
elif count_heads < n // 2:
print(f'Choose {options[1]}')
else:
coin_toss()
if __name__ == '__main__':
coin_toss()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment