Skip to content

Instantly share code, notes, and snippets.

@lem0n4id
Created June 17, 2021 21:02
Show Gist options
  • Save lem0n4id/7fb8e1d043edd02e3f4646bd60c54684 to your computer and use it in GitHub Desktop.
Save lem0n4id/7fb8e1d043edd02e3f4646bd60c54684 to your computer and use it in GitHub Desktop.
this is python program that impliments a slot machine like simulator using random module of python ;)
import random
def slot_machine_start():
print('\t\t\t\t\tWelcome to slot machine simulator')
print()
print('\tHere\'s your 100 coins to start playing')
print(' ____________________________________________________________________________________')
print(' | |')
print(' | The game is simple |')
print(' | |')
print(' | Each spin costs 25 coins |')
print(' | |')
print(' | There are 1-9 numbers which are randomly generated |')
print(' | |')
print(' | If you got the middle row of numbers same then you get the Jackpot |')
print(' | The Jackpot is ONE MILLION COINS. |')
print(' | |')
print(' | If you get the upper or lower row of numbers matched then you get a free spin |')
print(' | If you get the number matched up diagonally then you win 50 coins |')
print(' | |')
print(' | GOOD LUCK! |')
print(' | |')
print(' ____________________________________________________________________________________')
print()
choice()
def choice():
print()
play=input('do you want to spin? (y/n) ')
if play=='y':
return reduct_money_slot()
elif play=='n':
print('Ok. Thank you!')
return exit()
else:
print('invalid input')
return exit()
def reduct_money_slot():
global money
money-=25
return chance() #for slot machine
def chance():
for i in key:
a[i]=random.randint(1,9)
print()
print(' ___________ ___________ ___________ ')
print(' | | | | ')
print(' | ',a['u_1'],' | ',a['u_2'],' | ',a['u_3'],' |',sep='')
print(' | | | | ')
print(' ___________ ___________ ___________ ')
print(' | | | | ')
print(' | ',a['m_1'],' | ',a['m_2'],' | ',a['m_3'],' |',sep='')
print(' | | | | ')
print(' ___________ ___________ ___________ ')
print(' | | | | ')
print(' | ',a['l_1'],' | ',a['l_2'],' | ',a['l_3'],' |',sep='')
print(' | | | | ')
print(' ___________ ___________ ___________ ')
print()
return result()
def result():
global money
if a['m_1']==a['m_2'] and a['m_2']==a['m_3']:
return jackpot()
elif a['u_1']==a['u_2'] and a['u_2']==a['u_3']:
print('Well you got all the numbers in the upper row same so here\'s your another chance')
return chance()
elif a['l_1']==a['l_2'] and a['l_2']==a['l_3']:
print('Well you got the numbers in the lower row matched up so here\'s your another chance')
return chance()
elif a['u_1']==a['m_2'] and a['m_2']==a['l_3']:
print('Congrats!')
print('You got the numbers matched diagonally!')
print('You won 50 coins!')
money+=50
return balance(),choice()
elif a['u_3']==a['m_2'] and a['m_2']==a['l_1']:
print('Congrats!')
print('You got the numbers matched diagonally!')
money+=50
return balance(),choice()
else:
print('Better luck next time')
balance()
if money<=0:
print('Sorry insufficient balance')
print('Come again tommorow')
return exit()
else:
return choice()
def jackpot():
global money
print()
print('Woah you won 1 million dollers!')
money+=1000000
print('Congratulations!')
balance()
print('Sorry but the game went bankrupt because of you,we had to shut down')
print('Have a nice day')
return exit()
def balance():
global money
print('Your current balance is ',money)
if __name__ == '__main__':
money=100
a={'u_1':' ',\
'u_2':' ',\
'u_3':' ',\
'm_1':' ',\
'm_2':' ',\
'm_3':' ',\
'l_1':' ',\
'l_2':' ',\
'l_3':' '} #co-ordinates
key=['u_1','u_2','u_3','m_1','m_2','m_3','l_1','l_2','l_3']
slot_machine_start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment