Author Topic: EOF in my py program  (Read 294 times)

N33n0Gr33n

  • Full Member
  • ***
  • Posts: 116
  • Reputation: 1
  • Rogue ininja
  • Computers: Dell,HP
  • iDevices: Iphone4,HTC
EOF in my py program
« on: September 29, 2012, 01:32:21 pm »

Half_ounce = 14.#grams
One_ounce = 28.#grams
A_quarter = 112.#grams
One_pound = 448.#grams



print 'I will tell you about the basic gram scale for banana's'
print# Line space
print "A half an ounce equals to %s" % Half_ounce
print "A half an ounce divided by 2 eqauls"
print Half_ounce / 2,('which is a 7th')
print# line Space
print "Multiply %d by 4 and you get %s grams." % (Half_ounce, One_ounce)
print# line Space
print "One ounce equals to %d grams" % One_ounce
print "Now divide %s by 2 and you get " % One_ounce
print One_ounce / 2
print
print "4 ounces multiplied by %d will give you %s" % (One_ounce, A_quarter)
print "%s divided by 2 will give you" % A_quarter
print A_quarter / 2
print "Which is a half ounce."
print
print"%s equals to a a pound" % One_pound
print "divide %d by 2 and you get."% One_pound
print One_pound / 2
print
print
# interactive script
print ("Now lets interact")
print
print ("Make a choice and i will")
print ("tell how many grams are in each one.")
print ("These are your choices")
print ("Half ounce, One ounce, A quarter, One pound")

run = int(input("Enter your choice:"))
while run:

   choice = int(input("Enter your choice:"))
   if choice == ("Half ounce"):
      print %d Half_ounce
      run = False

##############################################
I'm reading learn py the hard way, so you see all of the print is where  #
im practicing using %d and %s. And then i want to turn the program     #
into an interacive one. I ended the program at run = False to test the   #
output.                                                                                                     #
##############################################

                                                                                                           
                                                                                                           
« Last Edit: September 29, 2012, 09:19:46 pm by N33n0Gr33n »

[null]

  • Hero Member
  • *****
  • Posts: 646
  • Reputation: 42
  • the halloween jack is a real cool cat
  • Computers: I have a PC running Windows 7 that was built by my uncle. I also have a Newsmy T3 Android Tablet.
  • iDevices: iPod Touch 4G
Re: EOF in my py program
« Reply #1 on: September 29, 2012, 04:56:19 pm »
Next time, put your code in
Code: [Select]
code tags, like this!!But no matter. I'll download the script and try to find out the error.
« Last Edit: September 29, 2012, 08:30:09 pm by [null] »
__  __           ___    ___          
/\ \/\ \         /\_ \  /\_ \          
\ \ `\\ \  __  __\//\ \ \//\ \     
 \ \ , ` \/\ \/\ \ \ \ \  \ \ \          
  \ \ \`\ \ \ \_\ \ \_\ \_ \_\ \_
   \ \_\ \_\ \____/ /\____\/\____\
    \/_/\/_/\/___/  \/____/\/____/

A12danrulz

  • Leader
  • Hero Member
  • *****
  • Posts: 4018
  • Reputation: 216
  • Badges:
Re: EOF in my py program
« Reply #2 on: September 29, 2012, 05:32:45 pm »
The first print statement. Either enclose that string in double quotes or use an escape (aka a backslash) on the ' in banana's

Code: (Python) [Select]
print "I will tell you about the basic gram scale for banana's"
# Or....
print 'I will tell you about the basic gram scale for banana\'s'

However, even though both double and single quotes work for strings, generally you are supposed to use double quotes. It increases code readability.
« Last Edit: September 29, 2012, 05:43:44 pm by A12danrulz »

Trcx528

  • Haxor
  • Hero Member
  • *****
  • Posts: 4502
  • Reputation: 166
  • Google it!
    • iNinjas
  • Badges:
  • Computers: 13" 2011 Macbook Pro, 120 GB SSD and 16 GB of Ram
  • iDevices: None
Re: EOF in my py program
« Reply #3 on: September 29, 2012, 07:53:12 pm »
The difference between " ' is that the contents of double quoted are interpreted, where single quotes are considered literal.  For example %d inside double quotes will use the value of a variable, where as in a single quoted string it will display a literal %d, regardless of the value of the following variable.  This also means that single quoted strings do not need to be escaped, where double quoted strings do.   

N33n0Gr33n

  • Full Member
  • ***
  • Posts: 116
  • Reputation: 1
  • Rogue ininja
  • Computers: Dell,HP
  • iDevices: Iphone4,HTC
Re: EOF in my py program
« Reply #4 on: September 29, 2012, 09:14:52 pm »
Referring to the quotes, I have an idea of what you guys mean. I tried to get an output of %d and %s as one string from one variable but I ended up with two strings, maybe it was the quotes.
And [null] thanks for the heads up I'll remember that next time.

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: EOF in my py program
« Reply #5 on: September 30, 2012, 04:05:22 am »
Solved:

I did some research, reading a post back seven years.
here's the link if your curious( http://www.daniweb.com/software-development/python/threads/12326/how-to-do-input-in-python)

Basically i was asking the program to look for an integer as input.
Code: (Python) [Select]
run = int(input ("Enter your choice:"))
while run:

    choice = int(input ("Enter your choice:"))
    if choice == Half ounce:
        print Half_ounce
        run = False

When all i needed was raw input to grab my string and output my variable/integer, if said right. [null] thanks anyways.