Quantcast

Got Homework?

Connect with other students for help. It's a free community.

  • across
    MIT Grad Student
    Online now
  • laura*
    Helped 1,000 students
    Online now
  • Hero
    College Math Guru
    Online now

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

Aoxx Group Title

While trying to make my code smaller i ran into an issue with increasing the days by a loop counter. Why cant I assign in this way? http://dpaste.com/1398446/ Num_Days = 0 Total = 0 Data = 0 Day1 = 0 Day2 = 0 Day3 = 0 def Start_Work(x): while Num_Days < 3: Num_Days += 1 print "This is Day:",Num_Days n = Num_Days Total = +20 Day(n) += Total else: print "failed" x = str('start')

  • one year ago
  • one year ago

  • This Question is Closed
  1. UseInduction Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    What is your function supposed to do/print?

    • one year ago
  2. Alienium Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    why... ppl use python ?... it's so..... pfff, so not professional as in... not a strongly typed serious language

    • one year ago
  3. rsmith6559 Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    Total = +20 Looks to me like the += is transposed. while Num_Days < 3: Looks like it could have a scope issue. Try putting in "print Num_Days" before the while statement. If the print statement bombs, you should put a "global Num_Days" as the first statement in the function.

    • one year ago
  4. e.mccormick Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    @Alienium Actually, it is strongly typed. It is also dynamically typed. C++ is also dynamically typed and will promote the type of variable as needed. Google, in their training class on Python, talked about why they use it. For many things, Python is a very easy language to use. This saves time for programmers. They can easily buy more CPUs. They can't just buy more good programmers. So they let programmers use the easy languages where appropriate.

    • one year ago
  5. bwCA Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    what exactly are you trying to do? http://bit.ly/19HCL0B line 13 - you can't do that

    • one year ago
  6. Aoxx Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    I am trying to write a program that will allow me to have it ask three questions, then upon the input of those question make a calculation of total out put, then store it and wait for the next days input. I can do this if I make a new block of code for each day but to get 3 weeks out my program would be massive. I am just trying to learn how to write a function that i can plug in to check what day it is and store that info in the area for that day so it can be looked back upon later.

    • one year ago
  7. bwCA Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    you need to refine that a bit - I only have a vague idea of what you want to do. can you break it down into discrete chunks/processes? Sometimes it helps to spend some time thinking about the container your going to put your stuff in - when you figure that out, you'll want to make use of its methods and that will shape your code. what datatype is Day and what is that line trying to do?

    • one year ago
  8. Aoxx Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    I sent you a message as I am having a hard time putting code and links in this box.

    • one year ago
  9. Aoxx Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    think I got it this time http://dpaste.com/1399100/ This is the main program, I want this to have a function in it so i will not need to write each day individually. I would like it to store the input data by the Num_Days counter but I cant figure out how that is supposed to work or what it is called that I am trying to do. This was my attempt but this Function wont complete a loop. http://dpaste.com/1399101/

    • one year ago
  10. bwCA Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    it might be easier to keep track of what you are doing if you write some more functions lets see if i read it right. you get up in the morning and workout then run your program. you want it to: - 'remember' which day in a six (n) day sequence you are in and the results of previous days workouts - ask you what type of workout you did - regardless of the workout type ask three questions - make decisions based on the answers to the questions the type of workout, and the day in the sequence - yell at you if you are slacking making functions for discrete parts of your process helps keep the number of lines in the main code down and helps you see your algorithm better - it really helps if you give the functions descriptive names so that when you read the statement that calls it you know exactly what it is doing. make a function that asks three questions: and use it wherever you ask three questions http://dpaste.com/1399126/ the crunching and benching code blocks look the same - i only see one difference. you could write a single function for this - as i look closer at these blocks, i don't think i understand the ``` - make decisions based on the answers to the questions, the type of workout, and the day in the sequence ``` part the remembering part implies to me that you want to persist your data - one way to do that is to store it in a file at the end of the program and read it from a file at the beginning of the program. there are many ways to do this and your choice of datatype to contain your data might influence how you do it. The most likely candidates would be to pickle your data or write your data to a csv file - these are easy to do and they are in the Python standard library http://docs.python.org/2.7/library/pickle.html http://docs.python.org/2.7/library/csv.html a dictionary might be a good container for your data. one for each workout type - {'Day1' : data, 'Day2' : data, 'Dayn': data, ....} http://docs.python.org/2.7/tutorial/datastructures.html#dictionaries http://docs.python.org/2.7/library/stdtypes.html#mapping-types-dict or maybe a list of tuples [('dayn', data), ...] - this might be better because as you add to the list, it will keep its order - this means you can look at the last item in the list and use it to figure out which day today is. a dictionary is 'orderless'

    • one year ago
  11. Aoxx Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    Yes, what I am running into the problem of is not having to write a new block of code for each day, I would like for it to start the loop and read the Num_Days and set the current loop to store in a Day(x) type where x = Num_Days and Num_Days has just increased by +1 in the step previously (Num_Days += 1). I thought I could make this a defined function and just plug that function into the block of code for each exercise (benching, crunches, squats) but when i tried to do that it tells me it cant. and writing out each day would make the code very large and very difficult to debug if I added something and ran into issues.

    • one year ago
  12. Aoxx Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    And of course thank you for you input

    • one year ago
  13. Aoxx Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    I have gotten a little closer with making the function, but now it seems that after creating the tuple for day1 it creates a whole new tuple for day2 and overrides day1 data with day2's data in both spots in the tuple http://dpaste.com/1399270/

    • one year ago
  14. Aoxx Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    OK, I got this figured out, I needed to use Day.append(Total_Output) instead of the 'n' and 'Day' lines.

    • one year ago
    • Attachments:

See more questions >>>

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.