Results 1 to 10 of 10

Thread: Python programmers?

  1. #1
    SG Enthusiast colour's Avatar
    Join Date
    Aug 2000
    Location
    Honolulu, Hawai'i
    Posts
    1,597

    Python programmers?

    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.

    here is what i have so far:

    PHP Code:
    true=1
    false
    =0
    answer
    =8
    repeating
    =true
    running
    =true
    while(repeating):
        while(
    running):
            
    inputString=raw_input("Enter a number: ")
            
    guess=int(inputString)
            if (
    guess>answer):
                print 
    "too high"
            
    elif (guess<answer):
                print 
    "too low"
            
    else:
                print 
    "correct"
                
    running=false
        
            inputString2
    =raw_input("play again, (y/n)?" )
            
    replay=inputString2.strip()
            if (
    replay=='y'):
                print 
    "ok"
            
    else:
                print 
    "bye"
                
    repeating=false 
    it runs all the way through then fails to run the 2nd loop(game loop) again, it just hangs.

    aslo for some odd reason i keep getting syntax errors when i try to use while(answer!=8).

    help?
    Last edited by colour; 04-05-04 at 08:15 AM.
    asdf?

  2. #2
    SG Enthusiast colour's Avatar
    Join Date
    Aug 2000
    Location
    Honolulu, Hawai'i
    Posts
    1,597

    ok i figured out the indentation was wrong.

    works almost right now.

    heres updated code:
    PHP Code:
    true=1
    false
    =0
    answer
    =8
    repeating
    =true
    running
    =true
    while(repeating):
        while(
    running):
            
    inputString=raw_input("Enter a number: ")
            
    guess=int(inputString)
            if (
    guess>answer):
                print 
    "too high"
            
    elif (guess<answer):
                print 
    "too low"
            
    else:
                print 
    "correct"
                
    running=false
        
        inputString2
    =raw_input("play again, (y/n)?" )
        
    eplay=inputString2.strip()
        if (
    replay=='y'):
            print 
    "ok"
        
    else:
            print 
    "bye"
            
    repeating=false 
    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".

    come on guys.
    asdf?

  3. #3
    Regular Member vc_wannabe's Avatar
    Join Date
    Jan 2002
    Location
    SD
    Posts
    487
    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...


    PHP Code:

    true
    =
    false
    =
    answer
    =
    repeating
    =true 
    running
    =true 
    while(repeating): 
        while(
    running): 
            
    inputString=raw_input("Enter a number: "
            
    guess=int(inputString
            if (
    guess>answer): 
                print 
    "too high" 
            
    elif (guess<answer): 
                print 
    "too low" 
            
    else: 
                print 
    "correct" 
                
    running=false 
         
        inputString2
    =raw_input("play again, (y/n)?" 
        
    replay=inputString2.strip() 
        if (
    replay=='y'):
            print 
    "ok"
            
    repeating=true
            running
    =true

        
    else: 
            print 
    "bye" 
            
    repeating=false
            running
    =false 
    Main: AMD Ryzen R7 3700X, Asus Crosshair Hero VI, Nvidia 2070 Super, 16GB 3200MHz Ram, NVMe, EVGA SuperNOVA 750 P2 PLATINUM, Lian Li PC-V2120

    Macbook Pro 16", Intel i9, AMD Radeon Pro 5500M, 16GB Ram, 1TB NVMe

    Security System "NVR": Intel i7 9700k, Z390 Phantom Gaming-ITX/ac, 16GB ram, Seasonic FOCUS+ 550 Platinum, Thermaltake Core V1 Mini ITX, Cryorig H7

  4. #4

    Heres a guessing game I came up with

    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

  5. #5
    Cybernetic Interloper ub3r_n00b's Avatar
    Join Date
    Feb 2003
    Location
    Rivendel, East of The Ford of Bruinen
    Posts
    2,086
    you figure it out? I can probably help you out.. i know python.


    -Preet
    www.erudianart.com

  6. #6
    Junior Member
    Join Date
    Jan 2005
    Posts
    2

    help wanted

    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

  7. #7
    Cybernetic Interloper ub3r_n00b's Avatar
    Join Date
    Feb 2003
    Location
    Rivendel, East of The Ford of Bruinen
    Posts
    2,086
    Do you mean loop back if input that the user entered is wrong?

    just have

    something = raw_input("Enter radius");
    while something < 0:
    something = raw_input("enter radius");



    Or whatever condition you want

    -Preet
    www.erudianart.com

  8. #8
    Junior Member
    Join Date
    Jan 2005
    Posts
    2

    more help pleeze

    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?

  9. #9
    Cybernetic Interloper ub3r_n00b's Avatar
    Join Date
    Feb 2003
    Location
    Rivendel, East of The Ford of Bruinen
    Posts
    2,086
    Quote Originally Posted by newbie101
    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;



    That will break out of the loop.

    -Preet
    www.erudianart.com

  10. #10
    SG Enthusiast colour's Avatar
    Join Date
    Aug 2000
    Location
    Honolulu, Hawai'i
    Posts
    1,597
    hey thanks for the replys, i figured it out, and never came back to check this thread. sorry.

    its been awhile but i think i got like a 99% on the project, got marked off because i didnt make it write to an output file correctly(syntax).
    asdf?

Similar Threads

  1. Microsoft Visual C++ 6.0 Programmer's Guide
    By Jon in forum Programming Forum
    Replies: 0
    Last Post: 09-07-01, 07:24 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •