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

#1
February 3rd, 2004, 06:08 AM
 Boceifus
Contributing User

Join Date: Jan 2004
Posts: 103
Time spent in forums: 3 Days 1 h 17 m 20 sec
Reputation Power: 10
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')
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 '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.

#2
February 3rd, 2004, 08:01 AM
 lazy_yogi
Contributing User

Join Date: Mar 2003
Posts: 325
Time spent in forums: 7 h 58 m 36 sec
Reputation Power: 11
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:
time.sleep(1)```
to this
Code:
```        answer= raw_input('\nIS THIS CORRECT? "y" FOR YES "n" FOR NO

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

#3
February 3rd, 2004, 08:11 AM
 Boceifus
Contributing User

Join Date: Jan 2004
Posts: 103
Time spent in forums: 3 Days 1 h 17 m 20 sec
Reputation Power: 10
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')

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

#4
February 3rd, 2004, 08:11 AM
 netytan
Hello World :)

Join Date: Mar 2003
Location: Hull, UK
Posts: 2,537
Time spent in forums: 1 Week 2 Days 18 h 17 m 47 sec
Reputation Power: 68
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:
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

#5
February 3rd, 2004, 08:24 AM
 Boceifus
Contributing User

Join Date: Jan 2004
Posts: 103
Time spent in forums: 3 Days 1 h 17 m 20 sec
Reputation Power: 10
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')
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')

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

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

 Viewing: Dev Shed Forums > Programming Languages > Python Programming > basic questions for a basic code