# Python Basics

{% embed url="<https://tryhackme.com/room/pythonbasics>" %}
<https://tryhackme.com/room/pythonbasics>
{% endembed %}

| Room Attributes       | Value                                                                  |
| --------------------- | ---------------------------------------------------------------------- |
| Subscription Required | <mark style="color:green;background-color:green;">False</mark> \[Free] |
| Type                  | Walkthrough                                                            |
| Difficulty            | <mark style="color:blue;background-color:blue;">Info</mark>            |
| 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.

{% hint style="success" %}
No answer needed
{% endhint %}

## Task 2 - Hello World

### On the code editor, print "Hello World". What is the flag?

{% hint style="warning" %}
**HINT:** In the code editor (right-hand side), replace "Learn security with TryHackMe" with "Hello World" and click the green run code button.
{% endhint %}

<details>

<summary>Reveal Flag <span data-gb-custom-inline data-tag="emoji" data-code="1f6a9">🚩</span></summary>

:triangular\_flag\_on\_post:`THM{PRINT_STATEMENTS}`

</details>

## Task 3 - Mathematical Operators

### In the code editor, print the result of 21 + 43. What is the flag?

{% hint style="warning" %}
**HINT:** In the code editor on the right, write the following: print(21 + 43)
{% endhint %}

<details>

<summary>Reveal Flag <span data-gb-custom-inline data-tag="emoji" data-code="1f6a9">🚩</span></summary>

:triangular\_flag\_on\_post:`THM{PRINT_STATEMENTS}`

</details>

### Print the result of 142 - 52. What is the flag?

<details>

<summary>Reveal Flag <span data-gb-custom-inline data-tag="emoji" data-code="1f6a9">🚩</span></summary>

:triangular\_flag\_on\_post:`THM{SUBTRCT}`

</details>

### Print the result of 10 \* 342. What is the flag?

<details>

<summary>Reveal Flag <span data-gb-custom-inline data-tag="emoji" data-code="1f6a9">🚩</span></summary>

:triangular\_flag\_on\_post:`THM{MULTIPLICATION_PYTHON}`

</details>

### Print the result of 5 squared. What is the flag?

{% hint style="warning" %}
**HINT:** 5 \*\* 2
{% endhint %}

<details>

<summary>Reveal Flag <span data-gb-custom-inline data-tag="emoji" data-code="1f6a9">🚩</span></summary>

:triangular\_flag\_on\_post:`THM{EXP0N3NT_POWER}`

</details>

## Task 4 - Variables and Data Types

### In the code editor, create a variable called height and set its initial value to 200.

{% hint style="success" %}
No answer needed
{% endhint %}

### On a new line, add 50 to the height variable.

{% hint style="success" %}
No answer needed
{% endhint %}

### On another new line, print out the value of height. What is the flag that appears?

<details>

<summary>Reveal Flag <span data-gb-custom-inline data-tag="emoji" data-code="1f6a9">🚩</span></summary>

:triangular\_flag\_on\_post:`THM{VARIABL3S}`

</details>

## Task 5 - Logical and Boolean Operators

### Read the above section.

{% hint style="success" %}
No answer needed
{% endhint %}

## Task 6 - <mark style="color:green;background-color:green;">Shipping Project</mark> 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.

{% hint style="success" %}
No answer needed
{% endhint %}

### 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.

{% hint style="warning" %}
**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.
{% endhint %}

<details>

<summary>Reveal Flag <span data-gb-custom-inline data-tag="emoji" data-code="1f6a9">🚩</span></summary>

:triangular\_flag\_on\_post:`THM{IF_STATEMENT_SHOPPING}`

</details>

### 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.

<details>

<summary>Reveal Flag <span data-gb-custom-inline data-tag="emoji" data-code="1f6a9">🚩</span></summary>

:triangular\_flag\_on\_post:`THM{MY_FIRST_APP}`

</details>

## 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.

{% hint style="warning" %}
**HINT:** You can use a for loop or while loop, but it must print from 0 to 50.
{% endhint %}

<details>

<summary>Reveal Flag <span data-gb-custom-inline data-tag="emoji" data-code="1f6a9">🚩</span></summary>

:triangular\_flag\_on\_post:`THM{L00PS_WHILE_FOR}`

</details>

## Task 8 - <mark style="color:green;background-color:green;">Bitcoin Project</mark> 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 style="warning" %}
**HINT:** Make sure your Python function has the name `bitcoinToUSD` and uses the parameter names `bitcoin_amount` and `bitcoin_value_usd`.
{% endhint %}

<details>

<summary>Reveal Flag <span data-gb-custom-inline data-tag="emoji" data-code="1f6a9">🚩</span></summary>

:triangular\_flag\_on\_post:`THM{BITC0IN_INVESTOR}`

</details>

### 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.

{% hint style="success" %}
No answer needed
{% endhint %}

## Task 9 - Files

### In the code editor, write Python code to read the flag.txt file. What is the flag in this file?

<details>

<summary>Reveal Flag <span data-gb-custom-inline data-tag="emoji" data-code="1f6a9">🚩</span></summary>

:triangular\_flag\_on\_post:`THM{F1LE_R3AD}`

</details>

## Task 10 - Imports

### Read the task and run the Python example code above in the code editor on the right.

{% hint style="success" %}
No answer needed
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://thmflags.gitbook.io/thm-walkthroughs/difficulty-info/python-basics.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
