![]() |
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" |
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" |
Fuck this is like rocket science. What are you guys talking about? Is it about girls? I want in too. |
CMPT 120? I HATE THAT FUCKING CLASS |
You need to construct additional Pylons. |
Quote:
Goliath online. |
Quote:
|
Quote:
|
Isn't this CMPT 165? If so, I can give you my assignments |
yah i got some pythons to help you right here buddy http://www.criticalbench.com/images/bigarm.jpg BATHROOMS OVER THERE!! <--------------- |
Quote:
I can't remember what to use for this. Quote:
To do that you may want to use a while statement Code:
My python may be off, but hope it makes sense to you. |
Quote:
|
Quote:
(getgrade / run code line) nor have we covered it in class [CMPT165] haha. Blaaaaaaaaahhhhhhhhh. |
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. |
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:
|
Quote:
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. :/ |
Quote:
|
Quote:
|
hahaha i took cmpt 165 way before they implemented python but was forced to learn it in another comp class... |
Quote:
|
Quote:
|
Quote:
|
Quote:
|
you suck at logic. drop it now. lol |
Quote:
''' 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:
|
All times are GMT -8. The time now is 12:08 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