REVscene - Vancouver Automotive Forum


Welcome to the REVscene Automotive Forum forums.

Registration is Free!You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! The banners on the left side and below do not show for registered users!

If you have any problems with the registration process or your account login, please contact contact us.


Go Back   REVscene Automotive Forum > Automotive Chat > Vancouver Off-Topic / Current Events

Vancouver Off-Topic / Current Events The off-topic forum for Vancouver, funnies, non-auto centered discussions, WORK SAFE. While the rules are more relaxed here, there are still rules. Please refer to sticky thread in this forum.

Reply
 
Thread Tools
Old 03-10-2009, 08:50 PM   #1
2010 RS Top Food Critic Winner
 
K-Dub's Avatar
 
Join Date: Jul 2006
Location: Vancouver
Posts: 5,410
Thanked 694 Times in 233 Posts
Failed 102 Times in 16 Posts
Help with Python please?

Ask the user to enter three names. Print the names in alphabetical order.

This is what I got so far.. sort of. Not working though. :/

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

if name1 < name2:
....if name1 < name3:
........print name1
....elif name3 < name2:
........print name3
elif name2 < name3:
....print name2
....if name2 < name1:
.......print name2
else:
....print name3


Ask the user to enter a percentage, between 0 and 100. Tell them what letter grade this corresponds to, with an A between 100 and 85, a B between 84 and 70, a C between 69 and 60, a D between 59 and 50 and an F below 50.

This one I'm having more trouble understanding/charting out.

percentage = raw_input ("Enter a percent between 0-100:")
if percentage <50:
....print ""+ percentage +"% is equal to an F"
........if percentage >=50:
............print ""+ percentage +"% is equal to a D"
........elif percentage >=60:
............print ""+ percentage +"% is equal to a C"
........elif percentage >=70:
............print ""+ percentage +"% is equal to a B"
else:
....print ""+ percentage +"% is equal to a A"
Advertisement
K-Dub is offline   Reply With Quote
Old 03-10-2009, 08:51 PM   #2
14 dolla balla aint got nothing on me!
 
Join Date: Jun 2007
Location: vancouver
Posts: 664
Thanked 6 Times in 3 Posts
Failed 4 Times in 3 Posts
put it in an array and order it for the first one (that way you can have infinite number of names). OR beginner way (wayyyyyy more code)

if name1 > name2:
if name1 > name3:
print name1
if name2 > name3:
print name2 + "\n" + name3;
else
print name3 + "\n" + name2;
else
print name3 + "\n" + name1 + "\n" + name2

..... then elif to see if the scenario is that another one is bigger

As for the second one you can use "case" or if you want to do it the long way "ifs" do work. just do it this way

percentage = raw_input ("Enter a percent between 0-100:")
if percentage >= 80:
print percentage +"% is equal to an A"
elif percentage >= 70:
print percentage +"% is equal to a B"
elif percentage >=60:
print percentage +"% is equal to a C"
elif percentage >=50:
print percentage +"% is equal to a D"
else:
print percentage +"% is equal to a F"

Last edited by MegaMx; 03-11-2009 at 02:12 PM.
MegaMx is offline   Reply With Quote
This post thanked by:
Old 03-10-2009, 09:35 PM   #3
Rs has made me the woman i am today!
 
k20a's Avatar
 
Join Date: Feb 2006
Location: Vancouver
Posts: 4,054
Thanked 62 Times in 23 Posts
Failed 3 Times in 2 Posts
Fuck this is like rocket science. What are you guys talking about? Is it about girls? I want in too.
k20a is offline   Reply With Quote
Old 03-10-2009, 09:50 PM   #4
14 dolla balla aint got nothing on me!
 
Join Date: Nov 2008
Location: Hong Kong
Posts: 613
Thanked 38 Times in 25 Posts
Failed 3 Times in 3 Posts
CMPT 120? I HATE THAT FUCKING CLASS
bbbj is offline   Reply With Quote
Old 03-10-2009, 09:54 PM   #5
Banned (ABWS)
 
Join Date: Jan 2007
Location: Vancouver
Posts: 1,201
Thanked 92 Times in 46 Posts
Failed 0 Times in 0 Posts
You need to construct additional Pylons.
pandalove is offline   Reply With Quote
This post thanked by:
Old 03-10-2009, 10:09 PM   #6
Need to Seek Professional Help
 
BoS_DC2's Avatar
 
Join Date: May 2007
Location: Toilet
Posts: 1,081
Thanked 354 Times in 63 Posts
Failed 11 Times in 4 Posts
Quote:
Originally Posted by pandalove View Post
You need to construct additional Pylons.
LOL.

Goliath online.
BoS_DC2 is offline   Reply With Quote
Old 03-10-2009, 10:14 PM   #7
My dinner reheated before my turbo spooled
 
c_loke's Avatar
 
Join Date: Aug 2002
Location: Richmond
Posts: 1,706
Thanked 10 Times in 7 Posts
Failed 0 Times in 0 Posts
Quote:
Originally Posted by k20a View Post
Fuck this is like rocket science. What are you guys talking about? Is it about girls? I want in too.
girls dont exist in computer science.
c_loke is offline   Reply With Quote
Old 03-10-2009, 10:20 PM   #8
14 dolla balla aint got nothing on me!
 
Join Date: Nov 2008
Location: Hong Kong
Posts: 613
Thanked 38 Times in 25 Posts
Failed 3 Times in 3 Posts
Quote:
Originally Posted by c_loke View Post
girls dont exist in computer science.
Does Tifa and Aeris count?
bbbj is offline   Reply With Quote
Old 03-10-2009, 10:55 PM   #9
Raping Captured Dolphins since 2002 on EZ board days
 
RFlush's Avatar
 
Join Date: Jul 2002
Location: Hong Kong
Posts: 6,251
Thanked 658 Times in 191 Posts
Failed 78 Times in 45 Posts
Isn't this CMPT 165? If so, I can give you my assignments
__________________
Quote:
Originally Posted by asian_XL View Post
apparently, freedom of speech does not exist on RS
Quote:
Originally Posted by Alphamale View Post
I give a lot of people rim jobs.
My Feedback
RFlush is offline   Reply With Quote
Old 03-10-2009, 11:00 PM   #10
My dinner reheated before my turbo spooled
 
StaxBundlez's Avatar
 
Join Date: Nov 2006
Location: Vancouver
Posts: 1,720
Thanked 2,116 Times in 382 Posts
Failed 877 Times in 94 Posts
yah i got some pythons to help you right here buddy


BATHROOMS OVER THERE!!
<---------------
__________________
Quote:
If we are not able to ask skeptical questions, to interrogate those who tell us that something is true; to be skeptical of those in authority, then we're up for grabs..
-Carl Sagan
StaxBundlez is offline   Reply With Quote
Old 03-10-2009, 11:09 PM   #11
Need to Seek Professional Help
 
w00tgasm's Avatar
 
Join Date: Jun 2005
Location: Vancouver
Posts: 1,038
Thanked 166 Times in 40 Posts
Failed 21 Times in 7 Posts
Quote:
Originally Posted by K-Dub View Post
Ask the user to enter three names. Print the names in alphabetical order.
Fuck this one haha.
I can't remember what to use for this.

Quote:
Originally Posted by K-Dub View Post
Ask the user to enter a percentage, between 0 and 100. Tell them what letter grade this corresponds to, with an A between 100 and 85, a B between 84 and 70, a C between 69 and 60, a D between 59 and 50 and an F below 50.

This one I'm having more trouble understanding/charting out.
You're going to want to limit the user input between going below 0 or above 100.

To do that you may want to use a while statement
Code:
getgrade = 1;
while getgrade==1:
    percentage = raw_input("Enter your grade between 0-100")
    if (percentage > 100 or percentage < 0):
        getgrade = 1;
    else:
        getgrade = 0;

runcode = 1;
while runcode == 1:
    if percentage < 50:
        print "You got an F for your percentage of " + percentage;
        runcode = 0;
    elif percentage < 59:
        print "You got an D for your percentage of " + percentage;
        runcode = 0;
    elif percentage < 69:
        print "You got a C for your percentage of " + percentage;
        runcode = 0;
    elif percentage < 84:
        print "You got a B for your percentage of " + percentage;
        runcode = 0;
    elif percentage < 100:
        print "You got a A for your percentage of " + percentage;
        runcode = 0;
Because you're working up from 0 you're going to end the code there so it doesn't print F, D, C, etc.

My python may be off, but hope it makes sense to you.
w00tgasm is offline   Reply With Quote
This post thanked by:
Old 03-10-2009, 11:11 PM   #12
Need to Seek Professional Help
 
w00tgasm's Avatar
 
Join Date: Jun 2005
Location: Vancouver
Posts: 1,038
Thanked 166 Times in 40 Posts
Failed 21 Times in 7 Posts
Quote:
Originally Posted by MegaMx View Post
put it in an array and order it for the first one (that way you can have infinite number of names). OR beginner way (wayyyyyy more code)

if name1 > name2:
if name1 > name3:
print name1
if name2 > name3:
print name2 + "\n" + name3;
else
print name3 + "\n" + name2;
else
print name3 + "\n" + name1 + "\n" + name2

..... then elif to see if the scenario is that another one is bigger

As for the second one you can use "case" or if you want to do it the long way "ifs" do work. just do it this way

percentage = raw_input ("Enter a percent between 0-100:")
if percentage >= 80:
print percentage +"% is equal to an A"
if percentage >= 70:
print percentage +"% is equal to a B"
elif percentage >=60:
print percentage +"% is equal to a C"
elif percentage >=50:
print percentage +"% is equal to a D"
else:
print percentage +"% is equal to a F"
If the percentage input is 90, it'll print out the print statements for A B C and D...
w00tgasm is offline   Reply With Quote
Old 03-10-2009, 11:29 PM   #13
2010 RS Top Food Critic Winner
 
K-Dub's Avatar
 
Join Date: Jul 2006
Location: Vancouver
Posts: 5,410
Thanked 694 Times in 233 Posts
Failed 102 Times in 16 Posts
Quote:
Originally Posted by -Paolo- View Post
Fuck this one haha.
I can't remember what to use for this.



You're going to want to limit the user input between going below 0 or above 100.

To do that you may want to use a while statement
Code:
getgrade = 1;
while getgrade==1:
    percentage = raw_input("Enter your grade between 0-100")
    if (percentage > 100 or percentage < 0):
        getgrade = 1;
    else:
        getgrade = 0;

runcode = 1;
while runcode == 1:
    if percentage < 50:
        print "You got an F for your percentage of " + percentage;
        runcode = 0;
    elif percentage < 59:
        print "You got an D for your percentage of " + percentage;
        runcode = 0;
    elif percentage < 69:
        print "You got a C for your percentage of " + percentage;
        runcode = 0;
    elif percentage < 84:
        print "You got a B for your percentage of " + percentage;
        runcode = 0;
    elif percentage < 100:
        print "You got a A for your percentage of " + percentage;
        runcode = 0;
Because you're working up from 0 you're going to end the code there so it doesn't print F, D, C, etc.

My python may be off, but hope it makes sense to you.
Thanks for the help, but I have no idea what the code of line that you put in means
(getgrade / run code line) nor have we covered it in class [CMPT165] haha.

Blaaaaaaaaahhhhhhhhh.
K-Dub is offline   Reply With Quote
Old 03-10-2009, 11:31 PM   #14
Need to Seek Professional Help
 
w00tgasm's Avatar
 
Join Date: Jun 2005
Location: Vancouver
Posts: 1,038
Thanked 166 Times in 40 Posts
Failed 21 Times in 7 Posts
basically it terminates the program after it prints the statement, so it doesn't run through a series of the print statements...

but if you're not comfortable using it, don't.
w00tgasm is offline   Reply With Quote
Old 03-11-2009, 06:41 AM   #15
Rs has made me the man i am today!
 
meepmeepdeath's Avatar
 
Join Date: Oct 2005
Location: BC
Posts: 3,086
Thanked 4 Times in 3 Posts
Failed 0 Times in 0 Posts
all the code you require to finish the assignment is covered in his notes. I would be careful with the way you code your hw or else you might be bitch slapped by the prof, I've seen him ask students to explain their hw when he does not believe the student did the work

i would skip the getgrade = 1 and runcode = 1. you also dont require while loops for this hw

Quote:
Originally Posted by K-Dub View Post
Thanks for the help, but I have no idea what the code of line that you put in means
(getgrade / run code line) nor have we covered it in class [CMPT165] haha.

Blaaaaaaaaahhhhhhhhh.
__________________
buy/sell comments
meepmeepdeath is offline   Reply With Quote
Old 03-11-2009, 07:25 AM   #16
2010 RS Top Food Critic Winner
 
K-Dub's Avatar
 
Join Date: Jul 2006
Location: Vancouver
Posts: 5,410
Thanked 694 Times in 233 Posts
Failed 102 Times in 16 Posts
Quote:
Originally Posted by meepmeepdeath View Post
all the code you require to finish the assignment is covered in his notes. I would be careful with the way you code your hw or else you might be bitch slapped by the prof, I've seen him ask students to explain their hw when he does not believe the student did the work

i would skip the getgrade = 1 and runcode = 1. you also dont require while loops for this hw
I'm not taking it with Baker, but I know. I do want to understand it, just need a little....guidance.

Anyways, figured out the second one. I was missing the int(), if I didn't have it in before it wouldn't do anything else after the first if.

percentage = int(raw_input("Enter a percent between 0-100:"))

if percentage >=85:
print percentage, "% is equal to a A"
elif percentage >=70:
print percentage, "% is equal to a B"
elif percentage >=60:
print percentage, "% is equal to a C"
elif percentage >=50:
print percentage, "% is equal to a D"
else:
print percentage, "% is equal to a F"

Still stuck on the first one. :/
K-Dub is offline   Reply With Quote
Old 03-11-2009, 09:15 AM   #17
Hopeless Romantic
 
jtanner_'s Avatar
 
Join Date: Sep 2006
Location: Surrey
Posts: 2,544
Thanked 989 Times in 232 Posts
Failed 12 Times in 7 Posts
Quote:
Originally Posted by K-Dub View Post
I'm not taking it with Baker, but I know. I do want to understand it, just need a little....guidance.

Anyways, figured out the second one. I was missing the int(), if I didn't have it in before it wouldn't do anything else after the first if.

percentage = int(raw_input("Enter a percent between 0-100:"))

if percentage >=85:
print percentage, "% is equal to a A"
elif percentage >=70:
print percentage, "% is equal to a B"
elif percentage >=60:
print percentage, "% is equal to a C"
elif percentage >=50:
print percentage, "% is equal to a D"
else:
print percentage, "% is equal to a F"

Still stuck on the first one. :/
Hey Colin here, Im watching you.
jtanner_ is offline   Reply With Quote
Old 03-11-2009, 09:29 AM   #18
2010 RS Top Food Critic Winner
 
K-Dub's Avatar
 
Join Date: Jul 2006
Location: Vancouver
Posts: 5,410
Thanked 694 Times in 233 Posts
Failed 102 Times in 16 Posts
Quote:
Originally Posted by bagel.tech View Post
Hey Colin here, Im watching you.
Liessssssssssss!
K-Dub is offline   Reply With Quote
Old 03-11-2009, 09:44 AM   #19
RS controls my life!
 
Orion's Avatar
 
Join Date: Feb 2005
Location: Burnaby
Posts: 731
Thanked 82 Times in 30 Posts
Failed 45 Times in 9 Posts
hahaha i took cmpt 165 way before they implemented python but was forced to learn it in another comp class...
__________________
Quote:
Originally Posted by orion
I know it doesn't make my car faster... its aesthetics
I mean those LV and Gucci also doesn't make you any smarter
Shirlz - Things to do in Vancouver | Web Developer Resource
Orion is offline   Reply With Quote
Old 03-11-2009, 10:01 AM   #20
Hopeless Romantic
 
jtanner_'s Avatar
 
Join Date: Sep 2006
Location: Surrey
Posts: 2,544
Thanked 989 Times in 232 Posts
Failed 12 Times in 7 Posts
Quote:
Originally Posted by K-Dub View Post
Liessssssssssss!
I like your glasses.
jtanner_ is offline   Reply With Quote
Old 03-11-2009, 12:00 PM   #21
Banned (ABWS)?
 
AzNightmare's Avatar
 
Join Date: Oct 2004
Location: Vancouver
Posts: 19,432
Thanked 4,099 Times in 1,760 Posts
Failed 434 Times in 211 Posts
Quote:
Originally Posted by bbbj View Post
Does Tifa and Aeris count?
They do!!!!
__________________
__________________________________________________
Last edited by AzNightmare; Today at 10:09 AM
AzNightmare is offline   Reply With Quote
Old 03-11-2009, 02:11 PM   #22
14 dolla balla aint got nothing on me!
 
Join Date: Jun 2007
Location: vancouver
Posts: 664
Thanked 6 Times in 3 Posts
Failed 4 Times in 3 Posts
Quote:
Originally Posted by -Paolo- View Post
If the percentage input is 90, it'll print out the print statements for A B C and D...
yea i forgot "elif" on the second one. it would just print out one because it stops. a while statement may be necessary if you're giving it to somebody retarded who is going to put something other than 0-100 but otherwise redundant
MegaMx is offline   Reply With Quote
Old 03-11-2009, 02:13 PM   #23
14 dolla balla aint got nothing on me!
 
Join Date: Jun 2007
Location: vancouver
Posts: 664
Thanked 6 Times in 3 Posts
Failed 4 Times in 3 Posts
Quote:
Originally Posted by K-Dub View Post
I'm not taking it with Baker, but I know. I do want to understand it, just need a little....guidance.

Anyways, figured out the second one. I was missing the int(), if I didn't have it in before it wouldn't do anything else after the first if.

percentage = int(raw_input("Enter a percent between 0-100:"))

if percentage >=85:
print percentage, "% is equal to a A"
elif percentage >=70:
print percentage, "% is equal to a B"
elif percentage >=60:
print percentage, "% is equal to a C"
elif percentage >=50:
print percentage, "% is equal to a D"
else:
print percentage, "% is equal to a F"

Still stuck on the first one. :/
What's wrong with that one? (what error are you getting?)
MegaMx is offline   Reply With Quote
Old 03-11-2009, 04:34 PM   #24
I contribute to threads in the offtopic forum
 
SuperSlowSS's Avatar
 
Join Date: Nov 2001
Location: Cayman Islands
Posts: 2,945
Thanked 93 Times in 29 Posts
Failed 12 Times in 5 Posts
you suck at logic. drop it now. lol
__________________
LClock 1.62b
pinkbaby(aka pinkbuggy): (_\._) :p
SuperSlowSS is offline   Reply With Quote
Old 03-11-2009, 05:34 PM   #25
2010 RS Top Food Critic Winner
 
K-Dub's Avatar
 
Join Date: Jul 2006
Location: Vancouver
Posts: 5,410
Thanked 694 Times in 233 Posts
Failed 102 Times in 16 Posts
Quote:
Originally Posted by MegaMx View Post
What's wrong with that one? (what error are you getting?)
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.

Quote:
Originally Posted by SuperSlowSS View Post
you suck at logic. drop it now. lol
Programmers logic I do not have.
K-Dub is offline   Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off



All times are GMT -8. The time now is 02:32 AM.


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