Follow us on Twitter!
Your life is ending one minute at a time. If you were to die tomorrow, what would you do today?
Thursday, April 24, 2014
Navigation
Home
HellBoundHackers Main:
HellBoundHackers Find:
HellBoundHackers Information:
Learn
Communicate
Submit
Shop
Challenges
HellBoundHackers Exploit:
HellBoundHackers Programming:
HellBoundHackers Think:
HellBoundHackers Track:
HellBoundHackers Patch:
HellBoundHackers Other:
HellBoundHackers Need Help?
Other
Members Online
Total Online: 25
Guests Online: 21
Members Online: 4

Registered Members: 82897
Newest Member: salim
Latest Articles
View Thread

HellBound Hackers | Computer General | Programming

Author

practice pyhton problem


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 15-08-06 05:48
Ok, I just started into python today. I was looking at a bunch of examples and tried a few. Then i decided to make somehting worthless just to combine some stuff. I am trying to work out using else and elif to be used together. here is what I have....

Code
print "Money Maker!"
string1 = raw_input("What is your name? ")
integer1 = input("How much do you make a year? ")
string2 = raw_input ("What is your friend's name? ")
integer2 = input("How much does your friend make a year? ")
print string1, "makes", integer1, "yearly while ", string2, "makes ", integer2, "yearly ",
integer3 = integer2 - integer1
integer4 = integer1 - integer2
if integer1 < integer2:
        print string2, "makes more money than", string1, "by", integer3, "dollars",
else:
        print string1, "makes more money than", string2, "by", integer4, "dollars",
 elif integer1 == integer2
        print string1, "and", string2, "both make", integer1,





any help will be appreciated! I am here to learn


Author

RE: practice pyhton problem


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 25-08-06 02:10
anyone able to help me?


Author

RE: practice pyhton problem

richohealey
Member



Posts: 1022
Location: #!/usr/local/bin/python
Joined: 01.05.06
Rank:
Monster
Posted on 25-08-06 02:17
in an if:
elif:
else:

sequence, else must be the last.

ie you have if as your first condition, then elif (else, if) as all the middle one, and then else, which is run if no prior conditions have been met.


bitchohealey at hotmail dot com skype:richohealey www.psych0tik.net
Author

RE: practice pyhton problem


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 03-09-06 05:27
ok, now this is what the code looks like....

Code
print "Money Maker!"
string1 = raw_input("What is your name? " )
integer1 = input("How much do you make a year? " )
string2 = raw_input ("What is your friend's name? " )
integer2 = input("How much does your friend make a year? " )
print string1, "makes", integer1, "yearly while ", string2, "makes ", integer2, "yearly ",
integer3 = integer2 - integer1
integer4 = integer1 - integer2
if integer1 < integer2:
   print string2, "makes more money than", string1, "by", integer3, "dollars",

elif integer1 > integer2:
   print string1, "makes more money than", string2, "by", integer4, "dollars",

else:
  print string1, "and", string2, "both make", integer1, “dollars”,





now when i run it I get a syntax error at the if and I dunno why.


Author

RE: practice pyhton problem


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 03-09-06 07:21
try indenting?

Code
if statement:
<tab here>do whatever




I know a little python and you have to indent wtih if statements

Edit: nvm, here:

Code
print "Money Maker!"
string1 = raw_input("What is your name? " )
integer1 = input("How much do you make a year? " )
string2 = raw_input ("What is your friend's name? " )
integer2 = input("How much does your friend make a year? " )
print string1, "makes", integer1, "yearly while ", string2, "makes ", integer2, "yearly ",
integer3 = integer2 - integer1
integer4 = integer1 - integer2
if integer1 < integer2:
   print string2, "makes more money than", string1, "by", integer3, "dollars",

elif integer1 > integer2:
   print string1, "makes more money than", string2, "by", integer4, "dollars",

else:
   print string1, "and", string2, "both make", integer1, "dollars"




that works, you had wrong quotes on last line

Edited by on 03-09-06 07:29