473,396 Members | 2,050 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

how to make the main function

I am struggle to make the main founction.
here is my code:

Expand|Select|Wrap|Line Numbers
  1.    import tools2         #My code is going the right     thing but just need several statements
  2.     import os      #the requirements are Functions must have 24 statements or less 
  3.  
  4.         def main():    #and The maximum number of return statements allowed in any function is 2.
  5.             filename = input("Enter filename: ")
  6.             while not os.path.isfile(filename):
  7.             print("File doesn't exist!")
  8.                 filename = input("Enter filename: ")
  9.             infile = open(filename)
  10.             lanes = infile.readlines()
  11.             years = []
  12.             for lane in lanes:
  13.                  weeks = lane.split(',')
  14.                  days = weeks[0]
  15.                  year = int(days[0:4])
  16.                  if year not in years:
  17.                      years.append(year)
  18.             print('Years in file =', years)
  19.             year_q = input("Enter year to summarise (q to     quit): ")
  20.             while not year_q == 'q' and int(year_q) not in     years:
  21.                 print("Year not in file!")
  22.                 print('Years in file =', years)
  23.                 year_q = input("Enter year to summarise (q to quit): ")
  24.             while year_q != 'q':
  25.                 year_q = int(year_q)
  26.                 years_lanes = []
  27.                 for lane in lanes:
  28.                     split = lane.split(',')
  29.                     day_to = split[0]
  30.                     day_month = int(day_to[4:6])
  31.                     daily = int(day_to[0:4])
  32.                     if daily == year_q:
  33.                         years_lanes.append(lane)
  34.                 month_rs = [0]*13
  35.                 month_qs = [0]*13
  36.                 for month in range(1,13):
  37.                     month_revenue = 0
  38.                     number = 0
  39.                     for lane in years_lanes:
  40.                         split = lane.split(',')
  41.                         day_to = split[0]
  42.                         day_month = int(day_to[4:6])
  43.                         daily = int(day_to[0:4])
  44.                         if day_month == month:
  45.                             lane = split[1]
  46.                             count = split[2]
  47.                             price = tools2.letter_price    (lane, count)
  48.                             quilty = int(split[3])
  49.                             Revenue = price * quilty
  50.                             month_revenue = month_revenue + Revenue
  51.                     month_rs[month] = month_revenue
  52.                 print()
  53.                 print()
  54.                 print('Summary for', year_q)
  55.                 print()
  56.                 print('{:>6}{:>16}'.format('Month','Total     Revenue'))
  57.                 for month in range(1, 13):
  58.                     print('{:>6}{:>16.2f}'.format    (month,month_rs[month]))
  59.                 year_revenue = 0 
  60.                 for month in range(1,13):
  61.                     year_revenue = year_revenue + month_rs[month]
  62.                 print('{:>6}{:>16.2f}'.format('TOTAL',year_revenue))
  63.                 print()
  64.                 print()
  65.                 print()
  66.                 print('Years in file =', years)
  67.                 year_q = input("Enter year to summarise (q to quit): ")
  68.                 while not year_q == 'q' and int(year_q) not in years:
  69.                     print("Year not in file!")
  70.                     print('Years in file =', years)
  71.                     year_q = input("Enter year to     summarise (q to quit): ")
  72.            main()
  73.  
  74. So this is what I done so far and the result is correct. However the other requirments are 
  75.  
  76. •Functions must have 24 statements or less. 
  77.  
  78. •The maximum number of return statements allowed in any function is 2.
  79.  
  80. so that mean I need to do the several statements to complete this code :(
  81. But I tried to slove the problem but failed :(
  82.  
  83. here is my file:
  84. filename : sales0.txt
  85.  
  86. and content is :
  87. 20101113,p,parauri,3120120830,s,kikorangi,9820130105,z,waiporoporo,3920141027,r,kowhai,12
  88.  
  89. so for example the  20101113,p,parauri,31 means 31 parauri p's were sold on the 13th day of the 11th month in 2010.
  90. and to cauclute the letter_price this is the fountion is :
  91.  
  92.     import hashlib
  93.     def letter_price(letter, colour):
  94.         """ Returns the price of a letter in dollars, as a float """
  95.         if letter == " ":
  96.             price = 0
  97.         else:
  98.             digest = hashlib.sha1((letter+colour).encode("utf8", "ignore")).hexdigest()
  99.             hex_str = "0x" + digest[-4:]
  100.             price = (int(hex_str, 16) % 300 + 100) / 100
  101.         return price
  102.  
any suggestion whould be appreciate :)
Sep 25 '14 #1
0 997

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: wongjoekmeu | last post by:
Hello All, >From a book where I have learned C++ it says that each application must have at least one function which is the main() function. Now I have the source code of a C++ program from...
89
by: Sweety | last post by:
hi, Is main function address is 657. its show in all compiler. try it & say why? bye,
1
by: wayne.denier | last post by:
Ran across this well documented, nice looking library for C++ gaming called Amaltheia ( http://home.gna.org/amaltheia/ ), but they don't have a community :P. I'm not sure if anybody has used it...
19
by: beliavsky | last post by:
I think I read a suggestion somewhere to wrap the code where a Python script starts in a main() function, so one has def main(): print "hi" main() instead of
50
by: LaundroMat | last post by:
Suppose I have this function: def f(var=1): return var*2 What value do I have to pass to f() if I want it to evaluate var to 1? I know that f() will return 2, but what if I absolutely want to...
1
by: shiniskumar | last post by:
i go tto perform some validation while ck=liking a button without refreshing the value.. i used ajax.My code is as follows...on button click i call the function validateGridAdd(); Inside tat...
3
by: zaeminkr | last post by:
I have class member data which is a pointer to class member function. However, I'm fail to compile the code. What is the correct grammar to make a function call by using static member data...
28
by: ravi | last post by:
Hello everybody, I am writing a small application which does some work before the user main function starts execution. I am trying to #define the main function. But the problem is that,
11
by: aarklon | last post by:
Hi all, I have heard many discussions among my colleagues that main is a user defined function or not. arguments in favour:- 1) if it is built in function it must be defined in some header...
2
by: Samant.Trupti | last post by:
Hi, Does main function support unicode? int main( int argc, char** argv ) can I say int mainw( int argc, wchar_t** argv )? Thanks Trupti
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.