Binary to Decimal Updated

In my other blog post ‘Binary to Decimal’, I realized what if I had put in a different number than 1 and 0. I tried putting a 2 and the code still worked. So I will be sharing an updated version, so that you can only put in either 1 or 0. Else there will be an error. # make a new function def bintodeci(num): reverse = len(num) -1 exp = 0 total = 0 for index in range(reverse, -1, -1): # if each number is either 0 or 1 else it'll print out an error. if num[index] in '01': total += int(num[index]) * (2**exp) exp += 1 else: print("Error: Invalid binary number") return None # return the value return total # In case I want to import it if __name__ == '__main__': print(f'The variable __name__ is {__name__}') answer = bintodeci("111") print(answer)

January 28, 2025 · 1 min · SourFox

Recursive function

Hi, today I’m sharing a recursive funtion in python. Recursive in python means the ‘def’ function to call itself. The goal is to sum up the numbers to the number I want. For example, if I put in 3: 1 + 2 + 3 = 6 # def = makes a new function def sum(num): # if we have an 'if', we should also have an 'else'. if num == 0: return 0 else: return sum(num - 1) + num print(sum(2)) Outcome: ...

January 27, 2025 · 1 min · SourFox

Binary to Decimal

I’m sharing a program that converts binary to decimal in python. # make a new function def bintodeci(num): reverse = len(num) -1 exp = 0 total = 0 # range(start, stop, step) for digit in range(reverse, -1, -1): total += int(num[digit]) * (2**exp) exp += 1 # return the value return total answer = bintodeci("11") print(answer) sample output: 10 bai.

January 23, 2025 · 1 min · SourFox

Create Restic Backup Program

I’m sharing a wrapper program written in python to backup my files in my device using restic. import subprocess restic_command = ['restic', 'backup'] backup = ["C:\\Users\\veronica\\ibisPaint", "C:\\Users\\veronica\\Pictures", "C:\\Users\\veronica\\Documents"] print("List of directories to be backed up:\n" ) #list the files that will be backed up. #enumerate = allows you to keep track of the number of iterations in a loop. for number, dir in enumerate(backup, start=1): print(f" {number}. {dir}") # Or: print(" " + str(number) + ".", letter ) # \n makes a new line print("\nBackup process started...\n") # combines the lists together. backup_command = restic_command + backup restic = subprocess.run(backup_command, shell=True) The end. -w- ...

December 30, 2024 · 1 min · SourFox

Create a new user account on Linus Server Take 2

Hallooo peeps! Last time, I made a new user on Linux but in this one, instead of just making a new user, I’ll alo be adding a name for the user and add it into the ‘wheel’ group. Here are the requirements: Username: cooldonkey Password: awesomedonkey24 Name of account: “Donkey” Group: ‘cooldonkey’, ‘wheel’ (wheel group allows a user to run sudo command) The first thing I’ll do is making the user so we’ll use the sudo useradd. But instead of just using useradd, I’ll also add in an option called –comment (-c). This will let me do number 3. Add a name for the user. ...

November 16, 2024 · 1 min · SourFox