Two Plus Two Poker Forums

Two Plus Two Poker Forums (https://forumserver.twoplustwo.com/)
-   Computer and Technical Help (https://forumserver.twoplustwo.com/48/computer-technical-help/)
-   -   ** Python Support Thread ** (https://forumserver.twoplustwo.com/48/computer-technical-help/python-support-thread-1007515/)

daveT 06-06-2012 05:49 PM

Re: ** Python Support Thread **
 
If Udacity is 7 or 8 class modules compared to MIT's 24 classes, so yes, the MIT class is probably much more thorough. As for finding answers to 6.000, there are quite a few (poorly done) answers found online.

6.000 has a pretty specific goal of preparing you for 6.001 (Structure and Interpretation of Computer Programs).

The approach is, from what I can remember, pretty CS-heavy and not particularly focused on Python: in fact the professor is pretty vocal about his contempt toward the language. Some quotes I remember:

"I hate this friggin' language."
"Ooops, I thought I was writing Lisp."
"I'm a Lisp hacker, so using this language is..."
"I ~hate~ this (operation overload / whatever feature)."
"This is how Python handles lists, which isn't so bad, but (long mind-blowing dissertation in how Lisp handles lists) which is far better."

Unfortunately, he didn't teach the OO part of the class. I'm sure that would have been wildly entertaining. (OO is pretty controversial in Lisp programming and generally frowned upon)

Sounds like an awful teacher, but he was actually really really good. There were a few classes I had to watch twice to understand it. At the time of taking this course, I didn't have a job, so I finished it in one month, but with a job, it would've taken me 3 to 5 months.

So, with time constraints and stuff, Udacity's shorter format is probably a good option.

As for the problem in question: It's find the 1001st prime. I guess to weigh the speed (and perhaps quality?) of each class, figure out how far you'd have to be in Udacity before they would introduce that question.

splashpot 06-06-2012 06:16 PM

Re: ** Python Support Thread **
 
Putting the actual content aside, Udacity's delivery method is MUCH better. OCW has no interactivity. Udacity prompts the students to answer questions and actually write code. That's more interactivity than most students (the ones who sit in the back and don't raise their hand) get actually attending MIT lectures. Udacity actually feels like the professor is tutoring me personally. I'm a fan.

Jbrochu 06-06-2012 07:02 PM

Re: ** Python Support Thread **
 
Sorry if I misled anybody. I was just seconding an opinion that Udacity is pretty good. I don't know anything about the MIT program.

windwakeroftime 06-06-2012 07:47 PM

Re: ** Python Support Thread **
 
Quote:

Originally Posted by daveT (Post 33143026)
I did this class. You're way over-thinking this part of the problem.

Think about this step: You simply want to print a column of numbers that are odd, right?

1
3
5
7
9
11
...

Think about the unique feature of integers that would make generating that list easy.

You have the following steps:

initialize a variable. What variable would allow you to take advantage of the unique feature alluded to?

generate the list: What would you do to that initial variable that reflects the unique feature alluded to?

See how I wrote down what you wanted to do? That class says using a pencil and paper is an important step in programming and I absolutely agree with that assertion. Writing down the output you want to see will help you see things that you may not have noticed before.

If you really do give up, then use the spoiler tag:

Try to fill in the blanks:

Spoiler:
Code:


x = ?

while x < 100:
    print x
    {{ What are you going to do to X?? }}}




Ohh, yeah, I finally got that. I wrote a code to write down the odd numbers and now I am trying to figure out how to determine if the odd number is prime or not.

I can do it on paper, and I know I probably have to use the a%b, but it just doesn't seem to be coming out. I'll keep working at it D:<!

windwakeroftime 06-06-2012 07:54 PM

Re: ** Python Support Thread **
 
So I had this to find the odd number,
Quote:

odd_number=-1
while odd_number<10:
odd_number +=2
print (odd_number)

and then i tried this to find the prime number
Quote:

odd_number=-1


while odd_number<10:

odd_number+=2

value=2

while value<10:
value+=1

if odd_number%value!=0:
print odd_number
but it gives me an output of eleven. Which baffles me because I put that odd_number<10 and value<10

Xhad 06-06-2012 08:13 PM

Re: ** Python Support Thread **
 
Use <code> tags so we can see your indentation

daveT 06-06-2012 08:17 PM

Re: ** Python Support Thread **
 
You need to use code tags to format the code you are asking about. I'm not really sure if you are nesting loops or if you are writing consecutive loops. With that said:

Yes, the output should be 11 because the code did exactly what you told it to do. Did you get to the part where he is at the chalk board and charting out the looping function i/o? Do the same on a pencil and paper.

windwakeroftime 06-06-2012 08:34 PM

Re: ** Python Support Thread **
 
Code:

odd_number=-1

for x in range(1,11):
        odd_number+=2
        print odd_number

This is what i have so far. (i changed it a little) So, I'm still a little confused on the concept of loops. If I put in the range (1,11), what exactly is it computing?

Thanks for all of the help guys :D! I really appreciate it!

Jbrochu 06-06-2012 08:46 PM

Re: ** Python Support Thread **
 
Try printing the value of x inside the loop so you can see for yourself what it's doing.

daveT 06-06-2012 11:10 PM

Re: ** Python Support Thread **
 
Quote:

Originally Posted by windwakeroftime (Post 33154185)

So, I'm still a little confused on the concept of loops. If I put in the range (1,11), what exactly is it computing?

This the reason why the class introduces loops with "while" and not "for"

Does the while loop feel stupid right now? Sure, since all you're trying to do is count some numbers, but soon you will have zero options but to use the while loop and unless you can learn to generate a basic counter with it, you're not going to be able to understand why other stuff is breaking.

If you're going to make it through this class, you must learn to do two things:

1- Pencil and Paper. I know, sounds primitive, so if you prefer: "back of the envelope computations."

2- Create toy programs. Trying to create a fully functioning program, as you are now hopefully discovering, isn't at all possible until you understand the components of each piece you are writing. To gain insight, you must create toy programs.

Copy / paste these into your IDLE, then type each one (these won't work due to indent errors) and see what they output, and try to understand why they work. Once you ~think~ you understand the codes, try creating your own toy codes and see if the output you expected to see is what you get. If not, try to find out why:

Code:

x = 1


while x < 9:
    print x
    x += 2

 
while x <= 9:
    print x
    x += 2


 while x < 9:
    x += 2
    print x
 
 while x <= 9:
    x += 2
    print x

 while x < 9:
    x += 2
print x

You absolutely positively must get this understood. Programming in just about all of its essence is flow control and loops, and not being able to conquer the while loop is inexcusable.

If at this point of the class, you have not been introduced to for loop, then you should probably try to do this hw in while loops only. I think it's worth the effort.

Xhad 06-06-2012 11:16 PM

Re: ** Python Support Thread **
 
Quote:

Originally Posted by daveT (Post 33156599)
If at this point of the class, you have not been introduced to for loop, then you should probably try to do this hw in while loops only. I think it's worth the effort.

This is good advice imo. But if you want a hint as to what the for loop is doing, try:

Code:

print range(1,11)

unluckyboy 06-09-2012 11:47 PM

Re: ** Python Support Thread **
 
i am using python and sqlite3 to make a database and analyze the information. can i get some tips on database design please? the data is there are 21 turtles and there are measurements taken on their shell length, width, and weight, and these measurements were all taken 5 different times one week apart. how do i structure this data?

Neko 06-09-2012 11:58 PM

Re: ** Python Support Thread **
 
Would probably just do a couple tables like:

Code:

Table Turtles:
ID, Name, Age, Sex, Location

Table Measurements:
MeasureID, TurtleID, MeasuredDateTime, Length, Width, Weight


Jbrochu 06-10-2012 12:00 AM

Re: ** Python Support Thread **
 
Sounds like all you need is one table with these fields:

TurtleID, MeasurementDate, Length, Width, Weight

Edit: Neko is correct. Add the second table for the turtle info.

unluckyboy 06-10-2012 12:04 AM

Re: ** Python Support Thread **
 
lol thanks for some reason i was thinking need a new table for each measurement date. it seems like database work could get complex though if you have a lot of data

unluckyboy 06-10-2012 12:06 AM

Re: ** Python Support Thread **
 
well as long as im here, here is another question. so i have this table in sqlite with a column of data type REAL, yet when i run a SELECT command and get the data and do c.fetchall() or c.fetchone() it returns me the correct number but as data type "none type" so i cant manipulate the number. how do i get the data as a REAL

Neko 06-10-2012 12:08 AM

Re: ** Python Support Thread **
 
It's more likely returning it as a string then untyped. You should be able to change to a float/real by doing:

Code:

x = "123.4"
x = float(x)


unluckyboy 06-10-2012 12:15 AM

Re: ** Python Support Thread **
 
oh i see it is returning it as a list so i just have to get first element of list. sorry kind of dumb question i am just burning out now and i'm a newbie programmer

unluckyboy 06-10-2012 10:57 PM

Re: ** Python Support Thread **
 
do you guys use gspread or gdata library?

unluckyboy 06-10-2012 11:12 PM

Re: ** Python Support Thread **
 
kind of annoying if i do gspread.range it returns numbers turned into text strings with the cell number in text.

found this it helps, sales_data = [float(c.value) for c in worksheet.range('E1:E17')]

windwakeroftime 06-11-2012 10:32 PM

Re: ** Python Support Thread **
 
Code:

q=1
while q == 1:

    x=int(raw_input('what is yo numba'))
    counter=0
    for pn in range (2,x+1):
        if x%pn==0:
                counter=counter+1
    if counter==1:
        print x, 'is a prime numba.'
    else:
        print x, 'is not a prime numba. srry betch yo numba aint prime'

I've got how to determine whether a number is prime or not, but now I'm trying to figure out how to find out what "number" prime number it is.

So 2 is the first prime number
3 is the second
etc.

HALP.

windwakeroftime 06-11-2012 10:36 PM

Re: ** Python Support Thread **
 
Excuse my french. Just having a little fun with the program.

daveT 06-11-2012 10:54 PM

Re: ** Python Support Thread **
 
It doesn't seem to work:

Code:

>>>
what is yo numba3.4
Traceback (most recent call last):
  File "C:/Documents and Settings/d/Desktop/prim.py", line 4, in <module>
    x=int(input('what is yo numba'))
ValueError: invalid literal for int() with base 10: '3.4'
>>>

Two questions:

1- Do really need to divide by every single number up to the candidate?

2- Do you know how to find the 1001st prime yet? If not, then try that first, then do this one.

unluckyboy 06-14-2012 12:42 PM

Re: ** Python Support Thread **
 
what do you use for parsing HTMl with python? beautiful soup, elementtree, just regex?

TheIrishThug 06-14-2012 02:01 PM

Re: ** Python Support Thread **
 
I've never used beautiful soup or elementtree, but the answer is not regex.


All times are GMT -4. The time now is 07:41 AM.

Powered by vBulletin®
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.

Copyright © 2008-2020, Two Plus Two Interactive