Google Colab
This is the new way to get a Python environment in the cloud, including an AI to help write your code.In a browser, go to
https://colab.research.google.com/If you see a blue "Sign In" button at the top right, click it and log into a Google account.From the menu, click File, "New notebook".
a = 10
b = 20
print("a:", a, "b:", b)
# Add and subtract
added = a + b
subtracted = a - b
print("Added:", added, "Subtracted:", subtracted)
The results show the expected values,
as shown below.
a = 10
b = 20
print("a:", a, "b:", b)
# Multiplying and Dividing
multiplied = a * b
divided = a / b
print("Multiplied:", multiplied, "Divided:", divided)
The results show the expected values,
as shown below.
import math
a = 2
b = 4
print("a:", a, "b:", b)
# Exponentiation and Logarithm
exponentiation = a ** b
log_a = math.log(a, 2)
log_b = math.log(b, 2)
print("a ** b:", exponentiation)
print("log(a, 2):", log_a)
print("log(b, 2):", log_b)
The results show the expected values,
as shown below.
a = 7
b = 24
print("a:", a, "b:", b)
# Binary and Hex
bin_a = bin(a)
bin_b = bin(b)
hex_a = hex(a)
hex_b = hex(b)
print("In binary, a:", bin_a, "b:", bin_b)
print("In hex, a:", hex_a, "b:", hex_b)
The results show the expected values,
as shown below.
But if they are strings, the "int" function is needed to perform the conversion.
Execute this code:
a = 0xf0
b = 0b11011
print("a:", a, "b:", b)
c = "ff"
d = "11101"
print("c:", c, "d:", d)
# Converting to Decimal
dec_c = int(c, 16)
dec_d = int(d, 2)
print("In Decimal, c:", dec_c, "d:", dec_d)
The results show the expected values,
as shown below.
Flag VP 20.1: Arithmetic (5 pts)
Start with two numbers:a: 22Now perform these operations in order:
b: 45The flag is the answer, covered by a green rectangle in the image below.
- Multiply a by b
- Add 108
- Divide by 9
- Subtract 14
Flag VP 20.2: Math (5 pts)
Start with two numbers:a: 25Now perform these operations in order:
b: 9The flag is the answer, covered by a green rectangle in the image below.
- Raise a to the power b
- Divide by 625 (use two slashes, as shown below, to make the result an integer)
- Subtract 300
- Display the result in hexadecimal
Flag VP 20.3: Log (5 pts extra)
Start with two numbers:a: 32Now perform these operations in order:
b: 8The flag is the answer, covered by a green rectangle in the image below.
- Raise a to the power b
- Divide by 50
- Subtract 3000
- Find the log to the base 2 of the result
Flag VP 20.4: Octal (10 pts extra)
Start with two numbers:a: 35Now perform these operations in order:
b: 4If you aren't familiar with the octal system, use a search engine to find a page explaining it and how to use it in Python.
- Raise a to the power b
- Divide by 5 (make sure the result is an integer)
- Subtract 200
- Express the result in octal
The flag is the answer, covered by a green rectangle in the image below.
Flag VP 20.5: Find the Pair (15 pts extra)
Start with these numbers:Find two numbers in that list that sum to 2085.[7419,162,1140,4737,6266,1248,7347,3580,7103,7577,2697,69,4881, 3013,1178,418,6740,8615,1923,5134,4128,586,483,6930,2445,7541, 2936,5390,9482,384,4850,3708,5583,8292,67,6003,7744,7918,7737, 8996,146,3204,7937,2063,9031,1060,9127,387,9304,6360]Multiply those two numbers together. The flag is that product.
Flag VP 20.6: Find the Triplet (15 pts extra)
Start with the numbers in this file:https://samsclass.info/COMSC132/proj/VP20a
Find three numbers in that list that sum to 2085.Multiply those three numbers together. The flag is that product.