Author Topic: Py variables  (Read 288 times)

N33n0Gr33n

  • Full Member
  • ***
  • Posts: 116
  • Reputation: 1
  • Rogue ininja
  • Computers: Dell,HP
  • iDevices: Iphone4,HTC
Py variables
« on: October 23, 2012, 01:15:44 am »
I want to write a script that responds to variables as negative or a positive.
Ex:

code: [select]
def good_bad (*args)
       Me, you = args
       print " blah %s blaah %s " % (Me, you)
       print " who would you rather be? "

Me = # a positive a number like 8
you = # a negative number like 7
raw_input(Enter me or you):

the negative and positives give certain
answers using if and elif.



grinch

  • Administrator
  • Hero Member
  • *****
  • Posts: 1926
  • Reputation: 187
  • the digital grinch who stole your data
    • @DigitalGrinch
  • Badges:
  • iDevices: iPhone 3GS 4.3.3, HTC Evo V 4G ICS
Re: Py variables
« Reply #1 on: October 23, 2012, 10:22:37 am »
Do you mean odd and even, not positive and negative?

7 vs 8

-1 vs 1
If I help you or you appreciate my work, clicking that +1 button is the best thanks I could get.

My opinions are my own, you may agree or disagree with them, but they are only just that; opinions
For example: facebook is the microsoft of social networks

http://goo.gl/PiVjI

@DigitalGrinch
https://twitter.com/DigitalGrinch

I follow all iNinjas members back. PM me if I am not following you

N33n0Gr33n

  • Full Member
  • ***
  • Posts: 116
  • Reputation: 1
  • Rogue ininja
  • Computers: Dell,HP
  • iDevices: Iphone4,HTC
Re: Py variables
« Reply #2 on: October 23, 2012, 11:07:48 am »
Yes, but instead of receiving true or false my output would be a string.

grinch

  • Administrator
  • Hero Member
  • *****
  • Posts: 1926
  • Reputation: 187
  • the digital grinch who stole your data
    • @DigitalGrinch
  • Badges:
  • iDevices: iPhone 3GS 4.3.3, HTC Evo V 4G ICS
Re: Py variables
« Reply #3 on: October 23, 2012, 02:47:17 pm »
Does it have to accept odd or even numbers as choices, or is inputting a letter like "A" for Me and "B" for You, or even "M" or "Y" as choices ok?
If I help you or you appreciate my work, clicking that +1 button is the best thanks I could get.

My opinions are my own, you may agree or disagree with them, but they are only just that; opinions
For example: facebook is the microsoft of social networks

http://goo.gl/PiVjI

@DigitalGrinch
https://twitter.com/DigitalGrinch

I follow all iNinjas members back. PM me if I am not following you

A12danrulz

  • Leader
  • Hero Member
  • *****
  • Posts: 4018
  • Reputation: 216
  • Badges:
Re: Py variables
« Reply #4 on: October 23, 2012, 03:41:02 pm »
Well to check for numbers being even, use modulus by 2. If it returns 0, it's even, odd will return 1.


if not num % 2:
  # Code for an even number, like 4
elif num % 2:
  # Code for an odd number, like 7


If your doing negative or positive, use greater than or less than signs.


if num > 0:
  # Num is positive
elif num < 0:
  # Num is negative

Don't like seeing ads? Click here to register!

N33n0Gr33n

  • Full Member
  • ***
  • Posts: 116
  • Reputation: 1
  • Rogue ininja
  • Computers: Dell,HP
  • iDevices: Iphone4,HTC
Re: Py variables
« Reply #5 on: October 23, 2012, 05:02:08 pm »
Both of you guys are on the money, I changed it and basically used if elif as it should. I used names for variables I'll give you guys a sample just to give a visual.

Code: [ select ]


def politics(*args):
   Democrat, Republican = args
   print "President Obama'\s a %s, Romney'\s a %s" % (Democrat, Republican)
   print("Who will you vote for?")
   
politics("Democrat", "Republican")   

Romney = 1
Obama = 2
answer = int(input("Enter your choice 1, 2:"))
if answer == Romney:
   print"So you like Romney?"
elif answer > Romney:
   print "So you like President Obama?"
print
print
prompt = 'press enter'
raw_input(prompt),

a = "poor"
b = "rich" 
r = "Republican" 
d = "Democrat"
print "Some people say when your rich you vote %s" % r
print "And if you vote %r" % d
print "you are %s" % a

« Last Edit: October 23, 2012, 05:10:30 pm by N33n0Gr33n »