I am struggle to make the main founction.
here is my code: - import tools2 #My code is going the right thing but just need several statements
-
import os #the requirements are Functions must have 24 statements or less
-
-
def main(): #and The maximum number of return statements allowed in any function is 2.
-
filename = input("Enter filename: ")
-
while not os.path.isfile(filename):
-
print("File doesn't exist!")
-
filename = input("Enter filename: ")
-
infile = open(filename)
-
lanes = infile.readlines()
-
years = []
-
for lane in lanes:
-
weeks = lane.split(',')
-
days = weeks[0]
-
year = int(days[0:4])
-
if year not in years:
-
years.append(year)
-
print('Years in file =', years)
-
year_q = input("Enter year to summarise (q to quit): ")
-
while not year_q == 'q' and int(year_q) not in years:
-
print("Year not in file!")
-
print('Years in file =', years)
-
year_q = input("Enter year to summarise (q to quit): ")
-
while year_q != 'q':
-
year_q = int(year_q)
-
years_lanes = []
-
for lane in lanes:
-
split = lane.split(',')
-
day_to = split[0]
-
day_month = int(day_to[4:6])
-
daily = int(day_to[0:4])
-
if daily == year_q:
-
years_lanes.append(lane)
-
month_rs = [0]*13
-
month_qs = [0]*13
-
for month in range(1,13):
-
month_revenue = 0
-
number = 0
-
for lane in years_lanes:
-
split = lane.split(',')
-
day_to = split[0]
-
day_month = int(day_to[4:6])
-
daily = int(day_to[0:4])
-
if day_month == month:
-
lane = split[1]
-
count = split[2]
-
price = tools2.letter_price (lane, count)
-
quilty = int(split[3])
-
Revenue = price * quilty
-
month_revenue = month_revenue + Revenue
-
month_rs[month] = month_revenue
-
print()
-
print()
-
print('Summary for', year_q)
-
print()
-
print('{:>6}{:>16}'.format('Month','Total Revenue'))
-
for month in range(1, 13):
-
print('{:>6}{:>16.2f}'.format (month,month_rs[month]))
-
year_revenue = 0
-
for month in range(1,13):
-
year_revenue = year_revenue + month_rs[month]
-
print('{:>6}{:>16.2f}'.format('TOTAL',year_revenue))
-
print()
-
print()
-
print()
-
print('Years in file =', years)
-
year_q = input("Enter year to summarise (q to quit): ")
-
while not year_q == 'q' and int(year_q) not in years:
-
print("Year not in file!")
-
print('Years in file =', years)
-
year_q = input("Enter year to summarise (q to quit): ")
-
main()
-
-
So this is what I done so far and the result is correct. However the other requirments are
-
-
•Functions must have 24 statements or less.
-
-
•The maximum number of return statements allowed in any function is 2.
-
-
so that mean I need to do the several statements to complete this code :(
-
But I tried to slove the problem but failed :(
-
-
here is my file:
-
filename : sales0.txt
-
-
and content is :
-
20101113,p,parauri,3120120830,s,kikorangi,9820130105,z,waiporoporo,3920141027,r,kowhai,12
-
-
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.
-
and to cauclute the letter_price this is the fountion is :
-
-
import hashlib
-
def letter_price(letter, colour):
-
""" Returns the price of a letter in dollars, as a float """
-
if letter == " ":
-
price = 0
-
else:
-
digest = hashlib.sha1((letter+colour).encode("utf8", "ignore")).hexdigest()
-
hex_str = "0x" + digest[-4:]
-
price = (int(hex_str, 16) % 300 + 100) / 100
-
return price
-
any suggestion whould be appreciate :)
0 997 Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
by: Sweety |
last post by:
hi,
Is main function address is 657.
its show in all compiler.
try it & say why?
bye,
|
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...
|
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
|
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...
|
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...
|
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...
|
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,
|
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...
|
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
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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...
|
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,...
|
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...
|
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,...
| |