Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,150,839 members, 7,810,224 topics. Date: Saturday, 27 April 2024 at 12:49 AM

Design A Module Program - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Design A Module Program (5993 Views)

Learn How To Design A Website / How To Build And Design A Mobile Application Like 2go, Whatsapp, Mixit / What Programming Languages Do I Need To Design A Site Like Nairaland? (2) (3) (4)

(1) (Reply) (Go Down)

Design A Module Program by eazyd(m): 7:05pm On Feb 14, 2012
Can someone help design this module program for python.

There are three seating categories at a stadium. For a softball game, Class A seats cost $15, Class B seats cost $12, and Class C seats cost $9. Design a module program that asks how many tickets for each class of seats were sold, and then displays the amount of income generated from ticket sales.

Thanks!
Re: Design A Module Program by DonSegmond(m): 12:28am On Feb 15, 2012
No, do your homework.

Free python tutorial - http://docs.python.org/tutorial/
Re: Design A Module Program by eazyd(m): 11:15am On Feb 15, 2012
My home work is done,just want to compare and contrast! I can post what i did if someone can do it too- thats how we learn!
Re: Design A Module Program by lordZOUGA(m): 11:32am On Feb 15, 2012
I think pple here like feeling superior, So you should post your code first and I guarantee you someone will post a better code jus for kicks,
Re: Design A Module Program by eazyd(m): 11:37am On Feb 15, 2012
This is “my program”
# This program calculates the income generated from ticket sales
# Class A seats cost $15, Class B seats cost $12, Class C seats cost $9
# mainline logic
def main():
intro() # call the intro function
readInput() # call readInput function
# This function displays some introductory messages
def intro():
print("\tWelcome to the Ticket Sales Program"wink
print("\tClass A seats cost $15"wink
print("\tClass B seats cost $12"wink
print("\tClass C seats cost $9"wink
print("\tYou will be asked to enter the number of tickets sold in each of the three categories"wink
print("\tThe program will then calculate the income generated from all the sales"wink
print()
raw_input("Press any Key when you are ready to begin"wink


# This function calculates the sales from the three categories
def calcSales(numClassA, numClassB, numClassC):
salesClassA = numClassA * 15
salesClassB = numClassB * 12
salesClassC = numClassC * 9
print("The income generated for Class A seats: $%7.2f"wink % salesClassA
print("The income generated for Class B seats: $%7.2f"wink % salesClassB
print("The income generated for Class C seats: $%7.2f"wink % salesClassC
totalSales(totalSales)

# This function outputs the income generated
def outputSales(Sales):
print("\nThe total income generated for the softball game is $%7.2f"wink % sales

# call the main function
main()
Re: Design A Module Program by eazyd(m): 9:13pm On Feb 15, 2012
my outcome was an error (NameError: global name 'readInput' is not defined) and i thought i'd find help here, where all dis programmers na??  dis should be quite easy for a guru! me just start yesterday sad
Re: Design A Module Program by DonSegmond(m): 9:27pm On Feb 15, 2012
You gotta learn how to debug.

The error tells you, that "readInput" is not defined. If you paid attention, you will notice that it gave you a line number too.

So let's look at the entire error. I put your program in a file called v, and ran "python v"

Traceback (most recent call last):
File "v", line 35, in ?
main()
File "v", line 6, in main
readInput() # call readInput function
NameError: global name 'readInput' is not defined


Start from the bottom, so NameError: "readInput" not defined. It means you are trying to use a function or variable that is not defined. The system can't find it. Go up, a notch. Line 6, readInput() function, call to readInput function. Look at your line 6.

These are your defintions


def main():
def intro():
def calcSales(numClassA, numClassB, numClassC):
def outputSales(Sales):


So define readInput() to do whatever it is you want it to do, which is to get input for the 3 variables that will be passed to calcSales()
Re: Design A Module Program by eazyd(m): 9:38pm On Feb 15, 2012
i just defined it-

def readInput():
numClassA = 15
numClassB = 12
numClassC = 9

does the program makes sense to you when you ran it? i did run it but it didn't calculate the total sales!
Re: Design A Module Program by DonSegmond(m): 10:04pm On Feb 15, 2012
Well, think of it.
It runs readInput(), the numbers are defined in it, but calcSales() is not called. So you need to call calcSales() with those value after. Try it, when it works. Then instead of assigning variables the way you did. You can use raw_input()
example
val = raw_input("Enter value >")

However, note that what will be stored in val is a string, and we want it to be an integer since it's the number of tickets.
so enclose it in the int() function

val = int(raw_input("Enter value >")

Try that.
Re: Design A Module Program by eazyd(m): 10:41pm On Feb 15, 2012
@DonSegmond

do i call this function with 0 since at this point they have no value.


how do i call this function?
Re: Design A Module Program by DonSegmond(m): 11:55pm On Feb 15, 2012
eazyd:

@DonSegmond

do i call this function with 0 since at this point they have no value.


how do i call this function?


okay,

def foo():
print "foo"

foo is a function, a function that takes no value

def bar(a):
print a

bar() is a function, a function that takes a value, you call bar by passing a value or variable.

what book or website are you using?
Re: Design A Module Program by eazyd(m): 12:50pm On Feb 16, 2012
I did call the function and passed a value to it- i use Programming Logic & Design by Tony Gaddis! can you just show me some workings,i learn from examples, i have written some programs but this tend to somehow confuse me and i know its just a lil error from me but i can't see m to figure it out dats why i need help. If i get it,i know for a fact that mistake will never be made again, i read your posts and you are an expert in python. if you got time to re design this program and i will compare and contrast with what i did.That way i know what to do next time.
Re: Design A Module Program by DonSegmond(m): 7:52am On Feb 17, 2012
sorry, i can't do that for you. the problem is that you don't have some functions defined. if you know what a function is, and how to define it, then pass value to it, and return value, you should be good. if note, consult your tutorial/books, then after you understand how to do those, you can solve the problem.

you are missing the function definition for readInput() and totalSales(), with that said, read the other things I posted, and you should figure it out.
Re: Design A Module Program by Nobody: 10:10am On Feb 17, 2012
Your program in the first place is very, very wrong. The reason why your program is wrong is because you mixed python 2.x syntax and python 3.x syntax together and NO python interpreter would compile/ interpret it. print is a function in python3 while raw_input is deprecated in python 3 and only works for python 2. For some strange reasons, my python interpreter doesn't work any longer so I cant test any program but I'll try and post a simple solution in a short time. Hope it works.

Thankz
Re: Design A Module Program by Nobody: 10:36am On Feb 17, 2012
Simple solution in Python 3:
def main():
intro()
class_a()
class_b()
class_c()
total()

def intro():
print("Welcome to the ticket sales program"wink
print("Class A costs $15"wink
print("Class B costs $12"wink
print("Class C costs $9"wink
print("You will be asked to enter the number of tickets sold"wink
print("The program would calculate the income generated"wink
print()

def class_a():
ticket_a = int(input("Enter the number of tickets sold for Class A:"wink)
global cost_a
cost_a = ticket_a * 15
print()

def class_b():
ticket_b = int(input("Enter the number of tickets sold for Class B:"wink)
global cost_b
cost_b = ticket_b * 12
print()

def class_c():
ticket_c = int(input("Enter the number of tickets sold for Class C:"wink)
global cost_c
cost_c = ticket_c * 9
print()

def total():
total = cost_a + cost_b + cost_c
print("The total income generated frocm the ticket sales is $", format(total, ',.2f'), sep = '')

main()
Re: Design A Module Program by Nobody: 10:48am On Feb 17, 2012
BTW, eazyd, can I get the e-book ur using
Re: Design A Module Program by eazyd(m): 2:30pm On Feb 17, 2012
@goon i use a book called Programming Logic & Design by Tony Gaddis. Thanks for the simple module. i use python 2.
Re: Design A Module Program by eazyd(m): 2:49pm On Feb 17, 2012
@goon,can you do this in python 2 pls.
Re: Design A Module Program by Nobody: 4:11pm On Feb 17, 2012
sure, would post a python 2 solution at nite when am on pc. thankz.
Re: Design A Module Program by eazyd(m): 4:55pm On Feb 17, 2012
Thanks! show your python result too. Once i confirm where my mistake is,i will do another program and let u check for me. Thanks for your help.
Re: Design A Module Program by eazyd(m): 6:56pm On Feb 17, 2012
wow finally learnt how to return value to the functions- dats where my problem was, thanks to donsegmond for pointing this out and thanks to you too goon! i learnt something today-yaaaaaaaaaaaa cheesy i can post my restructured program here again!
Re: Design A Module Program by Nobody: 8:10pm On Feb 17, 2012
Happy u have learnt what your problem was. Anyway if u still need the python 2 solution. This is it.
Python 2 simple solution:
def main():
intro()
class_a()
class_b()
class_c()
total()

def intro():
print "Welcome to the ticket sales program"
print "Class A costs $15"
print "Class B costs $12"
print "Class C costs $9"
print "You will be asked to enter the number of tickets sold"
print "The program would calculate the income generated"
print ""

def class_a():
ticket_a = input("Enter the number of tickets sold for Class A:"wink
global cost_a
cost_a = ticket_a * 15
print ""

def class_b():
ticket_b = input("Enter the number of tickets sold for Class B:"wink
global cost_b
cost_b = ticket_b * 12
print ""

def class_c():
ticket_c = input("Enter the number of tickets sold for Class C:"wink
global cost_c
cost_c = ticket_c * 9
print ""

def total():
total = cost_a + cost_b + cost_c
print "The total income generated from the ticket sales is $%.2f" %(total)

main()
Re: Design A Module Program by eazyd(m): 12:58am On Feb 18, 2012
This is my new program,i had to read the book again and i finally sort it out.

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

# This program calculates the total revenue of ticket sold at a softball game
# Initialize variables
ClassA = 15
ClassB = 12
ClassC = 9



def main():
intro() # call intro
ticketA = totalsoldA() # call totalsoldA function
ticketB= totalsoldB() # call totalsoldB function
ticketC= totalsoldC() # call totalsoldB function
revenueA= totalrevenueA(ticketA) # call totalrevenueA function
revenueB= totalrevenueB(ticketB) # call totalrevenueB function
revenueC= totalrevenueC(ticketC) # call totalrevenueC function
totalSales(revenueA,revenueB,revenueC) # call totalSales function

def intro():
print ("There are 3 seating categories in this staduim"wink
print ("ClassA cost $15"wink
print ("ClassB cost $12"wink
print ("ClassC Cost $9"wink
print ("This program will calculate the total revenue of tickets sold"wink

def totalsoldA():
print ("Enter the number of ticket sold in A."wink
totalsoldA= input ()
return totalsoldA

def totalsoldB():
print ("Enter the number of ticket sold in B."wink
totalsoldB= input ()
return totalsoldB

def totalsoldC():
print ("Enter the number of ticket sold in C."wink
totalsoldC= input ()
return totalsoldC

def totalrevenueA(totalsoldA):
totalrevenueA = totalsoldA * ClassA
return totalrevenueA

def totalrevenueB(totalsoldB):
totalrevenueB = totalsoldB * ClassB
return totalrevenueB

def totalrevenueC(totalsoldC):
totalrevenueC = totalsoldC * ClassC
return totalrevenueC

def totalSales(totalrevenueA,totalrevenueB,totalrevenueC):
totalSales = totalrevenueA + totalrevenueB + totalrevenueC
print "This is the total amount sold in all class of seats.$%7.2f"% totalSales

# call the main function
main()


--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Re: Design A Module Program by Nobody: 8:20pm On Feb 18, 2012
Well, ur code works fine but is far too complex for this very simple task. Next time, try to make your code as short and little as possible.
Thankz
Re: Design A Module Program by eazyd(m): 9:28pm On Feb 18, 2012
yea my friend told me that bt i will learn how to simplify my code as i learn , i'm jst glad i accomplished a goal this week and i'm also practicing on 2 other programs,if i get hooked i'll sure ask for your help , goon.whrs ur location?
Re: Design A Module Program by eazyd(m): 9:30pm On Feb 18, 2012
one more thing--ive tried to desk check my program according to the book but with so many lines i get confused where to start and what line to check.Can you help me on that?
Re: Design A Module Program by smile4kenn(m): 2:40am On Feb 19, 2012
thats wassup,

thats what am talking about
Re: Design A Module Program by Nobody: 6:42am On Feb 19, 2012
eazyd:

yea my friend told me that bt i will learn how to simplify my code as i learn , i'm jst glad i accomplished a goal this week and i'm also practicing on 2 other programs,if i get hooked i'll sure ask for your help , goon.whrs ur location?
I reside in Port-Harcourt but school at Enugu.
Re: Design A Module Program by Nobody: 6:48am On Feb 19, 2012
eazyd:

one more thing--ive tried to desk check my program according to the book but with so many lines i get confused where to start and what line to check.Can you help me on that?
Instead of spending too much time on desk-checking, Y dont U only come up with good pseudo-code and flowchart
Re: Design A Module Program by eazyd(m): 9:36pm On Feb 19, 2012
@smile4kenn-- na so we see am oo.
@goon- i had a pseudocode before i wrote the program but following the book, u need to desk check(hand-trace) for errors. Its time consuming since my programs got like 40 lines. I just wana know hw to. Can you do a desk check?

(1) (Reply)

I Want To Learn Programming In 2018 / Mobile Phone Application Programming / Check My App Pin Pals Out

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 44
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.