Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import random
- coin = 0
- def LoadGame(fname):
- global coin
- if(os.path.exists(fname)):
- print('\nLoading.....')
- load_file = open(fname,"r")
- coin = int(load_file.read())
- load_file.close()
- print('Saved game loaded...\n\n')
- print(f'your coin is now {coin}\n\n')
- Game()
- else:
- print(f'\nNo saved file for user {fname}\n\n')
- def GaveSave(fname):
- global coin
- game_file = open(fname,"w")
- game_file.write(str(coin))
- game_file.close()
- print("\nGame is Saved Successfully!\n\n")
- def Game():
- global coin
- bet = eval(input('how much will you bet? : '))
- if bet > coin:
- print('\nNo... you cannot bet that much')
- print(f'you only have {coin}')
- print(f'your bet become {coin}')
- bet = coin
- input('\npress any key to roll..')
- me = random.randint(1,6)
- print(f'your number is {me}')
- print('\ncomputer turn')
- comp = random.randint(1,6)
- print(f'computer number is {comp}')
- print()
- if(comp>me):
- print('computer wins')
- coin = coin - bet
- elif(comp<me):
- print('you win')
- coin = coin + bet
- else:
- print('draw')
- print(f'\nyour coin is {coin}')
- if coin == 0:
- print('\nyou need to buy more coin')
- print('will you buy or exit?')
- ans = input('y/n? ')
- if ans == 'y':
- coin = int(input('\nhow many coin: '))
- else:
- print('\n\nSee you next time buddy!')
- exit()
- # Program start here
- os.system('clear') # for windows use cls
- name = input('enter your name: ')
- # Aung Win Htut -> aung_win_htut
- print(name)
- name = name.lower()
- print(name)
- name = name.replace(" ","_")
- print(name)
- file_name = name + ".txt"
- coin = int(input('how many coin? :'))
- while(True):
- print('1 - Play Game')
- print('2 - Save Game')
- print('3 - Load Game')
- print('0 - Exit')
- ans = input('0, 1, 2 or 3 ? : ')
- if(ans=='1'):
- print('\nPlaying Game...')
- Game()
- print()
- elif(ans=='2'):
- GaveSave(file_name)
- elif(ans=='3'):
- LoadGame(file_name)
- elif(ans=='0'):
- print('Exiting now...')
- print()
- exit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement