Please explain the python code below
L1 = [2, 15, 'Carol', 7.4, 0, -10, -6, 42, 27, -1, 2.0, 'hello',
[2, 4], 23]
print("L1 =",L1)
odds =[]
evens=[]
list=['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','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',',','.']
no=0
for i in L1:
i=str(i)
for j in list:
if i.find(j)>=0:
no=1
if no==1:
None
else:
i=int(i)
if i%2==0:
evens.append(i)
else:
odds.append(i)
no=0
print("The list of odd numbers in L1:",odds)
print("The list of even numbers in L1:",evens)
The answer to this question is as follows:
The explanation is provided in the screenshot below:
L1 = [2, 15, 'Carol', 7.4, 0, -10, -6, 42, 27, -1, 2.0, 'hello',
[2, 4], 23]
print("L1 =",L1)
odds =[]
evens=[]
list=['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','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',',','.']
no=0
for i in L1:
#we are starting from the value of i
#from the list l1 it starts from value 2 until end of the
list
i=str(i)
#converting the i value into the string
for j in list:
# This loop takes from the value j i.e it starts from the value a
until end of the list
if i.find(j)>=0:
#if i contains the value of j
#for example the j value for the first repetition j value is a and
we are finding
#if the j i.e a contains the value 2 or not if contains we are
doing no=1
no=1
#if no equal to 1 then None
if no==1:
None
#otherwise the i value is converted into int then checking the
condition for the even or odd
else:
i=int(i)
if i%2==0:
evens.append(i)
else:
odds.append(i)
no=0
#printing the values for the odd or even numbers
print("The list of odd numbers in L1:",odds)
print("The list of even numbers in L1:",evens)
The screenshot are provided below:
Please explain the python code below L1 = [2, 15, 'Carol', 7.4, 0, -10, -6, 42,...
def average_word_length(string): num_words = 0 if not type(string)==str: return "Not a string" if not "A" or not "B" or not "C" or not "D" or not "E" or not "F" or not "G" or not "H" or not "I" or not "J"\ or not "K" or not "L" or not "M" or not "N" or not "O" or not "P" or not "Q" or not "R" or not "S" or not "T"\ or not "U" or not "V" or not...
12.22 Chapter 4: Encrypt Characters Simple Caesar Cipher challenge. You'll need to correct code to print ciphertext character correctly. With offset of 3 the output should be ORIGINAL CHARACTERS 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 ENCRYPTED CHARACTERS D E F G H I J K L M N O P Q R S T U V W X Y Z...
why is this wrong for vectors vector<char> decrypt{ {'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', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A'}, {'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B'}, }; for(int...
I was asked this question:Given any input series a corresponding graph must be generated without the use of any libraries.After, trying my best, I arrived at this solution to which they replied it had a logical issue.# Create the matrix print("Enter the sequence with spaces: ") arr = list(map(int, input().split())) count = len(arr) rows = int(sum(arr)) cols = int(sum(arr) + 4) content = [[" "]*cols for _ in range(rows)] maxq = 0 maxp = 0 content[0][0] = "/" # Apply the positions in the matrix p = 0 q = arr[0] k = 0 for l in range(q): if (k != q): content[k][p] = "/" p = p + 1 k = k + 1 p = q flag = 1 i = 0 j = 0 k = 0 c = 0 temp = 0 r = 0 flag = 1 for i,j in enumerate(arr): c = c + 1 if c < count: k = arr[i+1] else: k = 0 if arr[i]: if flag == 1: content[q][p] = "/\\" if maxq < q: maxq = q maxp = p qori = q pori = p p = p + k temp = q - k...
CODE IN C++ 13.5 Alphabet Histogram Write a program that reads input character by character from the given data file "data.txt" The program should be case insensitive and count the number of occurances of each character in the alphabet. It should print a histogram of the results as follows: A : B : C : * D : * E : * F : G : H : I : J : * K : L : M : N...
Write a python program that writes to an output file "decoder.txt" a table of letters as follows: ___1_2_3_4_5 1: A B C D E 2: F G H I K 3: L M N O P 4: Q R S T U 5: V W X Y Z Note that the letter J has been removed. Use string.ascii_uppercase to start
Write a program that prompts the user to enter a 10 alphabets (A-Z) and converts it to numbers using the following mapping: A, B, C = 8 D, E, F = 6 G, H, I = 4 J, K, L = 5 M, N, 0 = 7 P, Q, R, S = 2 T, U, V, W = 3 X, Y, Z = 1 Please be sure to use Object Oriented Programming concepts when designing and writing code for this...
Spell it out! Use the following Java concepts to compile the program below: String myName = "Chuck"; int length = myName.length(); char firstChar = myName.charAt(0); char secondChar = myName.charAt(1); if (myName.equals("Tom")) { System.out.println ("Sorry, Tom!"); } Write a program that uses a METHOD to translate these individual characters: input output input output input output input output input output a 4 g 9 m /\\/\\ s $ y ‘/ b B h |-| n |\\| t...
Java... Write a program that has 4 separate threads. The threads will have the following arrays: Thread1: A E I M Q U Y Thread2: B F J N R V Z Thread3: C G K O S W ThreadD: D H L P T X Your goal is to synchronize the threads in such a way that they print out all the letters of the alphabet in order.
Need help in c++ programming to output the lines in my code: if word if found: cout << "'" << word << "' was found in the grid" << endl; cout << "'" << word << "' was not found in the grid" << endl; The words can be touching if they are horizontally, vertically, or diagonally adjacent. For example, the board: Q W E R T A S D F G Z X C V B Y U A...