#16
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Location
    Usually Japan when not on contract
    Posts
    240
    Rep Power
    12
    Originally Posted by Wretch11
    is that close to right?
    Its not close to right, its exactly right. You're not slow on the uptake, you're just new. Keep reading and toying with the interpreter as much as you can. Your wetware is obviously working just fine.
  2. #17
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    27
    Rep Power
    0
    Code:
    import pygame
    import random
    
    # Defined colors
    black    = (   0,   0,   0)
    white    = ( 255, 255, 255)
    green    = (   0, 255,   0)
    red      = ( 255,   0,   0)
    dark_green_night_grass = (12, 99, 38)
    dark_blue_night_sky = (44, 12, 99)
    night_mountain_brown = (105, 75, 5)
    mountain_shadow = (71, 71, 69)
    pi = 3.141592653
    
    
    pygame.init()
      
    
    size = [700,500]
    screen = pygame.display.set_mode(size)
    pygame.display.set_caption("My Game")
    
    clock = pygame.time.Clock()
    
    
    done = False
    ellipse_x = 480
    ellipse_y = 75
    
    ellipse_x_two = 600
    ellipse_y_two = 50
    
    ellipse_change_x = -1
    ellipse_change_y = 0
    # -------- Main Program Loop -----------
    while done == False:
        
        for event in pygame.event.get(): 
            if event.type == pygame.QUIT: 
                done = True 
        
       
        screen.fill(white)
        
        pygame.draw.rect(screen,dark_blue_night_sky,[0,0,700,200],0) 
        pygame.draw.rect(screen,dark_green_night_grass,[0,200,700,300],0)
        pygame.draw.polygon(screen,night_mountain_brown,[(0,199),(150,100),(250,150),(300,90),(450,199),(-450,199)])
        pygame.draw.lines(screen,(0, 0, 0),False,[(0,199),(150,100),(250,150),(300,90),(450,199),],3)
        pygame.draw.circle(screen,(240, 239, 223),(235, 104), 26,)
        pygame.draw.circle(screen,(237, 217, 135),(235, 104), 25,2)
        pygame.draw.polygon(screen,(0, 0, 0),[(290,500),(345,200),(355,200),(410,500),(-120,500)],3)
        pygame.draw.polygon(screen,(82, 62, 29),[(291,499),(346,199),(354,199),(409,499),(-121,499)])
        pygame.draw.ellipse(screen,(5, 10, 5),[ellipse_x,ellipse_y,200,50])
        pygame.draw.ellipse(screen,(5, 10, 5),[ellipse_x_two,ellipse_y_two,70,30])
    
        ellipse_x += ellipse_change_x
        ellipse_y += ellipse_change_y
        ellipse_x_two += ellipse_change_x
        ellipse_y_two += ellipse_change_y
    
        if ellipse_x < -300 and ellipse_x_two < -50:
            ellipse_x = 880
            ellipse_x_two = 1000
        
        
        pygame.display.flip()
     
        
        clock.tick(20)
         
    
    pygame.quit()
    I'm trying my hand at simple animations. Currently, the code above moves two ellipses (clouds) from right to left on the screen. I'd like to add a simple effect where, as the clouds pass over the moon, the whole images darkens with a transparent black.

    My question is, how do I make a color transparent and how do I control the amount of transparency. I had a quick look around google, but could not turn up any clear answer.

    Again any help would be appreciated.
  4. #18
  5. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,900
    Rep Power
    481
    r g b and alpha. Use alpha.
    http://en.wikipedia.org/wiki/RGBA_color_space
    [code]Code tags[/code] are essential for python code and Makefiles!
  6. #19
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Location
    Usually Japan when not on contract
    Posts
    240
    Rep Power
    12
    Originally Posted by Wretch11
    My question is, how do I make a color transparent and how do I control the amount of transparency.
    In computers there is actually no such thing as transparency. There is painting a color or not. The color you pick, though, could be a blend of the colors you are considering the foreground and the background, and so pick a color that makes it appear that the foreground is tainting the image behind it.

    That's what b49P23TIvg is getting at with the RGB color scale reference. Play with the RGB values of whatever color you are painting, and adjust the zone you need to appear affected so that it appears the right way.

    Let's say I have an image of a tree. Then I want to show the image of the tree as though we are looking out of a half-opened window of pink-stained glass. I have to paint the image, of course, but to make the part covered by the glass look correct, the glass itself instead of being an image of its own, is an RGB value zone that is added to whatever images beyond it are. So the tree image is still shown, but the part of it covered by the glass bit is color-adjusted (mixing original values with the RGB tint the glass represents, and then usually reducing contrast so it doesn't look crazy).
  8. #20
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    27
    Rep Power
    0
    Code:
    import pygame
    import random
    
    # Defined colors
    black    = (   0,   0,   0)
    white    = ( 255, 255, 255)
    green    = (   0, 255,   0)
    red      = ( 255,   0,   0)
    dark_green_night_grass = (12, 99, 38)
    dark_blue_night_sky = (44, 12, 99)
    night_mountain_brown = (105, 75, 5)
    mountain_shadow = (71, 71, 69)
    pi = 3.141592653
    
    
    pygame.init()
      
    
    size = [700,500]
    screen = pygame.display.set_mode(size)
    pygame.display.set_caption("My Game")
    
    clock = pygame.time.Clock()
    
    
    done = False
    ellipse_x = 480
    ellipse_y = 75
    
    ellipse_x_two = 600
    ellipse_y_two = 50
    
    ellipse_change_x = -1
    ellipse_change_y = 0
    # -------- Main Program Loop -----------
    while done == False:
        
        for event in pygame.event.get(): 
            if event.type == pygame.QUIT: 
                done = True 
        
       
        screen.fill(white)
        
        pygame.draw.rect(screen,dark_blue_night_sky,[0,0,700,200],0) 
        pygame.draw.rect(screen,dark_green_night_grass,[0,200,700,300],0)
        pygame.draw.polygon(screen,night_mountain_brown,[(0,199),(150,100),(250,150),(300,90),(450,199),(-450,199)])
        pygame.draw.lines(screen,(0, 0, 0),False,[(0,199),(150,100),(250,150),(300,90),(450,199),],3)
        pygame.draw.circle(screen,(240, 239, 223),(235, 104), 26,)
        pygame.draw.circle(screen,(237, 217, 135),(235, 104), 25,2)
        pygame.draw.polygon(screen,(0, 0, 0),[(290,500),(345,200),(355,200),(410,500),(-120,500)],3)
        pygame.draw.polygon(screen,(82, 62, 29),[(291,499),(346,199),(354,199),(409,499),(-121,499)])
        pygame.draw.ellipse(screen,(5, 10, 5),[ellipse_x,ellipse_y,200,50])
    
        if ellipse_x <= 290 and ellipse_x >= 10:
            windowSurface = pygame.display.set_mode((700, 500), pygame.DOUBLEBUF)
            s = pygame.Surface((700,500),pygame.SRCALPHA)
            s.fill((1,1,1, 250))
            windowSurface.blit(s, (0,0))
        
        pygame.draw.ellipse(screen,(5, 10, 5),[ellipse_x_two,ellipse_y_two,70,30])
    
        ellipse_x += ellipse_change_x
        ellipse_y += ellipse_change_y
        ellipse_x_two += ellipse_change_x
        ellipse_y_two += ellipse_change_y
    
        if ellipse_x < -300 and ellipse_x_two < -50:
            ellipse_x = 880
            ellipse_x_two = 1000
        
        
        pygame.display.flip()
     
        
        clock.tick(20)
         
    
    pygame.quit()
    Trying the advice given above, this is what I ended up with. Now, black does cover my screen when the ellipses are where they need to be, but the screen goes full black, and shows nothing of whats behind it regardless of what I set my alpha at. Does anyone have an idea?

    As always, thanks
  10. #21
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Location
    Usually Japan when not on contract
    Posts
    240
    Rep Power
    12
    This is more of a pygame library question (a library with which I'm not familiar) but it seems the problem is in this snippet:
    python Code:
    windowSurface = pygame.display.set_mode((700, 500), pygame.DOUBLEBUF)
    s = pygame.Surface((700,500),pygame.SRCALPHA)
    s.fill((1,1,1, 250))
    windowSurface.blit(s, (0,0))

    Setting s to be the entire surface, then telling it to fill with 1,1,1 would turn things black. The alpha range for black shouldn't matter -- black will reduce to black.

    You want a call to your screen object that reduces the value of all contained colors at once. I'm pretty sure that a library like pygame would have a shader like this, I just don't know much about pygame so I can't say.

    To do it manually you would redraw everything in screen in the body of your if statement, but with a new color selected. So say you start with your declared "green" value and pygame.draw.rect() for the grass, then in the body of the if you would once again pygame.draw.rect() but with the dark_green value.

    Most OOP graphics libraries can return persistent objects once you draw them. So see if pygame supports something like:
    python Code:
    grass = pygame.draw.rect(screen, green, grass_shape, 0)
    grass.shade(night_shade_value)

    The second call is psuedocode -- its probably not a real pygame method, but things like this exist in many libraries, where you draw a thingy, the thingy is actually a persistent object, and you can tell it to change its color or image or dimensions or whatever on the fly.

    Look for things like this in the documentation for the library you are using. My explanation about graphics above is very low-level. Using a graphics library does all that stuff for you, you just need to read the docs of the graphics library you're using to find out what features are available.
  12. #22
  13. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,900
    Rep Power
    481
    And this tutorial might help---you shouldn't need to redraw the static portion of your movie.

    http://www.pygame.org/docs/tut/MoveIt.html
    [code]Code tags[/code] are essential for python code and Makefiles!
  14. #23
  15. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    27
    Rep Power
    0
    Got it working

    Code:
    import pygame
    import random
    
    # Defined colors
    black    = (   0,   0,   0)
    white    = ( 255, 255, 255)
    green    = (   0, 255,   0)
    red      = ( 255,   0,   0)
    dark_green_night_grass = (12, 99, 38)
    dark_blue_night_sky = (44, 12, 99)
    night_mountain_brown = (105, 75, 5)
    mountain_shadow = (71, 71, 69)
    pi = 3.141592653
    TRANSPARENT = (255,0,255)
    
    pygame.init()
      
    
    size = [700,500]
    screen = pygame.display.set_mode(size)
    pygame.display.set_caption("My Game")
    
    clock = pygame.time.Clock()
    
    done = False
    
    ellipse_x = 480
    ellipse_y = 75
    
    ellipse_x_two = 600
    ellipse_y_two = 50
    
    ellipse_change_x = -1
    ellipse_change_y = 0
    
    x = random.randrange(0,701)
    y = random.randrange(0,201)
    
    surf1 = pygame.Surface((700,500))
    surf1.fill(TRANSPARENT)
    surf1.set_colorkey(TRANSPARENT)
    pygame.draw.rect(surf1,(1,1,1,100),[0,0,700,500],0)
    surf1.set_alpha(100)
    
    # -------- Main Program Loop -----------
    while done == False:
        
        for event in pygame.event.get(): # User did something
            if event.type == pygame.QUIT: # If user clicked close
                done = True # Flag that we are done so we exit this loop
        
    
      
        
        screen.fill(white)
    
        
        pygame.draw.rect(screen,dark_blue_night_sky,[0,0,700,200],0)
        
         
            # Draw the star
        pygame.draw.circle(screen, white,(x,y), 2)
        x = x
        y = y
             
            
        
        pygame.draw.rect(screen,dark_green_night_grass,[0,200,700,300],0)
        pygame.draw.polygon(screen,night_mountain_brown,[(0,199),(150,100),(250,150),(300,90),(450,199),(-450,199)])
        pygame.draw.lines(screen,(0, 0, 0),False,[(0,199),(150,100),(250,150),(300,90),(450,199),],3)
        pygame.draw.circle(screen,(240, 239, 223),(235, 104), 26,)
        pygame.draw.circle(screen,(237, 217, 135),(235, 104), 25,2)
        pygame.draw.polygon(screen,(0, 0, 0),[(290,500),(345,200),(355,200),(410,500),(-120,500)],3)
        pygame.draw.polygon(screen,(82, 62, 29),[(291,499),(346,199),(354,199),(409,499),(-121,499)])
        pygame.draw.ellipse(screen,(5, 10, 5),[ellipse_x,ellipse_y,200,50])
        if ellipse_x <= 270 and ellipse_x >= 10:
            screen.blit(surf1,(0,0,700,500))
            
            
            
    
        pygame.draw.ellipse(screen,(5, 10, 5),[ellipse_x_two,ellipse_y_two,70,30])
    
        ellipse_x += ellipse_change_x
        ellipse_y += ellipse_change_y
        ellipse_x_two += ellipse_change_x
        ellipse_y_two += ellipse_change_y
    
        if ellipse_x < -300 and ellipse_x_two < -50:
            ellipse_x = 880
            ellipse_x_two = 1000
    
    
        pygame.display.flip()
     
        
        clock.tick(20)
         
    
    pygame.quit()
    My next challenge: getting the "shadows" moving from left to right when the clouds start covering the moon. I'll report back if I can't figure it out
  16. #24
  17. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,900
    Rep Power
    481

    unusual operation in python


    You can write
    if 10 <= ellipse_x <= 270:
    which python interprets as if it were written as in mathematical notation.

    Also,

    import math
    pi = math.pi
    TAU = 2*pi # http://tauday.com/tau-manifesto
    [code]Code tags[/code] are essential for python code and Makefiles!
  18. #25
  19. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Location
    Usually Japan when not on contract
    Posts
    240
    Rep Power
    12
    Originally Posted by Wretch11
    Got it working
    Code:
    if ellipse_x <= 270 and ellipse_x >= 10:
        screen.blit(surf1,(0,0,700,500))
    Nice job. Now you see what I mean -- most libraries have functions to handle this stuff for you, but you have to read the docs to know they are there. Knowing what to expect of a library is helpful as well and comes with experience, so you can't be faulted for not knowing about blit() just yet. That said, I strongly recommend that you read the pygame API once all the way through and read the Python language reference docs to see what modules exist (at least the first page of every module included in the core language to know what features are available).

    Around 90% of common "I need to do X... how?" type questions are answerable directly from library and language docs, but very few people seem to realize the exist, or know they exist and never spend even an hour browsing through them to get a feel for where things are. This means two things: 1- most people suck and aren't worth helping, 2- library and language designers have beaten the path wide and far to cover the vast majority of programming needs with functions for nearly anything you can think of (you just need to know the function exists).
    My next challenge: getting the "shadows" moving from left to right when the clouds start covering the moon. I'll report back if I can't figure it out
    Probably going to involve two color zones moving together drawn in sync in reference to a common anchor point that is being updated...

    But I wouldn't be surprised if the graphics library already has something that makes this trivial to code (whereas my explanation of how it works is rather low level).
  20. #26
  21. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    27
    Rep Power
    0
    At this point, I think i'll let pygame be for a while and return my focus on fully understanding basic python itself, without no added libraries.

    I was getting ahead of myself. Though I still managed to do what I set out to do with that test scenery, I need to have a better understanding of what python initially offers before I try taking on anything else, otherwise i'll just confuse myself.

    I'm gonna hit the docs for some intensive reading, then' I'll start thinking of some projects to put everything into practice. I found this site called codeacademy which offers interactive python tutorials so I'll also be checking that out. I'll keep reporting back with my progress and any question I might have.
  22. #27
  23. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Location
    Usually Japan when not on contract
    Posts
    240
    Rep Power
    12
    Way to go on figuring out hard stuff on your own. I frequently remember an adage ESR told me years ago: "If you understand what you're doing, you're not learning anything!"

    I would definitely recommend hitting the core python docs before going through non-core tutorials. codeacademy might have some great stuff, but considering how well you've done grasping new things so far, I really think that you + task + docs = win already.
  24. #28
  25. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    27
    Rep Power
    0
    I know python is a high level programming language that uses something called an interpreter to transform the input(source code) into machine code, but i'm wondering, what exactly is machine code? I know it works with the binary numeral system, but is that what they call assembly?
  26. #29
  27. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Location
    Usually Japan when not on contract
    Posts
    240
    Rep Power
    12
    Wow... bringing out the big questions. Your basic assumptions are correct, and you're probably wondering how in the world a set of numbers wind up becoming a set of instructions and how that turns gigantic binary numbers of a certain form into pictures of bikinis on your screen.

    But that requires a huge answer to respond to correctly. In fact, the answer spans the gap from electrical engineering to the theory of symbolic computation -- which is a pretty huge gap, with several points in between. (Each truly fascinating and absolutely worth contributing time towards vs, say, spending hours on end watching TV or other forms of imaginary reality.)

    The concise answer is to say that numbers are given an arbitrary meaning to the hardware, and that parts of the numbers represent three things:
    • What to operate on
    • What operation to perform
    • Where to go next

    In PC-type machines today the third part is just a special form of the first two; the operation being "go" and the operand being an address in memory to pull.

    This means two things, that numbers can have coded meanings pre-decided by the architecture of the hardware, and the positioning of a number within a stream of bits can itself have a meaning.

    So processors are constantly staring down the barrel of an effectively endless stream of bits, chopping them up into segments, and then categorizing their meaning by their relative placement -- "these first 8 bits are a number I should remember as a noun, to which I will apply the next 8 bits, which represent a verb; then the next 8 bits represent a [foo] while the next 8 represent a [bar]" and so on.

    For this reason it is, if you are a bit insanely dedicated to a particular hardware architecture, actually possible to write a program in raw binary. And for teeny tiny things this is actually a workable way to program, and it was for a long time the only way to program -- back when programmers were the same guys who physically built and maintained not just the machines, but the actual circuits and gates which defined the meanings encoded in the numbers.

    Pretty soon, though, that started to suck. I mean, the most convenient form of binary input is to twiddle a switch, and about the 1,000th twiddle you might forget which part of the program you were writing and screw it all up. No room for error with machines, after all.

    So groups of commonly used meanings were given code-words. Initially those code words had to be saved somehow, which originally mean triggering a physical device that would stream out whatever pattern the word represented. Those were the first programming verbs. But that sucked too, because they had to be connected by a series of GOTO instructions which, while making it possible to tell a program to repeat something or jump to a different section, didn't do much to make that jump mean anything with context attached (imagine being able to only call functions without arguments, forcing each to initialize its own context after entry).

    Blah blah... so a lot of these sort of incremental advancements went on over time. They basically followed a common pattern of "we now recognize that operation X is really useful and really common, and should be wrapped up in a single word so we only have to do the work involved in awful task X once, and can just call it from then on by name Y".

    And then it dawned on people that what programming was really about was describing processes (and that the "use OOP for everything" crowd has totally forgotten this is hilarious). Machines can deal with detail, and humans can think in the abstract. So the key is to design languages that permit the humans to think in the abstract (which means finding ways to hide details like which part of a numeric code means what to a computer) and give the machines a vast arsenal of ways in which they can transform those human-level abstractions into numerically correct instructions. At the very highest level of language the point is to let humans develop dynamic semantic systems (actually, "ontologies" -- but most programmers never realize they are doing this) that can flex the meanings of verbs as programs evolve, even during execution.

    So anyway... a bit of a meandering explanation, but let's get back to Python. Python is not at that outer extreme of semantic black magic. It is somewhere in the middle where the programmer still uses placement, execution order and other imperative/steps-in-series type methods to explain what he wants (for the most part), but also has a large number of ways available to hide complexity behind single words.

    To go from the Python code you write yourself to the machine instructions requires a runtime, though. Because the machine is not capable of being quite as flexible on its own as we want a language like Python to be. For a machine to be that flexible we would have to design a processor that understood the way Python itself works, and that would be really expensive. So instead there are runtimes written in a variety of languages (but the canonical implementation of Python being in good old-fashioned C). Those programs know how to simulate a processor that understands Python, but atop hardware that is something other than that itself. Its sort of a translator.

    The details of bytecode and all that... meh. Don't worry about it. Its really just a very dense version of whatever your program is, and not all Python implementations actually do the bytecode step -- some interpret directly line for line. Some are better at it than others.

    You mentioned assembler. Earlier I mentioned that people realized that it would be nice to be able to wrap up common meanings in human-friendly words rather than remember the binary encodings (which means position and value, both, to convey a meaning) for everything. This is basically what assembler is. It is a (marginally) more friendly way of writing explicit instructions for the processor to follow than entering binary with a toggle switch. In addition to providing wrappers for common meanings, most assembler environments let you do this magic thing where you can pre-define a whole series of things (or even a flexibly definable series of things) by hand, and then call that series of things by a name you make up (macros). Then when the program is converted from sorta-readable assembler to insanely confusing binary strings whatever words you put into your assembler will be in-line replaced with whatever you pre-defined the term to mean. Sort of like variables, but different.

    C is a (huge) step up from assembler, but it doesn't insulate you from the fact that everything stored in binary is actually an integer. So data in C is really all integers, but the C compiler (generally) forces a fiction on you that makes you behave yourself when moving bits around to save you the trouble of crying hard after outsmarting yourself (by, say, trying to multiply a number by a sentence). But compared to languages like Python its a very light wrapper over assembler.

    Python isn't in any way related to assembler, but the underlying C runtime is. When you compile something to native machine code most of the time its a three step process. The initial code is parsed for meaning, and that meaning is converted to a sub-set of C (just the essentials) referred to as C-minus. The C-minus code is still generally readable by humans, but almost never will be, because it is then converted to assembler. The assembler is then converted once more to a huge binary number that means whatever the programmer wrote in the first place (which itself can be a two or three step process -- remember macro expansion?), but would never have had the time to had he actually attempted it in binary to begin with.

    Python code never goes through this step if you're using a Python runtime, because the runtime insulates you from the strict rules of the processor. Instead it is converted to a crunched-down version of whatever you wrote, placed in memory, and then read as a script by the runtime, which takes actions on your behalf within the physical machine you're running your program on.

    Still awake?

    Meh. There are a bajillion books on this. This is my attempt at not boring you but still covering the subject enough that you won't be completely confounded when you try to research this on your own later. If you have time, read the Dragon Book and SICP. SICP is available online for free from MIT and is fascinating.

    But don't let that distract you from your short-term goal -- the Python game! Get this one under your belt before you start fishing in the other waters.
    Last edited by zxq9; July 12th, 2013 at 09:46 PM.
  28. #30
  29. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    27
    Rep Power
    0
    To my disappointment, it seems I've not yet been able to master simple loops...

    My code:

    Code:
    import random
    
    x_win = 0
    user_win = 0
    while x_win < 4 or user_win < 4:
        x = random.randrange(3)
        result = " "
        if x == 0 :
            x = "Rock"
        elif x == 1:
            x = "Paper"
        else:
            x = "Scissors"
    
        user = int (input("Rock, Paper or Scissors?\n\n" "1 is Rock\n2 is Paper\n3 is Scissors\n\n"))
        if user == 1 :
            user = "Rock"
        elif user == 2:
            user = "Paper"
        else:
            user = "Scissors"
    
        if x == user:
            result = "Draw"
            x_win += 0
            user_win += 0
        if x == "Rock" and user == "Paper" or x == "Paper" and user == "Scissors" or x == "Scissors" and user == "Rock":
            result = "You win"
            user_win += 1
        if x == "Rock" and user == "Scissors" or x == "Paper" and user == "Rock" or x == "Scissors" and user == "Paper":
            result = "You loose"
            x_win += 1
        
        print("You chose:", user,"/", "Computer chose:", x, "/", result, "/Score:", user_win, "-", x_win)
    Instructions Given:

    Write a program that plays rock, paper, scissors:

    1. Create a program that randomly prints 0, 1, or 2.

    2. Expand the program so it randomly prints rock, paper, or scissors using if statements. Don't select from a list, as shown in the chapter and don't use functions, we'll cover that later.

    3. Add to the program so it first asks the user their choice.
    - It will be easier if you have them enter 1, 2, or 3.

    4. Add conditional statement to figure out who wins.

    5. Create a loop that will track the running total and repeat the code until either the player, or the computer scores four points.
    My problem is that though i've managed to keep track of the running total of win/losses, the program does not stop looping when the score limit is reached.

    P.S I understand that I could of made the code simpler using functions and lists, but the instructions I was given specifically stated otherwise.

IMN logo majestic logo threadwatch logo seochat tools logo