def stopwatch(sec): logger.setLevel(logging.INFO) """ import time package define function for stopwatch format time b/w start and end clicks """ min = (sec // 3600)//60 sec = ((sec % 3600)%60) hours = min//3600 logger.info('%02d:%02d:%02d' %(hours, min, sec))
def coupon_number(number_of_coupons): logger.setLevel(logging.INFO) """ get input from user to genearte n random coupon numbe check the random numbers in loop check the number is not in random nums and append the number is random_nums list """ coupons = 0 random_numbers = 0 random_nums = [] while coupons != number_of_coupon: number = random.randint(1, 10**4) if number not in random_nums: random_nums.append(number) coupons += 1 logger.info(random_nums)
def gambler(stake,goal,number_of_times): logger.setLevel(logging.INFO) """ :param stake: initial amaount :param goal: goal to reach particular amount :return: win or loss while loop till gambler stake=0 or stake =goal(200) random var for win or loose if gambler looses stake-1 and number of loose-1 increment wins stake++ and win++ printing number of bets printing win percentage """ # initially win=0 and loose=0 bets=0 win=0 # while loop till gambler stake=0 or stake =goal(200) while win!=goal and stake!=0: # random var for win or loose num=random.random() if num<0.5: # if gambler looses stake-1 and number of loose-1 bets+=1 win+=1 else: # if wins stake++ and win++ bets+=1 stake-=1 loss_percentage=((bets-win)/bets)*100 win_percentage=(win/bets)*100 # printing number of bets logger.info(f"Total number of bets = {bets}") # printing number of wins logger.info(f"Total win = {win}") # printing win percentage logger.info(f"win percentage ={win_percentage}") logger.info(f"loss percentage ={loss_percentage}")
for mv in tup: if move == -1 and can_move(board, computer, mv): move = mv break return make_move(board, computer, move) def space_exist(): """check board if board is full than try to another block else game is tie using conditional statement use and check print valid sign or not""" return board.count('X') + board.count('O') != 9 try: player, computer = select_char() logger.info('Player is [%s] and computer is [%s]' % (player, computer)) result = '-----! Drawn, game tie' while space_exist(): print_board() print(end='') logger.info('Make your move ! [1-9] : ')\ move = int(input()) moved, won = make_move(board, player, move) if not moved: logger.info(' Invalid number, Please Try again ') continue if won: result = ' Congratulations ! You won ' break elif computer_move()[1]:
from logicallog import logger while True: try: """given user Input Enter ammount stake and goal given User Input How many times play the user""" stake = int(input("Enter the amount you want to stake :")) goal = int(input("Enter your goal:")) #given User Input How many times play the user number_of_times = int(input("How many times you want to play:")) if stake>0 and goal>0 and number_of_times>0: break else: logger.info("Invalid input!!") except: logger.info("Invalid input!!") def gambler(stake,goal,number_of_times): logger.setLevel(logging.INFO) """ :param stake: initial amaount :param goal: goal to reach particular amount :return: win or loss while loop till gambler stake=0 or stake =goal(200) random var for win or loose if gambler looses stake-1 and number of loose-1 increment wins stake++ and win++ printing number of bets printing win percentage
""" date = '27/04/2021' modified_date = '28/04/2021' author = 'Mahesh Naik' description =crete text file and perform read write operation""" import logging from logicallog import logger logger.setLevel(logging.INFO) """read and write text file using read,write function using append function add data in text file""" with open('simple.txt', 'w') as f: a = f.write('hello mahesh how are you') print(a) with open('simple.txt','r') as f: a = f.read() f= open('simple.txt','r') data = f.read() logger.info(data) f.close()
from logicallog import logger logger.setLevel(logging.INFO) data = {} data['people'] = [] data['people'].append({ 'name': 'Mahesh', 'website': 'naikmahesh.com', 'from': 'Kolhapur' }) data['people'].append({ 'name': 'sagar', 'website': 'google.com', 'from': 'Latur' }) data['people'].append({ 'name': 'Sheetal', 'website': 'apple.com', 'from': 'Nashik' }) with open('data.json', 'w') as outfile: json.dump(data, outfile) with open('data.json') as json_file: data = json.load(json_file) for p in data['people']: logger.info('Name: ' + p['name']) logger.info('Website: ' + p['website']) logger.info('From: ' + p['from']) logger.info('')