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)

K-Dub 03-10-2009 08:50 PM

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"

MegaMx 03-10-2009 08:51 PM

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"

k20a 03-10-2009 09:35 PM

Fuck this is like rocket science. What are you guys talking about? Is it about girls? I want in too.

bbbj 03-10-2009 09:50 PM

CMPT 120? I HATE THAT FUCKING CLASS

pandalove 03-10-2009 09:54 PM

You need to construct additional Pylons.

BoS_DC2 03-10-2009 10:09 PM

Quote:

Originally Posted by pandalove (Post 6323037)
You need to construct additional Pylons.

LOL. :haha:

Goliath online.

c_loke 03-10-2009 10:14 PM

Quote:

Originally Posted by k20a (Post 6322996)
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.

bbbj 03-10-2009 10:20 PM

Quote:

Originally Posted by c_loke (Post 6323098)
girls dont exist in computer science.

Does Tifa and Aeris count?

RFlush 03-10-2009 10:55 PM

Isn't this CMPT 165? If so, I can give you my assignments

StaxBundlez 03-10-2009 11:00 PM

yah i got some pythons to help you right here buddy
http://www.criticalbench.com/images/bigarm.jpg

BATHROOMS OVER THERE!!
<---------------

w00tgasm 03-10-2009 11:09 PM

Quote:

Originally Posted by K-Dub (Post 6322896)
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 (Post 6322896)
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 03-10-2009 11:11 PM

Quote:

Originally Posted by MegaMx (Post 6322898)
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...

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

Quote:

Originally Posted by -Paolo- (Post 6323213)
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.

w00tgasm 03-10-2009 11:31 PM

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.

meepmeepdeath 03-11-2009 06:41 AM

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 (Post 6323249)
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 03-11-2009 07:25 AM

Quote:

Originally Posted by meepmeepdeath (Post 6323287)
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. :/

jtanner_ 03-11-2009 09:15 AM

Quote:

Originally Posted by K-Dub (Post 6323328)
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.

K-Dub 03-11-2009 09:29 AM

Quote:

Originally Posted by bagel.tech (Post 6323410)
Hey Colin here, Im watching you.

Liessssssssssss!

Orion 03-11-2009 09:44 AM

hahaha i took cmpt 165 way before they implemented python but was forced to learn it in another comp class...

jtanner_ 03-11-2009 10:01 AM

Quote:

Originally Posted by K-Dub (Post 6323435)
Liessssssssssss!

I like your glasses. :thumbsup:

AzNightmare 03-11-2009 12:00 PM

Quote:

Originally Posted by bbbj (Post 6323111)
Does Tifa and Aeris count?

They do!!!!

MegaMx 03-11-2009 02:11 PM

Quote:

Originally Posted by -Paolo- (Post 6323218)
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 03-11-2009 02:13 PM

Quote:

Originally Posted by K-Dub (Post 6323328)
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?)

SuperSlowSS 03-11-2009 04:34 PM

you suck at logic. drop it now. lol

K-Dub 03-11-2009 05:34 PM

Quote:

Originally Posted by MegaMx (Post 6323811)
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 (Post 6324034)
you suck at logic. drop it now. lol

Programmers logic I do not have. :(


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