Elder Moderator

[email protected]

Total likes received: 94 | Pubby Cash: 873


Evan is a person who does coding. He codes with Python and watches videos of bootstrap. That's it.

My Articles: 57

The Algorithm to Create a Crossword Game Using Python.

Categories: Tech | Pubby Cash Received:  0

Do you know the algorithm to make a crossword puzzle using Python? If you do not know how, then you should read this article because it will teach you how. We will make two arrays one of them has the correct answers while the other one has the letter O to replace the words. Here is the code. added_words_count = 0# make a variable equal to zero def add_word(word,arr): #this function adds the horizontal words to the cross word     global added_words_count#global that variable that was made     row=random.choice(lst)#take a random row to put the word in     lst.remove(row)# remove it so it does not repeat     col=random.randint(0,15-len(word))# choose a random column to put the word in     addhword = True#set this variable to true for adding horizontal words     count = 0#set count to zero     rand_num = random.randint(0,1)# randomly choosing 1 or 0 to decide if the word goes from right to left or left to right.     if rand_num == 0:if the random number is zero         word1 = word[::-1]# make it backwards     else: # if the random number is not zero         word1 = word# keep it the same     for i in range(0,len(word1)):# print i         arr[row,col+i]=lett2num[word1[i]]     added_words_count += 1 #add one to the added_words_count variable     print('added horizontal')# print added horizontal to know how many words you added were horizontal def add_word1(word,arr):# this function is for adding vertical words     global added_words_count# global the added_words_count variable     addvword = True# set adding vertical words to true     rand_num = random.randint(0,1)# randomly choosing 1 or 0 to decide if the word goes from right to left or left to right.     if rand_num == 0:if the random number is zero         word1 = word[::-1]# make it backwards     else: # if the random number is not zero         word1 = word# keep it the same     def adding_v_word():# make another function for adding         completely_empty = True# set the completely empty variable to true         col=random.choice(lst)# lst.remove(col)         row=random.randint(0,15-len(word))# choose a random row to put the word in         ready = False# set the variable ready to false         for i in range(0,len(word1)):print i             if arr[row+i,col] != 0:# if it is not equal to zero                 completely_empty = False# the completely empty variable is equal to false                 addvword = False# also, adding a vertical word would be false                 # if the letter in this square is the same as the one we're adding                 if arr[row+i,col] == lett2num[word1[i]]:# if it is equal                     addvword = True# adding vertical word is true                     ready = True# also ready is true                 else:if that is not true                     addvword = False # both are false                     ready = False                     break # use break method         return row, col, ready, completely_empty# return the variables     while True:# while that is true         row, col, ready, completely_empty = adding_v_word()# those variables equal adding_v_word()         if ready or completely_empty:# if ready or completely_true are true             for i in range(0,len(word1)):# print i                 arr[row+i,col]=lett2num[word1[i]]             print('just added another vertical') # print this so you know when you added a vertical word             added_words_count += 1             break def display_arr(arr):# this function is for displaying the array     for row in range(0,15):# for the row in the range of 0 to 15         line=""# set line to an empty string         for col in range(0,15):# for the column in the range of 0 to 15             line = line + num2lett[(arr[row,col])] + " "# set line to line plus the num2lett plus an empty string         print(line)# print line     print()# print...  Read more

How to Make Diagonal Words and Making them Backwards Using Python

Categories: Tech | Pubby Cash Received:  0

Do you know the algorithm to make a crossword puzzle using Python? If you do not know how, then you should read this article because it will teach you how. We will make two arrays one of them has the correct answers while the other one has the letter O to replace the words. Here is the code. added_words_count = 0# make a variable equal to zero def add_word(word,arr): #this function adds the horizontal words to the cross word     global added_words_count#global that variable that was made     row=random.choice(lst)#take a random row to put the word in     lst.remove(row)# remove it so it does not repeat     col=random.randint(0,15-len(word))# choose a random column to put the word in     addhword = True#set this variable to true for adding horizontal words     count = 0#set count to zero     rand_num = random.randint(0,1)# randomly choosing 1 or 0 to decide if the word goes from right to left or left to right.     if rand_num == 0:if the random number is zero         word1 = word[::-1]# make it backwards     else: # if the random number is not zero         word1 = word# keep it the same     for i in range(0,len(word1)):# print i         arr[row,col+i]=lett2num[word1[i]]     added_words_count += 1 #add one to the added_words_count variable     print('added horizontal')# print added horizontal to know how many words you added were horizontal def add_word1(word,arr):# this function is for adding vertical words     global added_words_count# global the added_words_count variable     addvword = True# set adding vertical words to true     rand_num = random.randint(0,1)# randomly choosing 1 or 0 to decide if the word goes from right to left or left to right.     if rand_num == 0:if the random number is zero         word1 = word[::-1]# make it backwards     else: # if the random number is not zero         word1 = word# keep it the same     def adding_v_word():# make another function for adding         completely_empty = True# set the completely empty variable to true         col=random.choice(lst)# lst.remove(col)         row=random.randint(0,15-len(word))# choose a random row to put the word in         ready = False# set the variable ready to false         for i in range(0,len(word1)):print i             if arr[row+i,col] != 0:# if it is not equal to zero                 completely_empty = False# the completely empty variable is equal to false                 addvword = False# also, adding a vertical word would be false                 # if the letter in this square is the same as the one we're adding                 if arr[row+i,col] == lett2num[word1[i]]:# if it is equal                     addvword = True# adding vertical word is true                     ready = True# also ready is true                 else:if that is not true                     addvword = False # both are false                     ready = False                     break # use break method         return row, col, ready, completely_empty# return the variables     while True:# while that is true         row, col, ready, completely_empty = adding_v_word()# those variables equal adding_v_word()         if ready or completely_empty:# if ready or completely_true are true             for i in range(0,len(word1)):# print i                 arr[row+i,col]=lett2num[word1[i]]             print('just added another vertical') # print this so you know when you added a vertical word             added_words_count += 1             break def display_arr(arr):# this function is for displaying the array     for row in range(0,15):# for the row in the range of 0 to 15         line=""# set line to an empty string         for col in range(0,15):# for the column in the range of 0 to 15             line = line + num2lett[(arr[row,col])] + " "# set line to line plus the num2lett plus an empty string         print(line)# print line     print()# print...  Read more

How to Make Letters Horizontal, Vertical, Backwards, and Intersect when Coding a Word Search Game in Python

Categories: Tech | Pubby Cash Received:  0

Do you want to learn how to make letters horizontal, vertical, backwards, and intersect when coding a word search game in Python? If you said yes, than you should read this article, because it will teach you how. First, how to make words horizontal and how to make those horizontal words backwards. To do this, you first need to make a function. You then need to put things inside the function. Here is an example. def add_word(word,arr):# make a function     col=random.choice(lst)#chooses a random location in the columns for the word to be placed     lst.remove(col)# removes that place so another word does not get placed there     row=random.randint(0,15-len(word))# chooses a random row for the word to be placed, however the length of the word must fit into the row and cannot go over the limit     rand_num = random.randint(0,1)# 0 means that the word is backwards, 1 means that is forward     if rand_num == 0: # if the random number is 0, then you make the word backwards         word1 = word[::-1]# [::-1] makes words reversed     else: # if it is not 0, then keep it the same         word1 = word     for i in range(0,len(word1)): # printing the i         arr[col,row+i]=lett2num[word1[i]] Next I will tell you how to add the vertical words, make it backwards, and make them cross with the horizontal words. Adding a vertical word is almost the same as adding a horizontal one. The difference is that vertical ones are basically the opposite of horizontal ones. Here is an example. def add_word1(word,arr): # make a function     row=random.choice(lst)#chooses a random location in the rows for the word to be placed     lst.remove(row)# removes that place so another word does not get placed there     col=random.randint(0,15-len(word))# chooses a random column for the word to be placed, however the length of the word must fit into the row and cannot go over the limit     addvword = True # make a new variable for adding vertical word. This is so vertical words and horizontal ones can cross     count = 0 # set count to 0     rand_num = random.randint(0,1)# 0 means that the word is backwards, 1 means that is forward     if rand_num == 0: if the random number is 0, then you make the word backwards         word1 = word[::-1]# [::-1] makes words reversed     else:# if it is not 0, then keep it the same         word1 = word     for i in range(0,len(word1)):# printing the i         arr[col+i,row]=lett2num[word1[i]]     for i in range(0,len(word1)):         if arr[col+i,row]!=0:# if the adding vertical word space is taken...             addvword = False #you cannot add that vertical word there             if arr[col+i,row] == lett2num[word1[i]]:# if the array is equal to the word1 letter...                 count +=1 # add one to the count             else: # if that is not true...                 count = 0# keep count at 0     if count != 0: # if the count is not zero...         for i in range(0,len(word1)):             arr[col+i,row]=lett2num[word1[i]] # the array is equal to the word1 letter     elif addvword: # if that is not true, addvword is equal to true         for i in range(0,len(word1)):             arr[col+i,row]=lett2num[word1[i]]# you can cross the word with another word if the crossing letter is the same By now, you should have a better understanding of how to make letters horizontal, vertical, backwards, and intersect when...  Read more

How to Use NumPy in Python

Categories: Tech | Pubby Cash Received:  0

Do you know how to use NumPy, or what NumPy even is? NumPy is basically a library for the Python programming language, adding support for large, multi-dimensional arrays and matrices, along with a large collection of high-level mathematical functions to operate on these arrays. To use NumPy, you first need to import it, like this. import numpy as np I will now show an example of what you can do with NumPy. First of all, you can do arrays with NumPy. Here is a example. arr = np.array( [[ 1, 2, 3],                 [ 4, 2, 5]] ) This code is basically saying that you are making a array object. After that, you can do some things like getting the size of the array. You can do it like this. print("Size of array: ", arr.size) The output of this would be Size of array: 6. After reading this article, I hope you have a better understanding of NumPy and how it works....  Read more

How to Use the Random Method in Python

Categories: Tech | Pubby Cash Received:  0

The random method in Python is a very useful tool in Python because it has the power to select a random value. In this article, I will try my best to explain how to use the random method. The first thing that you need to know is that you have to import random first to access it. import random I will now provide an example of how to use the random method. Lets say that we want our program to generate a random number from one through five. This is how we can use the random method to do it. import random numbers = [1, 2, 3, 4, 5] print(random.choice(numbers)) This code is saying that numbers is equal to 1, 2, 3, 4, and 5. We are then printing a random number that is in the numbers variable. The output of this program could be 1, 2, 3, 4, or 5. This is because we are choosing a random number. After reading this article, you should have a better understanding about how to use the random method....  Read more

1 ... 5 6 7 ... 12

Daily Deals


MECHANICSBURG WEATHER