SunQuest
           Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old February 3rd, 2004, 06:08 AM
Boceifus's Avatar
Boceifus Boceifus is online now
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 93 Boceifus User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 2 h 5 m 27 sec
Reputation Power: 5
yes or no only loop [i]inside[/i] a loop

greets

i would like a better way to handle my verify response.if something other than "y" or "n" is used,to just repeat the verify question,instead of starting the whole input process again.thx in advance

Code:
import os.path

fn= raw_input('Please enter the girls name. \n')

if os.path.isfile(fn+'.txt'):
    print 'File found.'
    file = open(fn+'.txt', 'r')
    p=file.readline()
    l=file.readline()
    s=file.readline()
    print 'Phone Number:'+p
    print 'Location:'+l
    print 'Star Rating:'+s
    file.close()
else:
    print 'No data on this girl!'
    print 'Please take a moment to enter her data. \n'
    while True:
        p= raw_input ('What is her phone number? \n')
        l= raw_input ('Where is she located? \n')
        s= raw_input ('How many stars? \n')
        print ' \nPLEASE VERIFY HER INFO: \n'
        print 'Name='+fn
        print 'Phone Number='+p
        print 'Location='+l
        print 'Star Rating='+s
        a= raw_input('\nIS THIS CORRECT? "y" FOR YES "n" FOR NO \n')
        if a == ('y'):
            print 'Sweet!Recording info!'
            file = open(fn+'.txt', 'w')
            file.write (p+'\n')
            file.write (l+'\n')
            file.write (s+'\n')
            file.close()
            break
        elif a == ('n'):
            print 'OK,lets try it again. \n'
        else:
            print 'Please answer "y" or "n".Re-initializing. \n'
                    
print 'Future options coming soon.'
raw_input('Press any key to quit.')


p.s. no,i dont meet THAT many women...i plan to use this to make/search for config files that my future codes may need.the blackbook shnick just made it interesting
__________________
It is not important if the glass is half full or half empty.What is important,is who has been drinking from MY glass?!?!?

Last edited by Boceifus : February 3rd, 2004 at 08:03 AM.

Reply With Quote
  #2  
Old February 3rd, 2004, 08:01 AM
lazy_yogi lazy_yogi is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Posts: 325 lazy_yogi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 h 58 m 36 sec
Reputation Power: 6
Re: basic questions for a basic code

change this :
Code:
        a= raw_input('\nIS THIS CORRECT? "y" FOR YES "n" FOR NO \n')
        if a == ('y'):
            print 'Sweet!Recording info!'
            file = open(' '+fn+'.txt', 'w')
            file.write (p+'\n')
            file.write (l+'\n')
            file.write (s+'\n')
            file.close()
            break
        elif a == ('n'):
            print 'OK,lets try it again. \n'
            time.sleep(1)
        else:
            print 'Please answer "y" or "n".Re-initializing. \n'
            time.sleep(1)
to this
Code:
        answer= raw_input('\nIS THIS CORRECT? "y" FOR YES "n" FOR NO 
        while answer != 'y' and answer != 'n':
            answer= raw_input('\nPLEASE TRY AGAIN: "y" FOR YES "n" FOR NO\n')

        if answer == 'y':
            print 'Sweet!Recording info!'
            file = open(' '+fn+'.txt', 'w')
            file.write (p+'\n')
            file.write (l+'\n')
            file.write (s+'\n')
            file.close()
            break
        elif answer == 'n':
            print 'OK,lets try it again. \n'
            time.sleep(1)

Reply With Quote
  #3  
Old February 3rd, 2004, 08:11 AM
Boceifus's Avatar
Boceifus Boceifus is online now
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 93 Boceifus User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 2 h 5 m 27 sec
Reputation Power: 5
thank you very much Yogi!

one small thing,you left off ') on your first line hehe.no biggie,it works after the syntax is fixed

Code:
        answer= raw_input('\nIS THIS CORRECT? "y" FOR YES "n" FOR NO')
        while answer != 'y' and answer != 'n':
            answer= raw_input('\nPLEASE TRY AGAIN: "y" FOR YES "n" FOR NO\n')

        if answer == 'y':
            print 'Sweet!Recording info!'
            file = open(' '+fn+'.txt', 'w')
            file.write (p+'\n')
            file.write (l+'\n')
            file.write (s+'\n')
            file.close()
            break
        elif answer == 'n':
            print 'OK,lets try it again. \n'
            time.sleep(1)

Reply With Quote
  #4  
Old February 3rd, 2004, 08:11 AM
netytan's Avatar
netytan netytan is offline
Hello World :)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Mar 2003
Location: Hull, UK
Posts: 2,529 netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 17 h 19 m 5 sec
Reputation Power: 63
Send a message via ICQ to netytan Send a message via AIM to netytan Send a message via MSN to netytan Send a message via Yahoo to netytan
or, totaly revamped...

Code:
#!/usr/bin/env python

while True:
	
	name = raw_input('enter a Name to continue...')

	if name:

		path = 'names/' + name + '.txt'

		try:
			details = file(path, 'r').readlines()
			print 'phone number...', details[0],
			print 'location...    ', details[1],
			print 'star rating... ', details[2],

		except IOError:
			print name, 'could not be found; add it?\n'

			while True:
				choices = raw_input('(Y/N)')
				if choices == 'Y':
					details = []
					details.append(raw_input('phone number...') + '\n')
					details.append(raw_input('location...    ') + '\n')
					details.append(raw_input('star rating... ') + '\n')

					file(path, 'w').writelines(details)

					choices = 'N'

				if choices == 'N':
					break

	print	


Looks for files in the current/names/ directory. most of this is formatting but hey

You wrote a program so you can rate gurls you've been with original i'll give you that.

Mark.
__________________
programming language development: www.netytan.com Hula


Reply With Quote
  #5  
Old February 3rd, 2004, 08:24 AM
Boceifus's Avatar
Boceifus Boceifus is online now
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 93 Boceifus User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 2 h 5 m 27 sec
Reputation Power: 5
hehe,i edited my original post a few times,and i think you guys are so quick that you responded while i was editing hehehe.so my original is prob different that what you replied to hehe.

but thank you for the fast replies!

and im gonna give netytans approach a whirl hehe.and btw,i did mention (maybe wasnt isnt the version you read hehe) that i planned something else for this...just the blackbook theme seemed amusing

here's the final code i came up with using Yogi's yes or no only code

Code:
import os.path

fn= raw_input('Please enter the girls name. \n')

if os.path.isfile(fn+'.txt'):
    print 'File found.'
    file = open(fn+'.txt', 'r')
    p=file.readline()
    l=file.readline()
    s=file.readline()
    print 'Phone Number:'+p
    print 'Location:'+l
    print 'Star Rating:'+s
    file.close()
else:
    print 'No data on this girl!'
    print 'Please take a moment to enter her data. \n'
    while True:
        p= raw_input ('What is her phone number? \n')
        l= raw_input ('Where is she located? \n')
        s= raw_input ('How many stars? \n')
        print ' \nPLEASE VERIFY HER INFO: \n'
        print 'Name='+fn
        print 'Phone Number='+p
        print 'Location='+l
        print 'Star Rating='+s
        answer= raw_input('\nIS THIS CORRECT? "y" FOR YES "n" FOR NO')
        while answer != 'y' and answer != 'n':
            answer= raw_input('\nPLEASE TRY AGAIN: "y" FOR YES "n" FOR NO\n')

        if answer == 'y':
            print 'Sweet!Recording info!'
            file = open(fn+'.txt', 'w')
            file.write (p+'\n')
            file.write (l+'\n')
            file.write (s+'\n')
            file.close()
            break
        elif answer == 'n':
            print 'OK,lets try it again. \n'
            time.sleep(1)

                    
print 'Future options coming soon.'
raw_input('Press any key to quit.')

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > basic questions for a basic code


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway