Epython Lab via @QuizBot
🎲 Quiz 'Python' This quiz is introducing the basic python for beginners. 🖊 6 questions · ⏱ 3 min
Top 5. Still you have time to wine.
🥇 @Reset19 – 5 (53.1 sec)
🥈 @being_me1 – 5 (1 min 33 sec)
🥉 @PrisWen – 5 (1 min 42 sec)
4. ㅤㅤㅤㅤ ㅤ – 5 (1 min 45 sec)
🥇 @Reset19 – 5 (53.1 sec)
🥈 @being_me1 – 5 (1 min 33 sec)
🥉 @PrisWen – 5 (1 min 42 sec)
4. ㅤㅤㅤㅤ ㅤ – 5 (1 min 45 sec)
#TIP #help_function
Python has many more functions, and defining your own functions is a big part of python programming.
The help() function is possibly the most important Python function you can learn. If you can remember how to use help(), you hold the key to understanding most other function.
Here is an example:
help(round)
Python has many more functions, and defining your own functions is a big part of python programming.
The help() function is possibly the most important Python function you can learn. If you can remember how to use help(), you hold the key to understanding most other function.
Here is an example:
help(round)
#Question_by_user
Q: "Can somebody help me in putting list in CSV file in Python"
#Solution
# first create a list with items you would like to save a csv file
big_list = [{'name': 'Fredrick Stein', 'userid': 6712359021, 'is_admin': False},
{'name': 'Wiltmore Denis', 'userid': 2525942, 'is_admin': False},
{'name': 'Greely Plonk', 'userid': 15890235, 'is_admin': False},
{'name': 'Dendris Stulo', 'userid': 572189563, 'is_admin': True}]
# import csv module
import csv
# create afile with open function with a temporary file name output.csv
with open('output.csv', 'w') as output_csv:
# create a list of headers
fields = ['name', 'userid', 'is_admin']
# write the output using dictionary writter function
output_writer = csv.DictWriter(output_csv, fieldnames=fields)
# write the headers
output_writer.writeheader()
# create for loop which iterate each list and write a row
for item in big_list:
output_writer.writerow(item)
Q: "Can somebody help me in putting list in CSV file in Python"
#Solution
# first create a list with items you would like to save a csv file
big_list = [{'name': 'Fredrick Stein', 'userid': 6712359021, 'is_admin': False},
{'name': 'Wiltmore Denis', 'userid': 2525942, 'is_admin': False},
{'name': 'Greely Plonk', 'userid': 15890235, 'is_admin': False},
{'name': 'Dendris Stulo', 'userid': 572189563, 'is_admin': True}]
# import csv module
import csv
# create afile with open function with a temporary file name output.csv
with open('output.csv', 'w') as output_csv:
# create a list of headers
fields = ['name', 'userid', 'is_admin']
# write the output using dictionary writter function
output_writer = csv.DictWriter(output_csv, fieldnames=fields)
# write the headers
output_writer.writeheader()
# create for loop which iterate each list and write a row
for item in big_list:
output_writer.writerow(item)
👍3
One more #question_by_another_user
#Q: "What is the d/nce b/n Machine learning and Data science ...?"
#Q: "What is the d/nce b/n Machine learning and Data science ...?"
#CODE_CHALLENGE #PYTHON_LIST #LOOPS #FUNCTIONS
1. Write a function called delete_starting_evens() that has a parameter named lst.
The function should remove elements from the front of lst until the front of the list is not even. The function should then return lst.
For example if lst started as [4, 8, 10, 11, 12, 15], then delete_starting_evens(lst) should return [11, 12, 15].
Make sure your function works even if every element in the list is even!
POST YOUR SOLUTION @Pydiscussion
1. Write a function called delete_starting_evens() that has a parameter named lst.
The function should remove elements from the front of lst until the front of the list is not even. The function should then return lst.
For example if lst started as [4, 8, 10, 11, 12, 15], then delete_starting_evens(lst) should return [11, 12, 15].
Make sure your function works even if every element in the list is even!
POST YOUR SOLUTION @Pydiscussion
NEURAL NETWORK
A neural network is a network or circuit of neurons,or in a modern sense, an artificial neural network, composed of artificial neurons or nodes. This a neural network is either a biological neutral network, mafe up of real biological neurons or an artificial neural network for solving Artificial Intelligence problems. The connections of the biological neurons are modelled as weight. A positive weight reflects and extraordinary collection, while negative values means inhibitory connections. All inputs are modified by weight and summed. This activity is referred to as a linear combination. Finally and activation function control ls the Amplitude of the output. For example and acceptable range of output is usually between 0 and 1, or it could be -1 and 1.
A neural network is a network or circuit of neurons,or in a modern sense, an artificial neural network, composed of artificial neurons or nodes. This a neural network is either a biological neutral network, mafe up of real biological neurons or an artificial neural network for solving Artificial Intelligence problems. The connections of the biological neurons are modelled as weight. A positive weight reflects and extraordinary collection, while negative values means inhibitory connections. All inputs are modified by weight and summed. This activity is referred to as a linear combination. Finally and activation function control ls the Amplitude of the output. For example and acceptable range of output is usually between 0 and 1, or it could be -1 and 1.
Why we choice Python ? Well, Python is the library with the most complete set of Neural Network library . I will use Keras.
Keras is a higher-level abstraction for the popular neural network library, Tensorflow. Because of the high level of abstraction, you don’t have to build a low-level Linear Algorithm and Multivariate Calculus by yourself.
Keras is a higher-level abstraction for the popular neural network library, Tensorflow. Because of the high level of abstraction, you don’t have to build a low-level Linear Algorithm and Multivariate Calculus by yourself.
What does a neuron do ?
First, it adds up the value of every neurons from the previous column it is connected to.there are 3 inputs (x1, x2, x3) coming to the neuron, so 3 neurons of the previous column are connected to our neuron.
This value is multiplied, before being added, by another variable called “weight” (w1, w2, w3) which determines the connection between the two neurons. Each connection of neurons has its own weight, and those are the only values that will be modified during the learning process.
Moreover, a bias value may be added to the total value calculated. It is not a value coming from a specific neuron and is chosen before the learning phase, but can be useful for the network.
After all those summations, the neuron finally applies a function called “activation function” to the obtained value.
Take all values from connected neurons multiplied by their respective weight, add them, and apply an activation function. Then, the neuron is ready to send its new value to other neurons.
After every neurons of a column did it, the neural network passes to the next column. In the end, the last values obtained should be one usable to determine the desired output.
Now that we understand what a neuron does, we could possibly create any network we want.
First, it adds up the value of every neurons from the previous column it is connected to.there are 3 inputs (x1, x2, x3) coming to the neuron, so 3 neurons of the previous column are connected to our neuron.
This value is multiplied, before being added, by another variable called “weight” (w1, w2, w3) which determines the connection between the two neurons. Each connection of neurons has its own weight, and those are the only values that will be modified during the learning process.
Moreover, a bias value may be added to the total value calculated. It is not a value coming from a specific neuron and is chosen before the learning phase, but can be useful for the network.
After all those summations, the neuron finally applies a function called “activation function” to the obtained value.
Take all values from connected neurons multiplied by their respective weight, add them, and apply an activation function. Then, the neuron is ready to send its new value to other neurons.
After every neurons of a column did it, the neural network passes to the next column. In the end, the last values obtained should be one usable to determine the desired output.
Now that we understand what a neuron does, we could possibly create any network we want.
Epython Lab pinned «NEURAL NETWORK A neural network is a network or circuit of neurons,or in a modern sense, an artificial neural network, composed of artificial neurons or nodes. This a neural network is either a biological neutral network, mafe up of real biological neurons…»
Epython Lab
#CODE_CHALLENGE #PYTHON_LIST #LOOPS #FUNCTIONS 1. Write a function called delete_starting_evens() that has a parameter named lst. The function should remove elements from the front of lst until the front of the list is not even. The function should then…
#SOLUTION
Many of you are tried your best solution for the challenge. We thank you so much for your contribution.
We also thanks to someone who shared the info to others.
based on the instruction this is the best solution for the challenge
#Write your function here
def delete_starting_evens(lst):
# then check the condition here
while (len(lst) > 0 and lst[0] % 2 == 0):
# then slice the list
lst = lst[1:]
return lst
# Call the function and print the result
print(delete_starting_evens([4, 8, 10, 11, 12, 15]))
print(delete_starting_evens([4, 8, 10]))
# output
[11, 12, 15]
[]
Many of you are tried your best solution for the challenge. We thank you so much for your contribution.
We also thanks to someone who shared the info to others.
based on the instruction this is the best solution for the challenge
#Write your function here
def delete_starting_evens(lst):
# then check the condition here
while (len(lst) > 0 and lst[0] % 2 == 0):
# then slice the list
lst = lst[1:]
return lst
# Call the function and print the result
print(delete_starting_evens([4, 8, 10, 11, 12, 15]))
print(delete_starting_evens([4, 8, 10]))
# output
[11, 12, 15]
[]
#CODE_CHALLENGE_2 #FUNCTION #LIST_SLIC #STRING
1. Commercial bank of Ethiopia realized that their policy of using the first five letters of an employee’s last name as a user name isn’t ideal when they have multiple employees with the same last name.
Write a function called account_generator that takes two inputs, first_name and last_name and concatenates the first three letters of each and then returns the new account name.
2. They also wants to update how they generate temporary passwords for new employees.
Write a function called password_generator that takes two inputs, first_name and last_name and then concatenate the last three letters of each and returns them as a string.
Example: first_name = "Asibeh"
last_name = "Tenager"
expected output: user_name = AsiTen
temp_password = behger
Post your solution @PYTHONETHBOT
1. Commercial bank of Ethiopia realized that their policy of using the first five letters of an employee’s last name as a user name isn’t ideal when they have multiple employees with the same last name.
Write a function called account_generator that takes two inputs, first_name and last_name and concatenates the first three letters of each and then returns the new account name.
2. They also wants to update how they generate temporary passwords for new employees.
Write a function called password_generator that takes two inputs, first_name and last_name and then concatenate the last three letters of each and returns them as a string.
Example: first_name = "Asibeh"
last_name = "Tenager"
expected output: user_name = AsiTen
temp_password = behger
Post your solution @PYTHONETHBOT
Epython Lab
#CODE_CHALLENGE_2 #FUNCTION #LIST_SLIC #STRING 1. Commercial bank of Ethiopia realized that their policy of using the first five letters of an employee’s last name as a user name isn’t ideal when they have multiple employees with the same last name. Write…
Best solution is done by Sami(@Smlazne). Thanks for your contribution.
#AlternativeSolution
first_name = "Asibeh"
last_name ="Tenager"
def account_generator(first_name, last_name):
new_account = first_name[:3] + last_name[:3]
return new_account
# another function password generator
def password_generator(first_name, last_name):
new_pass = first_name[len(first_name)-3:] + last_name[len(last_name)-3:]
return new_pass
# call and print the result
# call and test the function
new_account = account_generator(first_name, last_name)
print(new_account)
temp_password = password_generator(first_name, last_name)
print(temp_password)
#If we wanted to find the last three letters of a string, we could use len:
#AlternativeSolution
first_name = "Asibeh"
last_name ="Tenager"
def account_generator(first_name, last_name):
new_account = first_name[:3] + last_name[:3]
return new_account
# another function password generator
def password_generator(first_name, last_name):
new_pass = first_name[len(first_name)-3:] + last_name[len(last_name)-3:]
return new_pass
# call and print the result
# call and test the function
new_account = account_generator(first_name, last_name)
print(new_account)
temp_password = password_generator(first_name, last_name)
print(temp_password)
#If we wanted to find the last three letters of a string, we could use len:
#PROJECTCHALLENGE #LOOP #DICTIONARY #LIST #FUNCTIONS
Scrabble
In this project, you will process some data from a group of friends playing scrabble. You will use dictionaries to organize players, words, and points.
There are many ways you can extend this project on your own if you finish and want to get more practice!
N.B: You should go through each task to complete this project.
Post your solution via @PYTHONETHBOT
Don't post your solution in the group
Follow instructions accordingly
Tasks
letters = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"]
points = [1, 3, 3, 2, 1, 4, 2, 4, 1, 8, 5, 1, 3, 4, 1, 3, 10, 1, 1, 1, 1, 4, 4, 8, 4, 10]
1. I have provided you with two lists, letters and points. You would like to combine these two into a dictionary that would map a letter to its point value.
Using a list comprehension and zip, create a dictionary called letter_to_points that has the elements of letters as the keys and the elements of points as the values.
2. Our letters list did not take into account blank tiles. Add an element to the letter_to_points dictionary that has a key of " " and a point value of 0.
3. We want to create a function that will take in a word and return how many points that word is worth.
Define a function called score_word that takes in a parameter word.
4. Inside score_word, create a variable called point_total and set it to 0.
5. After defining point_total, create a for loop that goes through the letters in word and adds the point value of each letter to point_total.
You should get the point value from the letter_to_points dictionary. If the letter you are checking for is not in letter_to_points, add 0 to the point_total.
6. After the for loop is finished, return point_total.
7. Let’s test this function! Create a variable called asibeh_points and set it equal to the value returned by the score_word() function with an input of "ASIBEH".
8. We expect the word ASIBEH to earn 11 points:
(A + S + I + B + E + H)
Let’s print out asibeh_points to make sure we got it right.
9. Create a dictionary called player_to_words that maps players to a list of the words they have played. This table represents the data to transcribe into your dictionary:
player1 wordNerd Lexi Con Prof Reader
BLUE EARTH ERASER ZAP
TENNIS EYES BELLY COMA
EXIT MACHINE HUSKY PERIOD
10. Create an empty dictionary called player_to_points.
11. Iterate through the items in player_to_words. Call each player player and each list of words words.
Within your loop, create a variable called player_points and set it to 0.
12. Within the loop, create another loop that goes through each word in words and adds the value of score_word() with word as an input.
13. After the inner loop ends, set the current player value to be a key of player_to_points, with a value of player_points.
14. player_to_points should now contain the mapping of players to how many points they’ve scored. Print this out to see the current standings for this game!
If you’ve calculated correctly, wordNerd should be winning by 1 point.
====GOOD LUCK=====
Scrabble
In this project, you will process some data from a group of friends playing scrabble. You will use dictionaries to organize players, words, and points.
There are many ways you can extend this project on your own if you finish and want to get more practice!
N.B: You should go through each task to complete this project.
Post your solution via @PYTHONETHBOT
Don't post your solution in the group
Follow instructions accordingly
Tasks
letters = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"]
points = [1, 3, 3, 2, 1, 4, 2, 4, 1, 8, 5, 1, 3, 4, 1, 3, 10, 1, 1, 1, 1, 4, 4, 8, 4, 10]
1. I have provided you with two lists, letters and points. You would like to combine these two into a dictionary that would map a letter to its point value.
Using a list comprehension and zip, create a dictionary called letter_to_points that has the elements of letters as the keys and the elements of points as the values.
2. Our letters list did not take into account blank tiles. Add an element to the letter_to_points dictionary that has a key of " " and a point value of 0.
3. We want to create a function that will take in a word and return how many points that word is worth.
Define a function called score_word that takes in a parameter word.
4. Inside score_word, create a variable called point_total and set it to 0.
5. After defining point_total, create a for loop that goes through the letters in word and adds the point value of each letter to point_total.
You should get the point value from the letter_to_points dictionary. If the letter you are checking for is not in letter_to_points, add 0 to the point_total.
6. After the for loop is finished, return point_total.
7. Let’s test this function! Create a variable called asibeh_points and set it equal to the value returned by the score_word() function with an input of "ASIBEH".
8. We expect the word ASIBEH to earn 11 points:
(A + S + I + B + E + H)
Let’s print out asibeh_points to make sure we got it right.
9. Create a dictionary called player_to_words that maps players to a list of the words they have played. This table represents the data to transcribe into your dictionary:
player1 wordNerd Lexi Con Prof Reader
BLUE EARTH ERASER ZAP
TENNIS EYES BELLY COMA
EXIT MACHINE HUSKY PERIOD
10. Create an empty dictionary called player_to_points.
11. Iterate through the items in player_to_words. Call each player player and each list of words words.
Within your loop, create a variable called player_points and set it to 0.
12. Within the loop, create another loop that goes through each word in words and adds the value of score_word() with word as an input.
13. After the inner loop ends, set the current player value to be a key of player_to_points, with a value of player_points.
14. player_to_points should now contain the mapping of players to how many points they’ve scored. Print this out to see the current standings for this game!
If you’ve calculated correctly, wordNerd should be winning by 1 point.
====GOOD LUCK=====
Numpy Code Snippet.pdf
88.5 KB
Hi, this is a simple example to practice Numpy. Go through each line of code and ask if you have any questions.
#CODE_CHALLENGE_3 #LIST #SWAP_TWO_NUMBERS
#Q: The next iteration of Asibeh Tenager will feature an extra-infuriating new item, the Purple Shell. When used, it warps the last place racer into first place and the first place racer into last place. Write a python function purple_shell and implement the Purple Shell's effect.
Note: Given a list of racers, set the first place racer (at the front of the list) to last
place and vice versa.
N.B: use swap mechanism
given list: racers = ["Asibeh", "Naol", "Obang"]
output list = ["Obang", "Naol", "Asibeh"]
Post your solution at @pythonethbot
#Q: The next iteration of Asibeh Tenager will feature an extra-infuriating new item, the Purple Shell. When used, it warps the last place racer into first place and the first place racer into last place. Write a python function purple_shell and implement the Purple Shell's effect.
Note: Given a list of racers, set the first place racer (at the front of the list) to last
place and vice versa.
N.B: use swap mechanism
given list: racers = ["Asibeh", "Naol", "Obang"]
output list = ["Obang", "Naol", "Asibeh"]
Post your solution at @pythonethbot