REVscene Automotive Forum

REVscene Automotive Forum (https://www.revscene.net/forums/)
-   Vancouver Off-Topic / Current Events (https://www.revscene.net/forums/vancouver-off-topic-current-events_50/)
-   -   Help with Python please? (https://www.revscene.net/forums/567682-help-python-please.html)

dual 03-11-2009 10:42 PM

Quote:

Originally Posted by SuperSlowSS (Post 6324034)
you suck at logic. drop it now. lol

That's actually good advice. If you can't even get a B in this CMPT 120, it only gets harder from there. Next is CMPT 125, 225, 275. Make sure you have Cukierman as your prof for 125. CMPT 225 and 275 is basically hell. If you do happen to do well in this course, take CMPT 165 and own all the art majors who don't know what python is.

Anyways, looking at your previous post, it looks like your algorithm is wrong in the second half. There should only be 6 'print' statements b/c there are only 6 possible ways to arrange the names (which you have listed out) assuming the names can't be exactly the same as each other. So your algorithm should be

If name1 before name2
..if name2 before name3
....print "name1, name2, name3"
..elif name1 before name3
....print "name1, name3, name2"
..else
....print "name3, name1, name2"
else //at this point, name2 is before name1
..if name3 before name2
....print "name3, name 2, name1"
..elif name3 before name1
....print "name2, name3, name1"
..else
....print "name2, name1, name3"

K-Dub 03-11-2009 10:51 PM

Quote:

Originally Posted by dual (Post 6324832)
That's actually good advice. If you can't even get a B in this CMPT 120, it only gets harder from there. Next is CMPT 125, 225, 275. Make sure you have Cukierman as your prof for 125. CMPT 225 and 275 is basically hell. If you do happen to do well in this course, take CMPT 165 and own all the art majors who don't know what python is.

....this is cmpt165.
im not majoring in cmpt this is just an elective.

c_loke 03-11-2009 11:12 PM

Quote:

Originally Posted by K-Dub (Post 6324123)
I didn't get the one about sorting alphabetically. I drew out a flowchart, etc..things were going good but just one variation of "ABC" would fuck it up.


'''
Question6
'''
name1 = raw_input ("Enter a name:")
name2 = raw_input ("Enter a second name:")
name3 = raw_input ("Enter a third name:")

if name1 < name2:
....if name2 < name3:
........print name1 + "\n" + name2 + "\n" + name3
....elif name1 < name3:
........print name1 + "\n" + name3 + "\n" + name2
....else:
........print name3 + "\n" + name1 + "\n" + name2
elif name1 < name3:
....if name2 < name3:
........print name3 + "\n" + name1 + "\n" + name2
........if name1 < name2:
............print name2 + "\n" + name3 + "\n" + name1
........else:
............print name3 + "\n" + name2 + "\n" + name1
....elif name3 < name2:
........print name2 + "\n" + name3 + "\n" + name1

else:
....print name3 + "\n" + name2 + "\n" + name1

Run these through it
ABC
ACB
BAC
BCA
CAB
CBA

The only one that will fuck it up will be BAC. I can't single out how to get that one to sort properly.

Anyways, fuck it, you know what?
The assignment is worth 1.25%.
Getting 6/7 questions right is enough.



Programmers logic I do not have. :(

I've never done python myself, but the way you can look at sorting alphabetically is by taking the word and tokenizing it. So for example, Duck could be place in an array of size 4, each element holds the letter of the word, then you do that for your other words, and then do a string compare. its super tedious but it works.

Suppose,

a[] = Duck
b[] = Dick

Compare the a[0] to b[0], if they are equal, then compare a[1] b[1]. if b[1]<a[1] then ouput dick, duck.

it gets real nasty when you have 3 words, thats why we use the built in language functions :D

dual 03-11-2009 11:20 PM

Quote:

Originally Posted by K-Dub (Post 6324867)
....this is cmpt165.
im not majoring in cmpt this is just an elective.

Haha I bet one of your CMPT friends told you it was ezpz. Have you tried the algorithm I posted above? It should work assuming you don't have names that are the same.


All times are GMT -8. The time now is 02:48 PM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
SEO by vBSEO ©2011, Crawlability, Inc.
Revscene.net cannot be held accountable for the actions of its members nor does the opinions of the members represent that of Revscene.net