in python would you please help me to keep this code as in a simple and easy code to follow please
I want the code to run like first line of the letters
['B', 'C', 'D', 'BC', 'CB', 'BD', 'BCB', 'CBD', 'BCBD']
['B', 'BC', 'BCB', 'BCBD', 'C', 'CB', 'CBD', 'BD', 'D']
word="BCBD"
lst=[]
for i in range(len(word)):
for j in range(i+1,len(word)+1):
if word [i:j] not in lst:
lst.append(word[i:j])
print(lst)
word="BCBD"
lst=[]
for i in range(1,len(word)+1):
for j in range(len(word)-i+1):
if word[j:j+i] not in lst:
lst.append(word[j:j+i])
print(lst)

['B', 'C', 'D', 'BC', 'CB', 'BD', 'BCB', 'CBD', 'BCBD']
Output:
['B', 'C', 'B', 'D', 'BC', 'CB', 'BD', 'BCB', 'CBD', 'BCBD'] Process finished with exit code o
in python would you please help me to keep this code as in a simple and...
# Python Please help me convert the input values to float values Code works, but the values printed need to be floats like 77.0 etc. j_list = [] k_list = [] c_list = [] # Enter scores for Jean print("Please enter Jean's scores one by one. ") for i in range(4): j_list.append(eval(input())) print("Jeans scores:", j_list) # Enter scores for Kayla print("Please enter Kayla's scores one by one. ") for i in range(4): k_list.append(eval(input())) print("Kayla scores: ",...
Hey guys, Question with PYTHON I have this simple code and I keep getting 13 for the answer but the answer is actually 13.33. Can someone show me how to get python to return this value! Thanks ! CN = 75 S = (1000/CN) print S
this python code below is to find the longest common subsequence from two input string !!! however it give me the wrong answer, can any one fix it thanks def lcs(s1, s2): matrix = [["" for x in range(len(s2))] for x in range(len(s1))] for i in range(len(s1)): for j in range(len(s2)): if s1[i] == s2[j]: if i == 0 or j == 0: matrix[i][j] = s1[i] else: matrix[i][j] = matrix[i-1][j-1] + s1[i] else: matrix[i][j] = max(matrix[i-1][j], matrix[i][j-1], key=len) cs =...
***IN PYTHON 2.7****Augment the following code with a new class named 'Coin'. Coin should inherit from Die, with the following modifications; The constructor should not take any arguments; a coin always has two sides add a flip() method that uses the roll() method from the parent class. If roll returns 1; flip should return "HEADS". If roll returns a 2, flip should return "TAILS" Do not override the roll or rollMultiple methods from the parent class #!/usr/bin/python # your class...
PLEASE HELP ASAP! in Python, I am supposed to create a program that compares insertion sorting and selection sorting. My program only compares insertion and selection once. It is supposed to compare increasing, decreasing and an array of random values for each at 5 different lengths (without looping). Please help me. I have included my code below. import time import random def insertion_sort(arr): for i in range(1, len(arr)): key = arr[i] j = i - 1 while j >= 0...
Using Python, if you could help me with the code # Create a modified version of the search linear function defined # above to return all # occurrences of the search word in the text # An occurrence is the index of a word in the text that matches your given # search string. # e.g. if "hatter" occurs at positions 0, 6, 12 then return [ 0, 6, 12] def search_linear_occurrences(xs, target): """ Find and return a list of...
please help, language is python You’re creating a secret code to share with your friends such that every word should be written with the second and last letters swapped. Write a function called encode that receives a string (input) and prints out another string with the second and last letters swapped. Example function calls: encode(secret) # should print “the code for secret is stcree” encode(city) # should print “the code for city is cyti”
How can I get my Python code to check to make sure there are no ships overlapping in my Battleship code? I am having a really hard time with a game of battleship that I have due for class. Each time I run my code, It will print the ships on the board but it will at times overlap them. I know I have to use some kind of nested if statements but I just don't get how or where...
PLEASE DESCRIBE THE STEPS IN THE CODE! please.. (simple code) In this homework, the rail fence cipher is written in Python. We did implement this already in the class by appending letters sequentially to three different lists, which represented three rails. In this project, you are allowed to implement it in any other way. First step is to drop all the space characters inside the plain text. An easy way to implement it is to notice that the first rail...
Python Merge Sort
Adjust the following code so that you can create
random lists of numbers of lengths 10, 15,
and 20.
You will run the merge sort 10 times for each
length. Record the run time for the length and then calculate the
average time to sort.
Finally, compare the average run time for each length to the
average time for the Merge Sort.
--------------------------------------------
Initial python code:
import random
import time
def mergeSort(alist):
print("Splitting ",alist)
if len(alist)>1:
mid...