Posts

Discord bot using discord.py

Image
 Discord is a VOIP and text messaging application that many people use. It has the ability to create 'servers', where text channels and voice channels can be create so people can communicate using it. A bot can be made for Discord, using a multitude of languages including python, so I decided to have a shot at it. Most of it is simple, as python and discord do all the bot stuff for you, you just have to make the commands. So I made some simple commands, such as 8ball question and answer, coinflip, deleting a number of messages, sending private messages to specific users. Then I made 2 bigger programs, which take a group of people and assigns each person another person without repeats, which is useful for some games and/or something like secret santa. Then I made a team organizer, which puts a group of people into a given number of teams. I also allowed it to join VC and leave it, for the purpose of it trying to play music. However, most of the tutorials I've watched on it i...

Binary subtraction

 Computer subtract two numbers by using a trick called two's complement. For example, if you wanted to do A - B with A and B as binary integers, what computer actually do is A + F(B) + 1, with F() being a function that handles two's complement. Two's complement works by reversing the digits of the binary number. If A = 1101011, and B = 101, first of all, you make B the same length as A by putting 0s in the front, B = 0000101. Then, you reverse the digits, so that F(B) = 1111010. Then you add one to F(B),  B = 1111011. Then you add those two numbers together, and ignore the left-most digit. A + F(B) + 1 = 1 1100110. This leaves us with 1100110, which should be equal to A - B: 1101011 = 107 101 = 5 1100110 = 102  107 - 5 = 102 number = input ( "Enter your binary digit: " ) array = [] for x in range ( 0 , len (number)): if number[x] == "1" : array.append( 0 ) elif number[x] == "0" : array.append( 1 ) number = input ( "...

Nim game

 The nim game requires 2 players, and 20 stones. The players take turns removing 1 to 3 stones at a time, and the person to remove the last stones is the winner.  There is a method of playing that allows you to win the game if you go second. Whatever the number of stones the opponent takes, take the number of stones so that the stones taken by you and your opponent for that exchange of turns become 4. That way, it will eventually reach 4 stones left on your opponents turn, meaning that no matter how many stones they take, you will win. For example: 20(starting) 1 - 18(2) 2 - 16(2) 1 - 13(3) 2 - 12(1) 1 - 9(3) 2 - 8(1) 1 - 7(1) 2 - 4(3)(checkmate) stones = 20 print (stones , "stones" ) while True : player1 = int(input( "Player1: enter the number of stones to take, 1~3: " )) stones -= player1 print( "Remaining stones:" , stones) if stones <= 0 : print( "player1 wins" ) break player2 = int(input( "Player2:...

Download Calculator

 I was downloading Overwatch again, and blizzard doesn't have an estimated download timer, and the online ones are kind of weird with the bits and bytes and the different types, so I just made a simple one so I don't have to rack my brain everytime. size = float ( input ( "Enter the download size in gigabytes: " )) speed = float ( input ( "Enter your download speed in megabytes per second: " )) size = size* 1000 time = size/speed print (time , "seconds" ) time = time/ 60 print ( "Or" ) print (time , "minutes" ) time = time/ 60 print ( "Or" ) print (time , "hours" )

Random license plates

 The simple program makes a simple 3 letter and 3 digit license plate, in the form LLL-DDD. It just picks 3 random letters from a list of letters, then 3 random digits. def license_plate (): alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" i = 0 alphabet_array = [] while i != len (alphabet): alphabet_array.append(alphabet[i]) i += 1 output = "" for x in range ( 0 , 3 ): output += alphabet[random.randint( 0 , 25 )] output += "-" for x in range ( 0 , 3 ): output += str (random.randint( 0 , 9 )) return output

Sound every hour

 Using the previous two program's components, I made a program that gives me a notification every hour that also tells me what time it is. This will give me an idea of how much time is passing. I'll have this open in a cmd window. from datetime import datetime import win10toast toast = win10toast.ToastNotifier() while True : time = datetime.now().strftime( "%M:%S" ) hour = datetime.now().strftime( "%H" ) if int (hour) > 12 : hour = str ( int (hour) - 12 ) if time == "00:00" : toast.show_toast( "Hourly notification" , "The time is " + hour + ":00" )

Better alarm

 I was thinking that the last program I made wasn't a good method of doing it, so I changed it. This time around, the program takes in a time in 24 hour format, in the form "HH:MM:SS". It then adds it to a list of those values, so that it can go through them and see if the current time is a time where an alarm needs to go off. If it is, it shows the notification, then removes that value from the list. If the list is empty, the program terminates. The current program doesn't allow for multiple inputs into the alarm's list, because the CLI will stop the program's progress if not given an input. Basically, the program is set to be ready for graphics integration.  from datetime import * import win10toast alarm_time = [] toast = win10toast.ToastNotifier() alarm_time.append( input ( "Enter the time for the alarm, in the form HH:MM:SS in 24 hour time: " )) print (alarm_time[ 0 ]) while True : time = datetime.now().strftime( "%H:%M:%S" ) i ...