Jump to content
  • Advertisement
Sign in to follow this  
  • entries
    7
  • comments
    2
  • views
    963

my 2nd program in python

Sign in to follow this  
WinterDragon

439 views

tip15 = 0
tip20 = 0
price = input ("how much did your meal cost?")
tip15 = int (price) * .15
tip20 = int (price) * .2
print ("A 20% tip would be ",tip20," and a 15% tip would be",tip15)
input ()

I wrote a tipper program for an exercise.
It's a simple program and it took 20mins to write including several bug fixes,
where I had to go back to looking through the textbook and a few glances at my first program,
before I got it running properly. I made the usual noob mistakes - since I've tackled many different languages, I had to figure out if I needed to declare variables.
I also got the variable on the wrong side of the equals sign, then I forgot to include commas in my print statement for the variables. I also forgot to state that the variable was an integer. Finally, I forgot to use brackets and then incorrectly included the calculation inside the brackets.
Eventually, I figured all of this out and came up with the above seemingly simple program.
And it works!

I'm still not using comments, but I'll fix that when I start writing longer programs.

Sign in to follow this  


0 Comments


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement
  • Advertisement
  • Blog Entries

  • Similar Content

    • By markypooch
      Hello all,
      essentially what I'm looking for is a flowchart generator that I can leverage with my python applications using, "magic characters" (@) and the like, above flow control structures, and important bits of code. While there does seem to exist some similar libraries in the py eco system, there doesn't seem to be anything 1:1 to what I'm looking for, I've heard of Doxygen, but i'd prefer something native to Python. 
      Really just something that gives my engineers minimal control of the output of what the flowchart will look like in the most minimally invasive way possible. Also, I know the process for flowcharting is backwards in this proposition, but this is more for management after the fact. 
      If something exists, great! If not, I'll code it out, but don't want to duplicate efforts if something similar is already out there
      Marcus
    • By jyscal
      Hello
      I am trying to create a grid of images in pyglet and python and I am not sure where exactly I am going wrong.
      The goal is for it to be a Breakout/Arkanoid clone. The problem I am having is getting the brick images to display in a grid.
      Here is the code that as far as I can tell, should place the bricks in the correct position.
       
      class Brick(): def __init__(self, space): # Create the list to hold different sprite bricks and load images self.batch = pyglet.graphics.Batch() self.brick_images = ['brick1.png', 'brick2.png'] self.brick_sprites = [] # 1 out of 5 chance to drop a power pill self.chance_to_drop = 1 # Set the images anchor point to its center and create sprites for i in range(len(self.brick_images)): img = pyglet.image.load(self.brick_images[i]) img.anchor_x = img.width // 2 img.anchor_y = img.height // 2 self.brick_sprites.append(pyglet.sprite.Sprite(img)) for x in range(7): for y in range(7): self.body = pymunk.Body(body_type=pymunk.Body.KINEMATIC) # The position where each pymunk body will be placed self.body.position = x * 100 + 75, y * 30 + 340 self.brick_type = random.randint(0, len(self.brick_sprites) - 1) if self.brick_type == 0: sprite = self.brick_sprites[0] # Set the sprite to the same position as the pymunk body sprite.set_position(self.body.position.x, self.body.position.y) sprite.batch = self.batch elif self.brick_type == 1: sprite = self.brick_sprites[1] sprite.set_position(self.body.position.x, self.body.position.y) sprite.batch = self.batch self.shape = pymunk.Segment(self.body, (0, 0), (50, 0), 6) self.shape.elasticity = 0.80 self.shape.collision_type = collision_types['brick'] space.add(self.body, self.shape) handler = space.add_collision_handler(collision_types['brick'], collision_types['ball']) handler.separate = self.remove_brick  
      So what I am trying to accomplish is have 7 rows of 7 bricks. As far as I can see the sprites are being created in the loop, but when I run the program only 2 bricks are being displayed. I am sure there is something wrong with the way I am looping but honestly just cannot see where I am going wrong. I have spent some time, trying to see the error but simply cannot see where I am going wrong.
      I can see that the pyglet brick sprites are NOT being set to the correct x, y of the pymunk body, even though, using the same formula for the player paddle object lines up the sprite perfectly.
       
      #Set the sprite to pymunk object position self.image = pyglet.image.load('paddle.png') self.image.anchor_x = self.image.width // 2 self.image.anchor_y = self.image.height // 2 self.sprite = pyglet.sprite.Sprite(self.image, x=self.position.x, y=self.position.y)  
      I am very confused with this one and I just hope I have explained everything clearly enough. Thank you for any help or assistance in any way.
    • By monkeypuffin
      Hi, 
      I have an online multiplayer RPG maze game which I built in NodeJS. It is quite simple. Uses socket.io. Single threaded application so I don't have to worry about race conditions such as two users attempting to take the same object at the same time. The client sends in messages, which are processed by the gameserver and alter the player/world state, query the MySQL database, and broadcasting messages to all the other players and also updating things in the MySQL database.
      In the last month I have been learning python and I would like to port my game to Python as I think it will be better suited. Doing some research I have found many suggest using Twisted Python so this is the route I am going to take. 
      I wondered if anyone could give me some suggestions for a basic framework of how I would handle the problem of race conditions when moving to an environment where things are operating in parallel, especially with regard the querying and updating of the state in the MySQL. 
      If at all possible I wondered if there are any open source implementations of an MMO architecture using Twisted Python that I could look through that dealt with these issues.  
      Thank you for your time reading this
          
    • By WinterDragon
      I want to make some games. My question is what should my first steps be, besides learning more python and unity2d?
      I'm hoping I haven't asked this before.
      I thought my first step was conquering enough of unity and python so I can start making small games.
      I don't know enough python to build a text-based adventure game just yet.
      I haven't really started with unity 2d yet.
      I want to make 4 games:
      1)  a survival game set in a bubble in New Zealand
      2) an rpg battle game about differently-shaped spaceships protecting their resources
      3) a hustling game influenced by land of Illusion: starring mickey mouse graphics and hell's kitchen ds mechanics
      4) an end of the world game where you play god and mutate heroes to fight the ultimate evil supervillain
       
      Other games which are major influences include: 8bitMMO, Another World, Discworld 2, Clop, Osmos, Hacker Evolution: Untold, the sims 1, close combat 1, MTGO, Limbo, Doug TenNapel games, Lemmings, Freedom Force, Gain Ground, Gynoug, Joust, Robocop Vs The Terminator, Ecco: the Dolphin, Super Meat Boy and Syphon Filter 1.
       
      Also does anyone have tips about marketing, or should I not worry until I have an early build?
    • By WinterDragon
      I'm trying to find/figure out where in a loop, before the loop, after the loop, the computer understands time.
      As I have created a loop and I need to put a time-limit on an input.
      lost my program, so I'll adapt the following to a guessing game from a coin flip. Then I need to insert a time counter, just need to understand where to put it?
       
      import random
      def variables ():
          heads = 0
          tails = 0
          coinCount = 0
          againPlay = "y"
         
      def game():
          heads = 0
          tails = 0
          againPlay = "y"
          coinCount = 1
          while coinCount > 0:
              if againPlay != "y":
                  print ("you had ", heads, "heads.")
                  print (" and ", tails, "tails.")
                  end = input ("You're all done now!")
              nmCoin = random.randrange(2)
              if coinCount > 100: againPlay = "n"
              if nmCoin == 1:
                 heads = heads + 1
                 coinCount = coinCount + 1
              elif nmCoin == 0:
                 tails = tails + 1
                 coinCount = coinCount + 1
              else:
                  print ("you had ", heads, "heads.")
                  print (" and ", tails, "tails.")
                  end = input ("You're all done now!")
          
      variables ()
      game ()
       
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!