7 Replies - 375 Views - Last Post: 02 July 2012 - 05:56 PM Rate Topic: -----

#1 BloodyInari  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 106
  • Joined: 16-November 09

Just messing around

Posted 01 July 2012 - 07:38 PM

story of my life, reading comics and mimicking them. HAHA! I'm sad now...
(anyhow, learning python and while loops)
def main():
#console mocks your loveless life
	love = raw_input("Do you love me? (y/n) ")
	
	if love == "n":
		print "I'll be back tomorrow..."
		while love == "n":
			print "\nDo you love me now?"
			love = raw_input("response (y/n): ")

			if love == "n":
				print "\nI'll be back tomorrow..." 
			elif love == "y":
				print "\nLove acquired!"
			else:
				print "\nYou're a twit! WHY DO I LOVE YOU?!"
	elif love == "y":

		print "\nLove acquired!"
	else:
		print "\nYou're a twit! WHY DO I LOVE YOU?!"
main()


This post has been edited by BloodyInari: 01 July 2012 - 07:40 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Just messing around

#2 atraub  Icon User is offline

  • Pythoneer
  • member icon

Reputation: 759
  • View blog
  • Posts: 2,010
  • Joined: 23-December 08

Re: Just messing around

Posted 01 July 2012 - 08:39 PM

I'd change the first 2 love == "n" conditions to love.lower() != "y" Something like this:

def main():
    #console mocks your loveless life
    love = raw_input("Do you love me? (y/n) ").lower()
    if love != "y":
        print "I'll be back tomorrow..."
        while love != "y":
            love = raw_input("\nDo you love me now?\nresponse (y/n): ").lower()

            if love == "n":
                print "\nI'll be back tomorrow..." 
            elif love == "y":
                print "\nLove acquired!"
            else:
                print "\nYou're a twit! WHY DO I LOVE YOU?!"
    else:
        print "\nLove acquired!"

if __name__ == "__main__":
    main()



This post has been edited by atraub: 01 July 2012 - 08:49 PM

Was This Post Helpful? 0
  • +
  • -

#3 Dogstopper  Icon User is offline

  • The Ninjaducky
  • member icon



Reputation: 2870
  • View blog
  • Posts: 11,021
  • Joined: 15-July 08

Re: Just messing around

Posted 01 July 2012 - 09:16 PM

Is there a question here? While atraub did make a good point with his comment, unless you are posting with a question in mind, you should start a blog and share it there instead. </dream.in.code> has blogs that you can set up and use as much as you'd like.
Was This Post Helpful? 0
  • +
  • -

#4 atraub  Icon User is offline

  • Pythoneer
  • member icon

Reputation: 759
  • View blog
  • Posts: 2,010
  • Joined: 23-December 08

Re: Just messing around

Posted 01 July 2012 - 09:29 PM

Yeah, I think he was just sharing a piece of code that wasn't quite a snippet, more of a discussion than anything :) Wasn't sure where to redirect him.
Was This Post Helpful? 0
  • +
  • -

#5 BloodyInari  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 106
  • Joined: 16-November 09

Re: Just messing around

Posted 01 July 2012 - 09:58 PM

View Postatraub, on 01 July 2012 - 10:39 PM, said:

I'd change the first 2 love == "n" conditions to love.lower() != "y" Something like this:

def main():
    #console mocks your loveless life
    love = raw_input("Do you love me? (y/n) ").lower()
    if love != "y":
        print "I'll be back tomorrow..."
        while love != "y":
            love = raw_input("\nDo you love me now?\nresponse (y/n): ").lower()

            if love == "n":
                print "\nI'll be back tomorrow..." 
            elif love == "y":
                print "\nLove acquired!"
            else:
                print "\nYou're a twit! WHY DO I LOVE YOU?!"
    else:
        print "\nLove acquired!"

if __name__ == "__main__":
    main()



no, you make a good point actually; removing redundant statements/optimizing the looping sequence.
Was This Post Helpful? 0
  • +
  • -

#6 BloodyInari  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 106
  • Joined: 16-November 09

Re: Just messing around

Posted 01 July 2012 - 10:32 PM

however Atraub, your version has a few inconsistencies that my code handled (like a repetition output for "y")
Optimized:
def main():
#console mocks your loveless life
	love = raw_input("Do you love me? (y/n) ")

	if love != "y":
                if (love != "y") and (love != "n"):
                        print "\nYou're a twit! WHY DO I LOVE YOU?!"
                        return
		print "\nI'll be back tomorrow..."

	while love != "y":
                print "*One tomorrow later*"
		love = raw_input("\nDo you love me now?\nresponse (y/n): ").lower()
	 
                if love == "n":
                        print "\nI'll be back tomorrow..."
	        elif love == "y":
	                print "\nLove acquired!"
	                return
	        else:
	                print "\nYou're a twit! WHY DO I LOVE YOU?!"
	                return
	else:
                print "\nLove acquired!"
main()


This post has been edited by BloodyInari: 01 July 2012 - 10:38 PM

Was This Post Helpful? 0
  • +
  • -

#7 atraub  Icon User is offline

  • Pythoneer
  • member icon

Reputation: 759
  • View blog
  • Posts: 2,010
  • Joined: 23-December 08

Re: Just messing around

Posted 02 July 2012 - 07:36 AM

Playing around with it on IDLE, I'm not sure what you're talking about

>>> main()
Do you love me? (y/n) y

Love acquired!
>>> main()
Do you love me? (y/n) Y

Love acquired!
>>> main()
Do you love me? (y/n) n
I'll be back tomorrow...

Do you love me now?
response (y/n): U

You're a twit! WHY DO I LOVE YOU?!

Do you love me now?
response (y/n): Y

Love acquired!
>>> main()
Do you love me? (y/n) f
I'll be back tomorrow...

Do you love me now?
response (y/n): f

You're a twit! WHY DO I LOVE YOU?!

Do you love me now?
response (y/n): f

You're a twit! WHY DO I LOVE YOU?!

Do you love me now?
response (y/n): Y

Love acquired!


What haven't I accounted for? Is it that you want it to display the "you're a twit" dialog even on the initial question? I'm confused

This post has been edited by atraub: 02 July 2012 - 07:37 AM

Was This Post Helpful? 0
  • +
  • -

#8 BloodyInari  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 106
  • Joined: 16-November 09

Re: Just messing around

Posted 02 July 2012 - 05:56 PM

View Postatraub, on 02 July 2012 - 09:36 AM, said:

Playing around with it on IDLE, I'm not sure what you're talking about

response (y/n): U

You're a twit! WHY DO I LOVE YOU?!

Do you love me now?
response (y/n): Y

Love acquired!


Is it that you want it to display the "you're a twit" dialog even on the initial question? I'm confused


yeah, that (modified your snippet with a return statement) and I think when I copypasta'd it, I ran into a redundant display for "n". However, its no matter now as it works perfectly.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1