Advertisement
kingbode

Untitled

Sep 11th, 2023
949
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.82 KB | None | 0 0
  1. import os
  2. import time
  3. import math
  4. import pyfiglet
  5.  
  6. # clear the screen
  7. def clearScreen():
  8.     if os.name == 'nt':
  9.         os.system('cls')
  10.     else:
  11.         os.system('clear')
  12.  
  13.  
  14. def updateStock(remainingEggs):
  15.     # open the file in read and write mode
  16.     stockUpdated = False
  17.     with open("Chk_Pjt.txt", "r+") as Chk_Pjt:
  18.         lines = Chk_Pjt.readlines()
  19.         for line in reversed(lines):
  20.             if line.startswith('Number of eggs stock is :'):
  21.                 number = float(line.split(":")[1].strip())
  22.                 new_number = number + remainingEggs
  23.                 line = f'Number of eggs stock is :{new_number}\n'
  24.                 l = str(line)
  25.                 Chk_Pjt.write(l)
  26.                 stockUpdated = True
  27.                 continue
  28.  
  29.     if not stockUpdated:
  30.         with open("Chk_Pjt.txt", "a") as Chk_Pjt:
  31.             Chk_Pjt.write(f'Number of eggs stock is :{remainingEggs}\n')
  32.             Chk_Pjt.write('<<--------------------------------------------------->>\n')
  33.  
  34.  
  35.  
  36.  
  37. name = pyfiglet.figlet_format('Chicken Project')
  38. print(name)
  39.  
  40. Chk_Pjt=open('Chk_Pjt.txt','a')
  41. login = input('Enter your text : ')
  42. if login == 'log-info':
  43.  
  44.       Chk_Pjt.write('>> '+ str(time.ctime()))
  45.  
  46.       eggsCount = int(input('>>Enter Number of eggs Product :'))
  47.       soldEggsCount = int(input('>>Enter Number of eggs sold :'))
  48.       remainingEggs = eggsCount - soldEggsCount
  49.  
  50.       eggPrince = float(input('>>Enter egg unit price (dh) :'))
  51.  
  52.       eggsTotalPrice = eggPrince * eggsCount
  53.  
  54.  
  55.       lostAmount = float(input('>>How much lost money of production that eggs :'))
  56.  
  57.       netProfit = eggsTotalPrice - lostAmount
  58.  
  59.       Chk_Pjt.write(f'\n\tNumber of eggs Product is : {str(eggsCount)}\n')
  60.  
  61.       Chk_Pjt.write(f'\tNumber of eggs sold is : {str(soldEggsCount)}\n')
  62.  
  63.       Chk_Pjt.write(f'\tone eggs price is : {str(eggPrince)} DH\n')
  64.  
  65.       Chk_Pjt.write(f'\tThe price of all eggs is : {str(eggsTotalPrice)} DH\n')
  66.  
  67.       Chk_Pjt.write(f'\tlost money of production that eggs is : {str(lostAmount)} DH\n')
  68.       Chk_Pjt.write('\t-------------------------\n')
  69.  
  70.       Chk_Pjt.write(f'\tYour profits is : {str(netProfit)} DH\n')
  71.       Chk_Pjt.write('\t-------------------------\n')
  72.  
  73.       Chk_Pjt.write('<<--------------------------------------------------->>\n')
  74.       Chk_Pjt.close()
  75.  
  76.       # update the stock
  77.       updateStock(remainingEggs)
  78.  
  79.  
  80.       if netProfit<0:
  81.           clearScreen()
  82.           print (pyfiglet.figlet_format('00000'))
  83.  
  84.       elif netProfit>0:
  85.           clearScreen()
  86.           print (pyfiglet.figlet_format('1111'))
  87.  
  88.       elif netProfit==0:
  89.           clearScreen()
  90.           print (pyfiglet.figlet_format('----------'))
  91.  
  92. elif login=='info-file':
  93.       Chk_Pjt = open('file_chk-pjt','r')
  94.       text = Chk_Pjt.read()
  95.  
  96.       Chk_Pjt.close()
  97.       print (repr(text))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement