Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Python Basics Types and Branching Comparisons

Andrei Musat
Andrei Musat
738 Points

What I wanted to ask is... How do I integrate all this new information when I actually have to write code?

Let's say we are pretty far immersed in the course and I want to use the knowledge I've received throughout the course. How do I actually integrate that knowledge so that I can write a usable program ?

5 Answers

Nicci Carlton
Nicci Carlton
809 Points

I think like the learning of any new language it all depends on you actually attempting to "think" in that language and then "voice" it outside your brain. When you learn French or Turkish you start with very basic sentence structures, and you repeat them over and over, gradually you add more words, more modifiers, verb conjugation etc. Treehouse is teaching the same way - worrying about how you are going to code an entire program at the start of this journey will just add anxiety to the learning.

I find for myself that my real learning (the stuff that sticks) comes with applied usage, understanding how to communicate in this new language. So I force myself to "create" my own lessons. On treehouse at the end of a section, I use the REPEL, create a new file and come up with my own scenario using the stuff I learned before as well as the new knowledge to write a code to solve (though not eloquently yet) a real world/work problem, usually making it more and more complicated. There are also lots of sites to help practice your new skills, like practicepython, edabit, hackerrank etc

Good luck! .

mouseandweb
mouseandweb
13,758 Points

with the knowledge you've gained so far in the Python track you will be able to create a paycheck calculator. That's the first thing I made at this point. I had to make use of variables, float(), input(), int(), using mathematics operations * / + and - as well as Order of Operations, if/else conditional statement, and print().

I use this program that I created in my computer terminal. When I open the .py I will be prompted to enter the hours I worked, the rate of pay, and what the income tax is. I could have included some things in the code, like taxes, but I wanted to keep it as an input. Same goes for the hourly.

I hope this answers your question. Please feel free to reach out if you have more questions.

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 91,253 Points

I'm not sure how you mean integrate!

But in all honesty, the based way to learn and remember code and how it all works together is I'm afraid just to make a real-world project. Understanding program flow is part of it but the more you code the more you immerse yourself into what it's like to create a production app or program.

Szymon Dabrowski
Szymon Dabrowski
2,207 Points

I guess with all this basic knowledge we gained one thing that comes to my mind that you could write a program about and, use it in a real-world example is a calculator that will convert kilograms into grams and other measurements like pounds etc.

So for example: if you are a butcher and a customer asks you for <random number> pounds of beef but your weight scale only shows kilograms. You have no idea how much that would be in pounds :( . You could use this calculator to sell your customer the correct amount of beef.

So first we need to ask the question in our program so we can find out how many pounds of beef the customer wants:

pounds = int(input("How many pounds of Beef does the customer want?  ")) 

remember that string cannot be calculated with other numbers so we put int (before input to make sure the number will be converted to an integer to avoid errors).

Then we google what the conversion is between pound to kg. Let's assume that 1 kilogram is 0.4 of a pound. With this information, we can make a formula:

kilogram = pounds * 0.4 

this is our calculator. A very simple version.

Then after we ask how many pounds we need to convert to kilograms we also need to find out how many kilograms we need to sell to the customer so we need to now print the result to find out:

print("Please sell" ,"{:.2f}".format(kilogram),"KG of beef to customer")

So as we know with decimal points on floats sometimes we have a weird number like 9.20000000000001 let's say and we really only care to round our floats to 2 decimal places. I have used the {} placeholder to then format our kilogram value to only ever show the first 2 decimal points and added some texts around it to display a message that a human can understand. Also if you have an idea of implementing something in your code but you don't know how just google it and you will probably find an answer.

Whole Code:

#Weight converter
pounds = int(input("How many pounds of Beef does the customer want?  "))
kilogram = pounds * 0.4
print("Please sell" ,"{:.2f}".format(kilogram),"KG of beef to the customer.")
Example: 
How many pounds of Beef does the customer want?  Answer: 3                                                                                                                                      
Please sell 1.20 KG of beef to the customer.

After this, you can pretty much do anything you want with it. Be creative. The butchers don't just sell beef. You can add many different types of meat or products. convert much different weight by asking the right questions and using if elif else statements and even adding a pricing tool if you really wanted to also display how much the customer should be charged in a currency etc. The power is yours.

I am a beginner myself trying to learn to code but I hope I helped out just a tiny bit at least with your question.

Szymon Dabrowski
Szymon Dabrowski
2,207 Points

Some of the formatting went wrong but I hope this makes sense D:

Jonathan Grieve
Jonathan Grieve
Treehouse Moderator 91,253 Points

I helped fix up the formatting for you. You can use Markdown in the forums to help you write code in the forums in the future with the Markdown Cheatsheet, or see Treehouse's course on Markdown. :)

Im sure if you gave more information by what you mean. we would be able to assist you better