General software, Operating Systems, and Programming discussion.
Everything from software questions, OSes, simple HTML to scripting languages, Perl, PHP, Python, MySQL, VB, C++ etc.
i need some help. im trying to create a number guessing game, eventually itll be randomly generated but for now its hard coded. im trying to have it loop, after a user plays it once, itll prompt Y/N to play again.
the problem now is that it loops the second block and not the game. after the "play again, (y/n)?" prompt itll loop "play again, (y/n)?" until you enter "n".
I took a look at it, its like 3am here and Im shot. I tested it, seems to work... Here is what the modified code is. You had it very close... If you copy this, make sure to move the first line back one space. I dont know why it keeps moving it over...
true=1
false=0
import random
repeating=true
running=true
while(repeating):
x = random.random()
y = int(10*x) + 18
guesses = 0
while(running):
guesses = guesses + 1
if (guesses == 4):
running = false
print "Welcome to the guessing game"
inputString=raw_input("Enter a number: ")
guess=int(inputString)
if (guess > y):
print "Too high"
elif (guess < y):
print "Too low"
else:
print "Yay, you got it correct"
running=false
inputString2=raw_input("Enter a 'Y' to guess again:\n" )
replay=inputString2.strip()
replay=inputString2.upper()
if (replay=='y'):
repeating=true
running=true
elif (replay=='Y'):
repeating = true
running =true
else:
print "Thanks for playing the guessing game"
repeating=false
running=false
hey,
i'm a realy newbie, so pardon the simple problem. i've just finished creating my first program that calculates area of a circle for you. i want to know how i can make the program loop back to the part where they input the radius. right now, i have to restart the entire program just to get back to the input part. here is the code:
print "Area of a Circle"
radius = input("What is the radius?")
area = 3.14*radius*radius
print "The area is", area
hey,
thanx for the help, but i've got another problem. as it stands, my program will continue to repeat itself as long as the area is > 0 (Which is always usually) anyway, i want to ask the user if he wants to go back to the main menu after the area for the cirlce is displayed if he says no, i want the program to continue asking for the radius, but if he says yes, i want the program to go back to the main menu. do you know how i can do that?
newbie101 wrote:hey,
thanx for the help, but i've got another problem. as it stands, my program will continue to repeat itself as long as the area is > 0 (Which is always usually) anyway, i want to ask the user if he wants to go back to the main menu after the area for the cirlce is displayed if he says no, i want the program to continue asking for the radius, but if he says yes, i want the program to go back to the main menu. do you know how i can do that?
insert some type of condition in the while loop
like
while something >= 0:
something = raw_input("Enter raidus, type 0 to go to menu");
if(something == 0):
break;