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

New Free Tools on Dev Shed!

#1
April 2nd, 2005, 04:28 AM
 hye345
Registered User

Join Date: Apr 2005
Posts: 14
Time spent in forums: 1 h 13 m 59 sec
Reputation Power: 0
python beginner help

i am making a program that has u guess a number between one and 20, with 3 chances to get it right; i have this so far:

y = 0
x = input('Pick a number between one and twenty. ')

while x > 7:
x = input('Smaller. ''Try again. ')
y = y + 1
if y == 2:
print 'Sorry. ''The number was seven. '

while x < 7:
x = input('Bigger. ''Try again. ')
y = y + 1
if y == 2:
print 'Sorry. ''The number was seven. '

if x == 7:
print 'Correct. '

it doesnt work right. waht am i doing wrong? pleaz help.

#2
April 2nd, 2005, 06:48 AM
 pord_80
Contributing User

Join Date: Mar 2005
Posts: 51
Time spent in forums: 1 Day 4 h 30 m 3 sec
Reputation Power: 9
Hi

Well I am also new to python....
But I have had a lot of help that I am understanding the way python work myself>>>

So hope this help!

num = 9
attempts = 3

for k in range(attempts):
num = input("make a guess: ")
print
if num <1 or num >20:
print"Your guess is out of range\n"

elif num == 9:
break

elif num < 9:
print"Too low, try again\n"
print
elif num > 9:
print
print"Too high, try again\n"
else :
print "You have ran out of attempts"

#3
April 2nd, 2005, 07:38 AM
 pord_80
Contributing User

Join Date: Mar 2005
Posts: 51
Time spent in forums: 1 Day 4 h 30 m 3 sec
Reputation Power: 9
Quote:
 Originally Posted by pord_80 Well I am also new to python.... But I have had a lot of help that I am understanding the way python work myself>>> So hope this help! num = 9 attempts = 3 for k in range(attempts): num = input("make a guess: ") print if num <1 or num >20: print print"Your guess is out of range\n" elif num == 9: print"Your guess is correct\n" break elif num < 9: print print"Too low, try again\n" elif num > 9: print print"Too high, try again\n" else : print "You have ran out of attempts"

Try to mind indentations if you want to copy this example...

#4
April 2nd, 2005, 08:22 AM
 Dietrich
Contributing User

Join Date: Feb 2005
Posts: 575
Time spent in forums: 5 Days 4 h 14 m
Reputation Power: 63

I corrected the last code a little bit.
PHP Code:
``` # guess a number pick = 7 chances = 3 print "Guess a number between 1 and 20" print "You have", chances,"chances" for k in range(chances):   num = input("Make a guess: ")   if num < 1 or num > 20:     print "Your guess is out of range!"   elif num == pick:     break    elif num < pick:     print "Too low, try again!"   elif num > pick:     print "Too high, try again!" if num == pick:   print "Your guess is correct!" else:   print "You have run out of chances!"  ```

#5
April 2nd, 2005, 10:33 AM
 pord_80
Contributing User

Join Date: Mar 2005
Posts: 51
Time spent in forums: 1 Day 4 h 30 m 3 sec
Reputation Power: 9
Good work, both output basically the same result......
But I guess you can never know too much.
That is my philosophy

Keep it going guys.

#6
April 2nd, 2005, 02:07 PM
 hye345
Registered User

Join Date: Apr 2005
Posts: 14
Time spent in forums: 1 h 13 m 59 sec
Reputation Power: 0
thx!!!!

thx alot, guys. it worked.

 Viewing: Dev Shed Forums > Programming Languages > Python Programming > python beginner help