Python
Python
Hello World
- On the code editor, print "Hello World". What is the flag?
THM{PRINT_STATEMENTS
Mathematical Operators
print(21+43)print(142-52)print(10*342)print(5**2)- In the code editor, print the result of 21 + 43. What is the flag?
THM{ADDITI0N}
- Print the result of 142 - 52. What is the flag?
THM{SUBTRCT}
- Print the result of 10 * 342. What is the flag?
THM{MULTIPLICATION_PYTHON}
- Print the result of 5 squared. What is the flag?
THM{EXP0N3NT_POWER}
Variables and Data Types
height = 200
height = height + 50
print(height)- On another new line, print out the value of height. What is the flag that appears?
THM{VARIABL3S}
Logical and Boolean Operators
Introduction to If Statements
chall
"""
In this project, you'll create a program that calculates the total
cost of a customers shopping basket, including shipping.
- If a customer spends over $100, they get free shipping
- If a customer spends < $100, the shipping cost is $1.20 per kg of the baskets weight
Print the customers total basket cost (including shipping) to complete this exercise.
"""
customer_basket_cost = 34
customer_basket_weight = 44
# Write if statement here to calculate the total costsolution
disini toal belanja nya adalah 34 dolar, dengan berat 44 kg. Karena total belanjaan kurang dari 100 dolar, maka dikenakan ongkos kirim 1.20 dolar per kg.
total_cost = 0
if customer_basket_cost > 100:
total_cost = customer_basket_cost
else:
shipping_cost = customer_basket_weight * 1.20
total_cost = customer_basket_cost + shipping_cost
print(total_cost)- 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.
- 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.
THM{IF_STATEMENT_SHOPPING}
customer_basket_cost = 101
customer_basket_weight = 44
price_per_kg = 1.20
total_cost = 0
if customer_basket_cost > 100:
total_cost = customer_basket_cost
else:
shipping_cost = customer_basket_weight * price_per_kg
total_cost = customer_basket_cost + shipping_cost
print(total_cost)- In shipping.py, on line 15 (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.
THM{MY_FIRST_APP}
Loops
for i in range(51):
print(i)- On the code editor, click back on the "script.py" tab and code a loop that outputs every number from 0 to 50.
- You can use a for loop or while loop, but it must print from 0 to 50.
THM{L00PS_WHILE_FOR}
Introduction to Functions
You've invested in Bitcoin and want to write a program that tells you when the value of Bitcoin falls below a particular value in dollars.
In the code editor, click on the bitcoin.py tab. Write a function called bitcoinToUSD with two parameters: bitcoin_amount, the amount of Bitcoin you own, and bitcoin_value_usd, the value of bitcoin in USD. The function should return usd_value, which is your bitcoin value in USD (to calculate this, in the function, you times bitcoin_amount variable by bitcoin_value_usd variable and return the value). The start of the function should look like this:
def bitcoinToUSD(bitcoin_amount, bitcoin_value_usd):chall
"""
In this project, you'll create a program that that tells
you when the value of your Bitcoin falls below $30,000.
You will need to:
- Create a function to convert Bitcoin to USD
- If your Bitcoin falls below $30,000, print a message.
You can assume that 1 Bitcoin is worth $40,000
"""
investment_in_bitcoin = 1.2
bitcoin_to_usd = 40000
# 1) write a function to calculate bitcoin to usd
# 2) use function to calculate if the investment is below $30,000
# 2) use function to calculate if its below $30,000solution
def bitcoinToUSD(bitcoin_amount, bitcoin_value_usd):
return bitcoin_amount * bitcoin_value_usd
investment_in_usd = bitcoinToUSD(investment_in_bitcoin, bitcoin_to_usd)
if investment_in_usd <= 30000:
print("Investment below $30,000! SELL!")
else:
print("Investment above $30,000")- 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).
- Make sure your Python function has the name bitcoinToUSD and uses the parameter names bitcoin_amount and bitcoin_value_usd.
THM{BITC0IN_INVESTOR}
- 1 Bitcoin is now worth $24,000. In the code editor on line 14, update the bitcoin_to_usd variable value to 24000 and see if your Python program recognises that your investment is below the $30,000 threshold.
Files
f = open("flag.txt", "r")
print(f.read())
# THM{F1LE_R3AD}- In the code editor, write Python code to read the flag.txt file. What is the flag in this file?
THM{F1LE_R3AD}
Imports
import datetime
current_time = datetime.datetime.now()
print(current_time)
# 2026-01-18 16:28:51.367800