Re: [Tutor] Python Assignment
On 03/08/16 18:58, Justin Korn via Tutor wrote: > This is what I have so far: OK, This is starting to look a bit random. You need to slow down and work through what is happening in each method and especially what data is being passed around where. At the moment it makes no sense whatsoever. > def load_file(): > with open("warehouse_data.txt") as infile: > for line in infile: > data = process_line(line) Where is process_line defined? And what happens to data? At the moment its a local variable that disappears when load_file terminates. > class Order(): > def __init__(self, order_number): > self.order_number = order_number > > def add_item(): > order = [] > order.append() What do you think this does? It takes no input values and appends nothing(*) to a list that is deleted at the end of the function. I'm pretty certain that's not what you want. (*) In fact append will error because it needs an input value. > def sort_key(): > all_keys = [] > for item in self.order_number: > all_keys.append(item.sort_key()) > return min(all_keys) You are looping over self.order_number. What kind of data is order_number? What kind of data will item be? Does item have a sort_key() method? Also neither function has a self parameter so will not be usable methods of the class. > class LineItem(): > def __init__(self, orderNumber, partNumber, quantityNumber, aisleNumber, > shelfNumber, binNumber): > self.orderNumber = orderNumber > self.partNumber = partNumber > self.quantityNumber = quantityNumber > self.aisleNumber = aisleNumber > self.shelfNumber = shelfNumber > self.binNumber = binNumber > > def sort_key(): > p = (self.aisleNumber, self.shelfNumber, self.binNumber) > for i in p: > p.sort(i.sort_key()) > return(self.aisleNumber, self.shelfNumber * -1, self.binNumber) Look at what the loop is doing. It iterates over three values and tries to sort the tuple p based on a sort_key method of each value. But do those values have a sort_key() method?. And does sorting p achieve anything? I assume you didn't try running this code since it would result in errors. You need to sort out the data types and use them consistently. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Python Assignment
To whom it may concern, I need someone to make changes to the following assignment: XYZ Corporation sells products online. The company has a large warehouse in which it stores its inventory of products. Orders are picked, packed and shipped from the warehouse. XYZ Corporation has contracted with you to write a program that will minimize the number of steps that the staff in the warehouse (called ODA's) take in picking the products ordered by customers. The information you will need to complete this assignment are in the following files: Specifications: CTIM285_Summer_2016_FinalExam.pdf Warehouse Map: WarehouseImage.pdf Data for Analysis: warehouse_data_final_exam_Python.txt Data for Analysis is saved in this order on each line of the file: [orderNumber, partNumber, quantyNumber, aisleNumber, shelfNumber, binNumber] This is what I have so far: def load_file(): with open("warehouse_data.txt") as infile: for line in infile: data = process_line(line) class Order(): def __init__(self, order_number): self.order_number = order_number def add_item(): order = [] order.append() def sort_key(): all_keys = [] for item in self.order_number: all_keys.append(item.sort_key()) return min(all_keys) class LineItem(): def __init__(self, orderNumber, partNumber, quantityNumber, aisleNumber, shelfNumber, binNumber): self.orderNumber = orderNumber self.partNumber = partNumber self.quantityNumber = quantityNumber self.aisleNumber = aisleNumber self.shelfNumber = shelfNumber self.binNumber = binNumber def sort_key(): p = (self.aisleNumber, self.shelfNumber, self.binNumber) for i in p: p.sort(i.sort_key()) return(self.aisleNumber, self.shelfNumber * -1, self.binNumber) def __str__(self): return("{} {} {} {} {} {}".format(self.aisleNumber, self.shelfNumber, self.binNumber, self.orderNumber, self.partNumber, self.quantityNumber)) Thanks, Justin ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python Assignment
On 03/08/16 06:34, Justin Korn via Tutor wrote: > Data for Analysis is saved in this order on each line of the file: > [orderNumber, partNumber, quantyNumber, aisleNumber, shelfNumber, binNumber] > > > This is what I have so far: > > infile = open("warehouse_data.txt", "r") > > class Order(): > def __init__(self, order_number, line_items): > self.order_number = order_number > line_items = line_items You use self for the order_number but not for the line_items? Also, are you really planning on building a collection of line items per order before you create the order? Or might it be better to create the order for the first identified line item and then add() subsequent line items as you find them? Just a thought... > class LineItem(): > def __init__(self, orderNumber, partNumber, quantityNumber, aisleNumber, > shelfNumber, binNumber): > self.orderNumber = orderNumber > self.partNumber = partNumber > self.quantityNumber = quantityNumber > self.aisleNumber = aisleNumber > self.shelfNumber = shelfNumber > binNumber = binNumber And similarly you do not use self for bin_number In each case the values without self will be thrown away when the __init__() method exits. Other than that issue it's a fair start in that you now have two classes that can be used to store the data in the file. Your next step is presumably to read the file into objects of these classes. Finally, I'm guessing you'll want to sort the line items into groups based on their location so that the warehouse pickers don't need to visit the same area twice. I'm not clear whether that should be limited per order or to all the line items per batch and the collected items assembled into orders later. I'm assuming that the items are picked by order... but the assignment doesn't seem to specify. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Python Assignment
To whom it may concern, I need help creating a program for the following assignment: XYZ Corporation sells products online. The company has a large warehouse in which it stores its inventory of products. Orders are picked, packed and shipped from the warehouse. XYZ Corporation has contracted with you to write a program that will minimize the number of steps that the staff in the warehouse (called ODA's) take in picking the products ordered by customers. The information you will need to complete this assignment are in the following files: Specifications: CTIM285_Summer_2016_FinalExam.pdf Warehouse Map: WarehouseImage.pdf Data for Analysis: warehouse_data_final_exam_Python.txt Data for Analysis is saved in this order on each line of the file: [orderNumber, partNumber, quantyNumber, aisleNumber, shelfNumber, binNumber] This is what I have so far: infile = open("warehouse_data.txt", "r") class Order(): def __init__(self, order_number, line_items): self.order_number = order_number line_items = line_items class LineItem(): def __init__(self, orderNumber, partNumber, quantityNumber, aisleNumber, shelfNumber, binNumber): self.orderNumber = orderNumber self.partNumber = partNumber self.quantityNumber = quantityNumber self.aisleNumber = aisleNumber self.shelfNumber = shelfNumber binNumber = binNumber Thanks, Justin ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python Assignment
On Aug 2, 2016 4:42 AM, "Justin Korn via Tutor" wrote: > > To whom it may concern, > > I need help on this assignment: > > > Create a new class, SMS_store. The class will instantiate SMS_store objects, similar to an inbox or outbox on a cellphone: > my_inbox = SMS_store() > This store can hold multiple SMS messages (i.e. its internal state will just be a list of messages). Each message will be represented as a tuple: > (has_been_viewed, from_number, time_arrived, text_of_SMS) > The inbox object should provide these methods: > my_inbox.add_new_arrival(from_number, time_arrived, text_of_SMS) > # Makes new SMS tuple, inserts it after other messages > # in the store. When creating this message, its > # has_been_viewed status is set False. > > my_inbox.message_count() > # Returns the number of sms messages in my_inbox > > my_inbox.get_unread_indexes() > # Returns list of indexes of all not-yet-viewed SMS messages > > my_inbox.get_message(i) > # Return (from_number, time_arrived, text_of_sms) for message[i] > # Also change its state to "has been viewed". > # If there is no message at position i, return None > > my_inbox.delete(i) # Delete the message at index i > my_inbox.clear() # Delete all messages from inbox > Write the class, create a message store object, write tests for these methods, and implement the methods. > > The following attachment is what I have so far: This mailing list is not forward attachments. Instead copy your code and paste it into the email. > > > and I get the error > > Traceback (most recent call last): > File "/Applications/Python Assignments/C15E6_JustinKorn.py", line 58, in > my_inbox.get_message(i) > NameError: name 'i' is not defined > > Please help me. > > Thanks, > Justin > > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > https://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Python Assignment
To whom it may concern, I need help on this assignment: Create a new class, SMS_store. The class will instantiate SMS_store objects, similar to an inbox or outbox on a cellphone: my_inbox = SMS_store() This store can hold multiple SMS messages (i.e. its internal state will just be a list of messages). Each message will be represented as a tuple: (has_been_viewed, from_number, time_arrived, text_of_SMS) The inbox object should provide these methods: my_inbox.add_new_arrival(from_number, time_arrived, text_of_SMS) # Makes new SMS tuple, inserts it after other messages # in the store. When creating this message, its # has_been_viewed status is set False. my_inbox.message_count() # Returns the number of sms messages in my_inbox my_inbox.get_unread_indexes() # Returns list of indexes of all not-yet-viewed SMS messages my_inbox.get_message(i) # Return (from_number, time_arrived, text_of_sms) for message[i] # Also change its state to "has been viewed". # If there is no message at position i, return None my_inbox.delete(i) # Delete the message at index i my_inbox.clear() # Delete all messages from inbox Write the class, create a message store object, write tests for these methods, and implement the methods. The following attachment is what I have so far: and I get the error Traceback (most recent call last): File "/Applications/Python Assignments/C15E6_JustinKorn.py", line 58, in my_inbox.get_message(i) NameError: name 'i' is not defined Please help me. Thanks, Justin ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python Assignment
On Mon, Aug 1, 2016 at 8:18 AM, Justin Korn via Tutor wrote: > To whom it may concern, > I need someone to help me to develop programs for the following assignments. You've asked a few questions earlier: https://mail.python.org/pipermail/tutor/2016-July/109403.html https://mail.python.org/pipermail/tutor/2016-July/109406.html That you have to take care of a sick relative is laudable. But mentioning it multiple times is not helpful: it sounds more like an emotional manipulation. It does not look sincere if you mention it every time you're asking for technical help. That being said, a situation like that *can* be a legitimate, major factor behind why you're having difficulty with the problem. And if that's the case, you *need* to talk with your professor or instructor. We're not the right audience to solve the real problem that you're encountering. Most teachers are often pretty good about considering extraordinary circumstances when setting things like deadlines, and they may give some allowance for your situation. Try talking with your instructor. Looking back at your question: it's possible that English isn't your first language, so you may not realize how poorly the questions are stated. This style of stating a problem statement and asking for a solution is not likely to be fruitful. This is because it looks like you are trying to just get a homework solution without regard to why. In most places of learning, this is against an institution's academic honor code. So try to improve the way you're asking questions, and do reply back if you receive a response, especially if you don't understand the response yet. Alan asked you several question in a previous response: https://mail.python.org/pipermail/tutor/2016-July/109405.html He's actually responded to you multiple times, generously giving you his attention. But it seems like you've ignored him altogether. Are there questions there that you do not understand? Good luck to you. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Python Assignment
To whom it may concern, I need someone to help me to develop programs for the following assignments. I have been working on these assignments for a week and a half, and I can't make any progress. I also been dealing with a sick relative, so please help me out immediately. I use the version 3.4.1. Here are the following assignments and what I have so far: Our final exam is a real world problem about efficiency in a warehouse. XYZ Corporation sells products online. The company has a large warehouse in which it stores its inventory of products. Orders are picked, packed and shipped from the warehouse. XYZ Corporation has contracted with you to write a program that will minimize the number of steps that the staff in the warehouse (called ODA's) take in picking the products ordered by customers. The information you will need to complete this assignment are in the following files: [orderNumber, partNumber, quantyNumber, aisleNumber, shelfNumber, binNumber] infile = open("warehouse_data.txt", "r") for x in infile for j in range(3, 6): if (j == 1): temp=a[0:3] a[0:3]=a[3:] a[3:]=temp Thanks, Justin ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python Assignment Expression and Callable Expression
On Fri, Sep 19, 2014 at 02:41:31AM +, Wang Lei (ERIAN) wrote: > Hi, everyone: > > I really believe that python is a great language but assignment and callable > are not flexible: > > I wish that I can do this: > > class matrixArray(list): > bla bla bla > def __call__(self, rid, cid): > return self.head[rid][cid] You can. __call__ is used for making objects a callable, function-like object. C++ calls them "functors". (Not the same thing as what Haskell calls functors!) > Once I call mat(1,1), I can get a result. but I want it more a value not a > reference. You want to change the entire execution model of Python? Why? Like most modern languages, such as Ruby, Java (mostly), and Javascript, Python values are references, not unboxed low-level primitive values. > Considering "mat(1,1) = 5" expression, I wish the parser can > dynamically map "mat(1,1)" to reference of value of that "or anonymous > reference" or reference defined in class. I'm afraid I don't understand what you are trying to say, but if you want to assign to individual items in a matrix, use indexing, not function call: mat[1, 1] = 5 will work perfectly once you add a __setitem__ method to your matrix class. > I don't want to modify the > lexical parsing in C++ but failed after trying different method in > pythonic ways: What does C++ have to do with this? > decorator: fun -> object mapping, because it just substitute function > name with new function and cannot read "self" object. > > I wish python developers could think of an idea to update the lexical > parsing method or simply provide us a tool to modify it in python > context. I think that their answer will be: "We will not complicate the language, making our job enormously harder, and Python much harder to learn and use, just because a beginner to Python who doesn't understand what the language can do or how to use it, wants to program in C++ instead of Python. If you want to program in C++, use C++. If you want to program in Python, learn Python." What do you expect to do with: mat(1, 1) = 5 that cannot be done with this instead? mat[1, 1] = 5 -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python Assignment Expression and Callable Expression
> I wish python developers could think of an idea to update the lexical > parsing method or simply provide us a tool to modify it in python context. Hi Lei, This is unfortunately out of scope for Python-tutor. We don't have direct influence over the future direction of the language. If you want to contact the developers and the larger community, you may want to check the official general-purpose mailing list: https://mail.python.org/mailman/listinfo/python-list (Be aware that python-list is high-traffic.) ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python Assignment Expression and Callable Expression
On 19Sep2014 02:41, Wang Lei (ERIAN) wrote: I really believe that python is a great language but assignment and callable are not flexible: Some flexibilities are too much. But there are ways to do what you ask... I wish that I can do this: class matrixArray(list): bla bla bla def __call__(self, rid, cid): return self.head[rid][cid] Once I call mat(1,1), I can get a result. but I want it more a value not a reference. You're going to need to be less vague. If the result is, for example, an int, in what fashion is it a value instead of an int as far as you are concerned? Please describe this issue more fully. Considering "mat(1,1) = 5" expression, I wish the parser can dynamically map "mat(1,1)" to reference of value of that "or anonymous reference" or reference defined in class. I don't want to modify the lexical parsing in C++ but failed after trying different method in pythonic ways: Define the __setitem__ method on your matrixArray class. Then you can write: mat[1,1] = 5 which is arguably more natural anyway. Assignment and calling are two very different things, and in python they are written differently. That is a good thing. decorator: fun -> object mapping, because it just substitute function name with new function and cannot read "self" object. I must be missing your point here, too. It does just substitute a new function, but that new function can (and generally must) access "self" to do its work. I think you are forgetting that the @decorator action occurs at the time the class is defined, not at the time the function is called. Cheers, Cameron Simpson More computing sins have been committed in the name of performance, without necessariliy achieving it, than for all other reasons combined. - Wulf ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Python Assignment Expression and Callable Expression
Hi, everyone: I really believe that python is a great language but assignment and callable are not flexible: I wish that I can do this: class matrixArray(list): bla bla bla def __call__(self, rid, cid): return self.head[rid][cid] Once I call mat(1,1), I can get a result. but I want it more a value not a reference. Considering "mat(1,1) = 5" expression, I wish the parser can dynamically map "mat(1,1)" to reference of value of that "or anonymous reference" or reference defined in class. I don't want to modify the lexical parsing in C++ but failed after trying different method in pythonic ways: decorator: fun -> object mapping, because it just substitute function name with new function and cannot read "self" object. I wish python developers could think of an idea to update the lexical parsing method or simply provide us a tool to modify it in python context. Regards, Lei Wang CONFIDENTIALITY:This email is intended solely for the person(s) named and may be confidential and/or privileged.If you are not the intended recipient,please delete it,notify us and do not copy,use,or disclose its contents. Towards a sustainable earth:Print only when necessary.Thank you. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python Assignment Question
On 09/24/2012 04:56 PM, Aija Thompson wrote: > > Hi, By top-posting, you lose all the context. The convention is to quote those parts of the previous messages necessary to understand the context, and then add your own remarks immediately after the appropriate parts. > Yeah this is my first assignment and I've never worked on anything > programming before. > I am working in Python 2.7 > The shorter and longer months thing is just a not to myself, that is why it > has the hash tag before he sentence. > But my initial plan was to make a string of months Fine. Have you played with it? Try something like this to get an idea what you have: months = 'January, February, March, April, May, June, July, August, September, October, November, December' for amonth in months: print amonth See what's wrong? Can you imagine what the difference might be if it were a list of strings? Once you get that, try the same kind of experimenting with the other anomalies I pointed out. I expect you haven't gotten a feeling for what all the various native types are good for, list, string, int, float. Are you also familiar with what int() does to a string? What def functions are? I'm sorry if i seem harsh, but this seems like a tough first assignment. You have to use a dozen concepts you apparently haven't wielded before. Weren't there exercises in the chapters you've been studying? Did you try every one of them? I'm actually somewhat envious of the way people get to try out computer programs today. That wasn't an option when I started. So take advantage of it. Write tiny programs and see whether they work, then figure out why not and fix them. and a string of the number of days in those months and have them compare to each other. So it would go through a loop and if you typed in February it would look through the list of numbers and see that January comes before and has 31 days and would add the number of days in February it has been. For instance 22. And it would add 22 to 31 to come up with how many days it has been this year so far. So I've been trying to make that work some way but I have so far been pretty unsuccesful. Does the way I'm even thinking about making the loop make sense? > Thanks! > -- DaveA ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python Assignment Question
Hi, Yeah this is my first assignment and I've never worked on anything programming before. I am working in Python 2.7 The shorter and longer months thing is just a not to myself, that is why it has the hash tag before he sentence. But my initial plan was to make a string of months and a string of the number of days in those months and have them compare to each other. So it would go through a loop and if you typed in February it would look through the list of numbers and see that January comes before and has 31 days and would add the number of days in February it has been. For instance 22. And it would add 22 to 31 to come up with how many days it has been this year so far. So I've been trying to make that work some way but I have so far been pretty unsuccesful. Does the way I'm even thinking about making the loop make sense? Thanks! > Date: Mon, 24 Sep 2012 16:48:56 -0400 > From: d...@davea.name > To: aijathomp...@hotmail.com > CC: tutor@python.org > Subject: Re: [Tutor] Python Assignment Question > > On 09/24/2012 03:20 PM, Aija Thompson wrote: > > Hi! > > I've been working on this question for a long time and for some reason it's > > just not clicking. > > I'm not sure if my loop for the question is the right one, or if I'm even > > on the right track. > > We're supposed to make a program that counts the number of days into the > > year it is if you input a date. Not including leap years. > > This is what I have so far: > > months = 'January, February, March, April, May, June, July, August, > > September, October, November, December'daysPerMonth = '31, 28, 31, 30, 31, > > 30, 31, 31, 30, 31, 30, 31' #shorterMonths = > > 'February, April, June, September, Novmeber'#longerMonths = 'January, > > March, May, July, August, October, December' > > month = raw_input('Enter the month: ')day = raw_input('Enter the day: ') > > for x in month:whichMonth = months.index(x)monthNumber = > > daysPerMonth[whichMonth]dayYear.append(monthNumber) > > I was hoping to make a loop that would check which month it is and compare > > it to the second list I made with the number of days in that month. I don't > > know if I've made that clear to the program or not. Either way, I feel > > pretty lost at the moment. > > Any help would do! > > Thanks! > > > > Please don't send an html message; this is a text mailing list, and > your text is hopelessly mangled. > > For the benefit of others, I reformatted the code and enclose it here, > with tabs turned into 4 spaces. > > months = 'January, February, March, April, May, June, July, August, > September, October, November, December' > daysPerMonth = '31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31' > #shorterMonths = 'February, April, June, September, Novmeber' > #longerMonths = 'January, March, May, July, August, October, December' > month = raw_input('Enter the month: ') > day = raw_input('Enter the day: ') > for x in month: > print "x = ", x > whichMonth = months.index(x) > monthNumber = daysPerMonth[whichMonth] > dayYear.append(monthNumber) > > is this your first assignment? Have you worked in any other programming > language before learning Python? Are you working with CPython 2.7 ? > > Most of this code makes no sense to me at all. Why isn't months a list > of strings? Why isn't daysPerMonth a list of ints? (I'm assuming that > shorterMonths and longerMonths are vestigial code. If not, the two > spellings for November would surely cause troubles. > > Why do you define day as a string, and not an int? > > And why is the loop looping through the characters in the specified month? > > Have you tried to describe in English how to solve the problem? > > > > -- > > DaveA > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python Assignment Question
On 09/24/2012 03:20 PM, Aija Thompson wrote: > Hi! > I've been working on this question for a long time and for some reason it's > just not clicking. > I'm not sure if my loop for the question is the right one, or if I'm even on > the right track. > We're supposed to make a program that counts the number of days into the year > it is if you input a date. Not including leap years. > This is what I have so far: > months = 'January, February, March, April, May, June, July, August, > September, October, November, December'daysPerMonth = '31, 28, 31, 30, 31, > 30, 31, 31, 30, 31, 30, 31' #shorterMonths = > 'February, April, June, September, Novmeber'#longerMonths = 'January, March, > May, July, August, October, December' > month = raw_input('Enter the month: ')day = raw_input('Enter the day: ') > for x in month:whichMonth = months.index(x)monthNumber = > daysPerMonth[whichMonth]dayYear.append(monthNumber) > I was hoping to make a loop that would check which month it is and compare it > to the second list I made with the number of days in that month. I don't know > if I've made that clear to the program or not. Either way, I feel pretty lost > at the moment. > Any help would do! > Thanks! > Please don't send an html message; this is a text mailing list, and your text is hopelessly mangled. For the benefit of others, I reformatted the code and enclose it here, with tabs turned into 4 spaces. months = 'January, February, March, April, May, June, July, August, September, October, November, December' daysPerMonth = '31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31' #shorterMonths = 'February, April, June, September, Novmeber' #longerMonths = 'January, March, May, July, August, October, December' month = raw_input('Enter the month: ') day = raw_input('Enter the day: ') for x in month: print "x = ", x whichMonth = months.index(x) monthNumber = daysPerMonth[whichMonth] dayYear.append(monthNumber) is this your first assignment? Have you worked in any other programming language before learning Python? Are you working with CPython 2.7 ? Most of this code makes no sense to me at all. Why isn't months a list of strings? Why isn't daysPerMonth a list of ints? (I'm assuming that shorterMonths and longerMonths are vestigial code. If not, the two spellings for November would surely cause troubles. Why do you define day as a string, and not an int? And why is the loop looping through the characters in the specified month? Have you tried to describe in English how to solve the problem? -- DaveA ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python Assignment Question
Aija Thompson wrote: > Hi! > > I've been working on this question for a long time and for some reason it's > just not clicking. > > I'm not sure if my loop for the question is the right one, or if I'm even on > the right track. > > We're supposed to make a program that counts the number of days into the year > it is if you input a date. Not including leap years. > > This is what I have so far: > > months = 'January, February, March, April, May, June, July, August, September, > October, November, December' This is a string of months. That will not be very helpful to you. Looking at your later code this should be a list. months = [ 'January', 'February', ] > daysPerMonth = '31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31' Same problem here, but given your months I would use a dictionary so you can map the month to the days per month. months = { 1 : 31, 2 : 28 } Note the lack of quotes around 31 and 28. That means these are Python numbers and not strings. Numbers will be more useful while calculating. Instead of using the month names, I figured it would be more useful to know the month number. > > #shorterMonths = 'February, April, June, September, Novmeber' > #longerMonths = 'January, March, May, July, August, October, December' > > month = raw_input('Enter the month: ') > day = raw_input('Enter the day: ') > > for x in month: > whichMonth = months.index(x) > monthNumber = daysPerMonth[whichMonth] > dayYear.append(monthNumber) If you iterate through months (unlike the month as written) it would iterate through all months regardless if x is December while the date input is say August. # Untested days = 0 month = int( raw_input( 'month: ' ) ) day_of_month = int( raw_input( 'day: ' ) ) current_month = 1 while current_month < month: # For all months before desired month days += months[ current_month ] # Now add days for current month. days += day_of_month > > I was hoping to make a loop that would check which month it is and compare it > to the second list I made with the number of days in that month. I don't know > if I've made that clear to the program or not. Either way, I feel pretty lost > at the moment. Although the above should work, it is not very flexible. I would probably look at the date class in the datetime module. You can use the date class to compare dates and increment the days. This has the advantage of taking into account things like leap years and paves the way for calculating days between ranges (which I suspect will be an upcoming assignment if you are a student). Of course, this is computationally inefficient but it should be "fast enough" and work. The pseudo-code is written below. while current_date < desired_date days +=1 current_date += 1 # look at the datetime.timedelta class to do this > > Any help would do! > > Thanks! This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python Assignment Question
On Mon, Sep 24, 2012 at 4:24 PM, Dwight Hutto wrote: > On Mon, Sep 24, 2012 at 3:20 PM, Aija Thompson > wrote: >> Hi! >> >> I've been working on this question for a long time and for some reason it's >> just not clicking. > > Algorithm is the appropriate approach. That's what makes it click. > >> >> I'm not sure if my loop for the question is the right one, or if I'm even on >> the right track. >> >> We're supposed to make a program that counts the number of days into the >> year it is if you input a date. Not including leap years. > > We'll leave leap years alone for now then, but there are special years > for that input which could be used as a count variable. > >> >> This is what I have so far: >> >> months = 'January, February, March, April, May, June, July, August, >> September, October, November, December' >> daysPerMonth = '31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31' >> >> #shorterMonths = 'February, April, June, September, Novmeber' >> #longerMonths = 'January, March, May, July, August, October, December' > > I'd suggest using a dictionary with the month as the > identifier(month_dict = {'january' : 31, 'february': [28,29]}, and an > integer as the value for each static count of months. > >> >> month = raw_input('Enter the month: ') >> day = raw_input('Enter the day: ') >> >> for x in month: >> whichMonth = months.index(x) >> monthNumber = daysPerMonth[whichMonth] >> dayYear.append(monthNumber) >> >> I was hoping to make a loop that would check which month it is and compare >> it to the second list I made with the number of days in that month. I don't >> know if I've made that clear to the program or not. Either way, I feel >> pretty lost at the moment. >> >> Any help would do! >> >> Thanks! >> > > But in the end, you just want to count days. > So you could iterate through the dictionary's values_of days in each > month, up until the month and the date matches(loop stops), while > using a day_count += 1 in the loop. > Or just count each month's days in the loop, and then when you hit the month, add the days to the adding of the previous months, which just would increment based on the dictionary's value, instead of a 1 count loop, you get an addition of the months prior to the date, plus how many days into the current month you want to find how many days into the year you are. For leap year just use a standard year, and if that year jn the input, or every 4 years past that, add in 1 day. > Just check for the value of the month, and the number of the day to > stop the loop count. > > -- > Best Regards, > David Hutto > CEO: http://www.hitwebdevelopment.com ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python Assignment Question
On Mon, Sep 24, 2012 at 3:20 PM, Aija Thompson wrote: > Hi! > > I've been working on this question for a long time and for some reason it's > just not clicking. Algorithm is the appropriate approach. That's what makes it click. > > I'm not sure if my loop for the question is the right one, or if I'm even on > the right track. > > We're supposed to make a program that counts the number of days into the > year it is if you input a date. Not including leap years. We'll leave leap years alone for now then, but there are special years for that input which could be used as a count variable. > > This is what I have so far: > > months = 'January, February, March, April, May, June, July, August, > September, October, November, December' > daysPerMonth = '31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31' > > #shorterMonths = 'February, April, June, September, Novmeber' > #longerMonths = 'January, March, May, July, August, October, December' I'd suggest using a dictionary with the month as the identifier(month_dict = {'january' : 31, 'february': [28,29]}, and an integer as the value for each static count of months. > > month = raw_input('Enter the month: ') > day = raw_input('Enter the day: ') > > for x in month: > whichMonth = months.index(x) > monthNumber = daysPerMonth[whichMonth] > dayYear.append(monthNumber) > > I was hoping to make a loop that would check which month it is and compare > it to the second list I made with the number of days in that month. I don't > know if I've made that clear to the program or not. Either way, I feel > pretty lost at the moment. > > Any help would do! > > Thanks! > But in the end, you just want to count days. So you could iterate through the dictionary's values_of days in each month, up until the month and the date matches(loop stops), while using a day_count += 1 in the loop. Just check for the value of the month, and the number of the day to stop the loop count. -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python Assignment Question
On 24/09/2012 20:20, Aija Thompson wrote: Hi! I've been working on this question for a long time and for some reason it's just not clicking. I'm not sure if my loop for the question is the right one, or if I'm even on the right track. We're supposed to make a program that counts the number of days into the year it is if you input a date. Not including leap years. This is what I have so far: months = 'January, February, March, April, May, June, July, August, September, October, November, December'daysPerMonth = '31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31' #shorterMonths = 'February, April, June, September, Novmeber'#longerMonths = 'January, March, May, July, August, October, December' month = raw_input('Enter the month: ')day = raw_input('Enter the day: ') for x in month:whichMonth = months.index(x)monthNumber = daysPerMonth[whichMonth]dayYear.append(monthNumber) I was hoping to make a loop that would check which month it is and compare it to the second list I made with the number of days in that month. I don't know if I've made that clear to the program or not. Either way, I feel pretty lost at the moment. Any help would do! Thanks! Your code is basically unreadable in Thunderbird but as I pinched another of your threads I've had a go at untangling it. What you're doing is getting an index into a string. You want to get an index into a list. You can also simplfy the whole structure so search the web for "python two dimensional lists", without the quotes of course. HTH. -- Cheers. Mark Lawrence. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Python Assignment Question
Hi! I've been working on this question for a long time and for some reason it's just not clicking. I'm not sure if my loop for the question is the right one, or if I'm even on the right track. We're supposed to make a program that counts the number of days into the year it is if you input a date. Not including leap years. This is what I have so far: months = 'January, February, March, April, May, June, July, August, September, October, November, December'daysPerMonth = '31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31' #shorterMonths = 'February, April, June, September, Novmeber'#longerMonths = 'January, March, May, July, August, October, December' month = raw_input('Enter the month: ')day = raw_input('Enter the day: ') for x in month:whichMonth = months.index(x)monthNumber = daysPerMonth[whichMonth]dayYear.append(monthNumber) I was hoping to make a loop that would check which month it is and compare it to the second list I made with the number of days in that month. I don't know if I've made that clear to the program or not. Either way, I feel pretty lost at the moment. Any help would do! Thanks! ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python assignment
On Mon, May 9, 2011 at 6:42 PM, Matthew Rezaei wrote: > I have a python assignment and I need help regarding it, is there anyone > that can help me out with it? The answer you will inevitably get is something like: Hi, we're happy to help you understand the problems you're encountering as you work on your assignment. In order to help with that: * Tell us the specific problem you are trying to solve * Show us the code that is giving you a problem (succinct!), including a cut-and-paste of the exact error message you get (if it's an error as opposed to unexpected results) * Give a clear question to answer. If you haven't gotten this from someone else, then consider this that response :) -- Brett Ritter / SwiftOne swift...@swiftone.org ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python assignment
Hello Matthew, On 9 May 2011 23:42, Matthew Rezaei wrote: > Hi There, > > > > I am hoping you can help me! > > > > I have a python assignment and I need help regarding it, is there anyone > that can help me out with it? > Yes. We won't do the assignment for you, but if you try to solve it and get stuck then we'll try to provide hints to get you unstuck. Remember to include full error messages and actual source code if you get stuck. Don't paraphrase code, don't shorten error messages. Don't make assumptions about what is wrong and then send us input based on those assumptions. Do send as much information as possible. Remember to "Reply-all" to ensure responses do go to the list as well. Walter ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Python assignment
Hi There, I am hoping you can help me! I have a python assignment and I need help regarding it, is there anyone that can help me out with it? Regards Matt ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor