def time_convert(sec): """ Description: :we are define function as time_convert parameters: :in hours converted into mins :in mins converted into sec """ mins = sec // 60 #sec = sec % 60 hours = mins // 60 #mins = mins % 60 logger.info("Time Lapsed = {0}:{1}:{2}".format(int(hours), int(mins), sec))
def AddCouponNumber(): """ Description: :we define function as AddCouponNumber Parameters: :give input in integer format.""" try: couponSet = set() condition = True while condition == True: userCoupon = int(input('enter distinct numbers: ')) for i in couponSet: if i == userCoupon: logger.info( 'number already exists, enter different number') couponSet.add(userCoupon) logger.info('Number added: ') logger.info(userCoupon) anotherNumber = input( 'to add another number enter y, or enter any other key to stop: ' ) if anotherNumber == 'y' or anotherNumber == 'Y': condition = True elif anotherNumber == 'n' or anotherNumber == 'N': condition = False else: #print('enter correct option') condition = False sortedUserCoupon = sorted(couponSet) firstElement = sortedUserCoupon[0] lastElement = sortedUserCoupon[len(sortedUserCoupon) - 1] Coupons = set() condition2 = True while condition2 == True: randomCoupon = random.randint(firstElement, lastElement) logger.info('generated coupon: ') logger.info(randomCoupon) Coupons.add(randomCoupon) logger.info('Coupon set is:') generateAnotherCoupon = input( 'enter y to generate another coupon, or press any other key to see all generated coupons: ' ) if generateAnotherCoupon == 'y' or generateAnotherCoupon == 'Y': condition2 = True else: condition2 = False logger.info(Coupons) except Exception as e: logger.info(e)
def main_game(): turn = 'X' count = 0 for i in range(1, 10): printBoard(theBoard) logger.info("It's your turn," + turn + "Enter the number between 1 to 9 :") move = input() if theBoard[move] == ' ': theBoard[move] = turn count += 1 else: logger.info("That place is already filled.\nMove to which place?") continue if count >= 5: if theBoard['7'] == theBoard['8'] == theBoard['9'] != ' ': printBoard(theBoard) logger.info("\nGame Over.\n") logger.info(" **** " + turn + " won. ****") break elif theBoard['4'] == theBoard['5'] == theBoard['6'] != ' ': printBoard(theBoard) logger.info("\nGame Over.\n") logger.info(" **** " + turn + " won. ****") break elif theBoard['1'] == theBoard['2'] == theBoard['3'] != ' ': printBoard(theBoard) logger.info("\nGame Over.\n") logger.info(" **** " + turn + " won. ****") break elif theBoard['1'] == theBoard['4'] == theBoard['7'] != ' ': printBoard(theBoard) logger.info("\nGame Over.\n") logger.info(" **** " + turn + " won. ****") break elif theBoard['2'] == theBoard['5'] == theBoard['8'] != ' ': printBoard(theBoard) logger.info("\nGame Over.\n") logger.info(" **** " + turn + " won. ****") break elif theBoard['3'] == theBoard['6'] == theBoard['9'] != ' ': printBoard(theBoard) logger.info("\nGame Over.\n") logger.info(" **** " + turn + " won. ****") break elif theBoard['7'] == theBoard['5'] == theBoard['3'] != ' ': printBoard(theBoard) logger.info("\nGame Over.\n") logger.info(" **** " + turn + " won. ****") break elif theBoard['1'] == theBoard['5'] == theBoard['9'] != ' ': printBoard(theBoard) logger.info("\nGame Over.\n") logger.info(" **** " + turn + " won. ****") break if count == 9: logger.info("\nGame Over.\n") logger.info("Draw!!") if turn == 'X': turn = 'O' else: turn = 'X'
def printBoard(board): logger.info(board['1'] + ' | ' + board['2'] + ' | ' + board['3']) logger.info('- + - + -') logger.info(board['4'] + ' | ' + board['5'] + ' | ' + board['6']) logger.info('- + - + -') logger.info(board['7'] + ' | ' + board['8'] + ' | ' + board['9'])
from Logicallog import logger logger.setLevel(logging.INFO) try: def time_convert(sec): """ Description: :we are define function as time_convert parameters: :in hours converted into mins :in mins converted into sec """ mins = sec // 60 #sec = sec % 60 hours = mins // 60 #mins = mins % 60 logger.info("Time Lapsed = {0}:{1}:{2}".format(int(hours), int(mins), sec)) input("Press A to start :") start_time = time.time() input("Press S to stop :") end_time = time.time() time_lapsed = end_time - start_time time_convert(round(time_lapsed)) except Exception as e: logger.info(e)
#initially Stake and goal stake = 100 goal = 200 #initially win=0 and loose=0 win = 0 loose = 0 #while loop till gambler stake=0 or stake =goal(200) while (stake > 0 and stake < goal): # random var for win or loose gamble = random.randint(0, 1) if gamble == 0: # if gambler looses stake-1 and number of loose-1 stake -= 1 loose += 1 else: # if wins stake++ and win++ stake += 1 win += 1 #printing number of wins logger.info("number of wins: ") logger.info(win) winPercentage = (win * 100) / (win + loose) losspercentage = 100 - winPercentage #printing win percentage logger.info("win percentage is: ") logger.info(winPercentage) logger.info("Loss percentage is: ") logger.info(losspercentage) except Exception as e: logger.info(e)