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. |  | |
03-10-2009, 08:50 PM
|
#1 | 2010 RS Top Food Critic Winner
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"
|
| |
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.
|
| |
03-10-2009, 09:35 PM
|
#3 | Rs has made me the woman i am today!
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.
|
| |
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
|
| |
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.
|
| |
03-10-2009, 10:09 PM
|
#6 | Need to Seek Professional Help
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 You need to construct additional Pylons. | LOL.
Goliath online.
|
| |
03-10-2009, 10:14 PM
|
#7 | My dinner reheated before my turbo spooled
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 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.
|
| |
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 girls dont exist in computer science. | Does Tifa and Aeris count?
|
| |
03-10-2009, 10:55 PM
|
#9 | Raping Captured Dolphins since 2002 on EZ board days
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 apparently, freedom of speech does not exist on RS | Quote:
Originally Posted by Alphamale I give a lot of people rim jobs. | My Feedback |
| |
03-10-2009, 11:00 PM
|
#10 | My dinner reheated before my turbo spooled
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
| |
| |
03-10-2009, 11:09 PM
|
#11 | Need to Seek Professional Help
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 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 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.
|
| |
03-10-2009, 11:11 PM
|
#12 | Need to Seek Professional Help
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 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...
|
| |
03-10-2009, 11:29 PM
|
#13 | 2010 RS Top Food Critic Winner
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- 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.
|
| |
03-10-2009, 11:31 PM
|
#14 | Need to Seek Professional Help
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.
|
| |
03-11-2009, 06:41 AM
|
#15 | Rs has made me the man i am today!
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 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. | |
| |
03-11-2009, 07:25 AM
|
#16 | 2010 RS Top Food Critic Winner
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 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. :/
|
| |
03-11-2009, 09:15 AM
|
#17 | Hopeless Romantic
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 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.
|
| |
03-11-2009, 09:29 AM
|
#18 | 2010 RS Top Food Critic Winner
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 Hey Colin here, Im watching you. | Liessssssssssss!
|
| |
03-11-2009, 09:44 AM
|
#19 | RS controls my life!
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...
|
| |
03-11-2009, 10:01 AM
|
#20 | Hopeless Romantic
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 Liessssssssssss! | I like your glasses. |
| |
03-11-2009, 12:00 PM
|
#21 | Banned (ABWS)?
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 Does Tifa and Aeris count? | They do!!!!
|
| |
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- 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
|
| |
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 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?)
|
| |
03-11-2009, 04:34 PM
|
#24 | I contribute to threads in the offtopic forum
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 |
| |
03-11-2009, 05:34 PM
|
#25 | 2010 RS Top Food Critic Winner
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 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 you suck at logic. drop it now. lol | Programmers logic I do not have. |
| |  | |
Posting Rules
| You may not post new threads You may not post replies You may not post attachments You may not edit your posts HTML code is Off | | | All times are GMT -8. The time now is 02:32 AM. |