๐Python Basics
Using a web-based code editor, learn the basics of Python and put your knowledge into practice by eventually coding a short Bitcoin investment project.
Room Attributes | Value |
---|---|
Subscription Required | False [Free] |
Type | Walkthrough |
Difficulty | Info |
Tags | Python, Programming, Bitcoin |
Task 1 - Introduction to Python
Run what's currently in the code editor by clicking the green "Run Code" button (on the right-hand side of your screen), and move onto the next task.
No answer needed
Task 2 - Hello World
On the code editor, print "Hello World". What is the flag?
HINT: In the code editor (right-hand side), replace "Learn security with TryHackMe" with "Hello World" and click the green run code button.
Task 3 - Mathematical Operators
In the code editor, print the result of 21 + 43. What is the flag?
HINT: In the code editor on the right, write the following: print(21 + 43)
Print the result of 142 - 52. What is the flag?
Print the result of 10 * 342. What is the flag?
Print the result of 5 squared. What is the flag?
HINT: 5 ** 2
Task 4 - Variables and Data Types
In the code editor, create a variable called height and set its initial value to 200.
No answer needed
On a new line, add 50 to the height variable.
No answer needed
On another new line, print out the value of height. What is the flag that appears?
Task 5 - Logical and Boolean Operators
Read the above section.
No answer needed
Task 6 - Shipping Project Introduction to If Statements
In this exercise, we will code a small application that calculates and outputs the shipping cost for a customer based on how much they've spent. In the code editor, click on the "shipping.py
" tab and follow the instructions to complete this task.
shipping.py
" tab and follow the instructions to complete this task.No answer needed
Once you've written the application in the code editor's shipping.py
tab, a flag will appear, which is the answer to this question.
shipping.py
tab, a flag will appear, which is the answer to this question.HINT: Need a hint? On the code editor, to the left of the "Run Code" button, there will be a hint button to help you get started.
In shipping.py
, on line 12 (when using the Code Editor's Hint), change the customer_basket_cost
variable to 101 and re-run your code. You will get a flag (if the total cost is correct based on your code); the flag is the answer to this question.
shipping.py
, on line 12 (when using the Code Editor's Hint), change the customer_basket_cost
variable to 101 and re-run your code. You will get a flag (if the total cost is correct based on your code); the flag is the answer to this question.Task 7 - Loops
On the code editor, click back on the "script.py
" tab and code a loop that outputs every number from 0 to 50.
script.py
" tab and code a loop that outputs every number from 0 to 50.HINT: You can use a for loop or while loop, but it must print from 0 to 50.
Task 8 - Bitcoin Project Introduction to Functions
Once you've written the bitcoinToUSD function, use it to calculate the value of your Bitcoin in USD, and then create an if statement to determine if the value falls below $30,000; if it does, output a message to alert you (via a print statement).
HINT: Make sure your Python function has the name bitcoinToUSD
and uses the parameter names bitcoin_amount
and bitcoin_value_usd
.
1 Bitcoin is now worth $25,000. In the code editor on line 14, update the bitcoin_to_usd
variable value to 25000 and see if your Python program recognises that your investment is below the $30,000 threshold.
bitcoin_to_usd
variable value to 25000 and see if your Python program recognises that your investment is below the $30,000 threshold.No answer needed
Task 9 - Files
In the code editor, write Python code to read the flag.txt file. What is the flag in this file?
Task 10 - Imports
Read the task and run the Python example code above in the code editor on the right.
No answer needed
Last updated