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

an early coding exercise 1

Sign in to follow this  
WinterDragon

657 views

4337f-python-5.jpg?w=300

carPrice = input ("what is the base price of the car?")

tax = int (carPrice) * .125
insurance = 250
totalcarPrice = int (carPrice) + int (insurance) + int (tax)

print ("total cost of your car including: insurance $",insurance,",")
print ("and tax: $",tax," comes to $",totalcarPrice)
input ()

 
This is a program that figures out all your extra costs, when buying a car.
The only mistake I still need to figure out, is what the escape clause is for avoiding having a space at the end of a statement inside a print function.
 
It works fine, the user enters the base cost for the car.
Program calculates the tax and adds a previously decided insurance cost.

Then the program provides the user with both the individual costs, and the total all-inclusive price of the car.

EDIT:
After some research not in-book, it turns out that you can avoid the white spaces in between statements by using the function sep = "", which should be treated as a variable - so not inside the quotation marks of the print function, rather, naked inside the brackets.

So the final program now looks like this:

carPrice = input ("what is the base price of the car?")

tax = int (carPrice) * .125
insurance = 250
totalcarPrice = int (carPrice) + int (insurance) + int (tax)

print ("total cost of your car including: insurance $",insurance,",", sep = "")
print ("and tax: $",tax," comes to $",totalcarPrice, sep = "")

 
input ()
Sign in to follow this  


2 Comments


Recommended Comments

An alternative is to use format():

print("and tax: ${} comes to ${}".format(tax, totalcarPrice))

Write the string as you want it, with "{}" at places where you want a number. Then add ".format(<values>)" behind the string. The format method creates a new string from your template by finding each "{}", and replacing it by a value listed in the format arguments.

Format can do more, but this will suffice at first

Share this comment


Link to comment

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 TheAICodeGuy
      Hello everyone!
      If you couldn't figure it out I'm new here. I've been reviewing jobs regarding AI game programming because I love working on AI systems. A few searches have been well straight forward and I'm grateful for that, but for anybody whose has or who still is currently working as an AI programmer, what skills would you say are necessary? I've learned (and still am learning because well learning and getting BETTER never ends) C and C++. Of course I'll continue to sharpen my skills there as much as possible. I've seen some jobs list python and/or lua in their descriptions. Would you say these extra skills are, I guess, major in the game industry? I know python a bit, but lua I don't really know much at all. 
      However I'm most definitely willing to learn.
      Thank you to anyone willing to give feedback!
    • By kalydos
      Currently I have two creative talents with me on board to work with me for my visual novel dating sim and we are currently looking for a programmer to work with in Ren'py (or another program if that works), minimal pixel art and it would require being able to contribute creatively as well as programming a stat/leveling system, affection system, calendar/scheduling activities system, a minimal sidescrolling exploration system and it would also be nice to have a GUI designer. If any clarification or anyone is on board contact me on discord kalydos#0726
    • By renedudfield
      The pygame book project has begun. It's called "pygame 4000" and is a book project by one of the main contributors of the pygame project.

      Not only does the book aim to cover Python programming, but also aims to cover C, and the GLSL shading language.
      [ Pixel Perfect Collision Detection ] [ SDL2 Fundamentals Tutorial in C ] [ Sound Generation and Visualization ] [ Python intro for game programming ] [ Let's make a shit JavaScript Interpreter! ] [ How to port and market games ] [ Let's write a unit test! ] [ Arduino; Serial & pixels for breakfast ] [ Awesome pygame. Great stuff you can use with pygame. ] pygame 4000 available as an early preview pre-release on the pygame book itch page. Updates will be posted on the pygame book developer web log.
      pygame is the most popular game/art/and music library available for the most popular programming language in the world -- Python. pygame is used in school classes, university courses, and workshops around the world. It's used in embedded devices like handheld game consoles, in video synthesizers, museum displays, and interactive art installations. It's available in over 130 different OS distributions, including on the Raspberry Pi, Ubuntu, and MacOS. All funds from the pygame 4000 book go towards pygame development and improvements to the pygame 4000 book.

      View full story
    • By renedudfield
      The pygame book project has begun. It's called "pygame 4000" and is a book project by one of the main contributors of the pygame project.

      Not only does the book aim to cover Python programming, but also aims to cover C, and the GLSL shading language.
      [ Pixel Perfect Collision Detection ] [ SDL2 Fundamentals Tutorial in C ] [ Sound Generation and Visualization ] [ Python intro for game programming ] [ Let's make a shit JavaScript Interpreter! ] [ How to port and market games ] [ Let's write a unit test! ] [ Arduino; Serial & pixels for breakfast ] [ Awesome pygame. Great stuff you can use with pygame. ] pygame 4000 available as an early preview pre-release on the pygame book itch page. Updates will be posted on the pygame book developer web log.
      pygame is the most popular game/art/and music library available for the most popular programming language in the world -- Python. pygame is used in school classes, university courses, and workshops around the world. It's used in embedded devices like handheld game consoles, in video synthesizers, museum displays, and interactive art installations. It's available in over 130 different OS distributions, including on the Raspberry Pi, Ubuntu, and MacOS. All funds from the pygame 4000 book go towards pygame development and improvements to the pygame 4000 book.
    • By Gomta777
      Hello, I am a Japanese, a novice of the python programming.
      I am currently trying to program games using pygame.
      The progress of the game production can be seen on the following blog and youtube channel.
      https://ko-gaku-jiji.hatenablog.jp/
      (sorry all of my page is written by Japanese)

      I'm trying to make a Tetris-like game right now, but sometimes I'm worried.
      In the process for the Tetris game, such as the process of line erasing, I feel that I can write a program more simply by using multithreading.
      However, I couldn't find a suitable sample for multithreading with pygame.
      If you know, please introduce me a web page with a simple and easy-to-understand sample.
  • Advertisement
×

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!