USING PYTHON 3!! 1) Write a loop that displays all possible combinations of two
ID: 3786935 • Letter: U
Question
USING PYTHON 3!!
1) Write a loop that displays all possible combinations of two letters where the letters are 'a', or 'b', or 'c', or 'd', or 'e'. The combinations should be displayed in ascending alphabetical order:
aa
ab
ac
ad
ae
ba
bb
...
ee
2)Write a loop that reads positive integers from standard input and that terminates when it reads an integer that is not positive. After the loop terminates, it prints out, on a line by itself, the sum of all the even integers read
3)Write a loop that reads positive integers from standard input, printing out those values that are greater than 100, each on a separate line, The loop terminates when it reads an integer that is not positive.
4)Given the lists list1 and list2, not necessarily of the same length, create a new list consisting of alternating elements of list1 and list2 (that is, the first element of list1 followed by the first element of list2, followed by the second element of list1, followed by the second element of list2, and so on. Once the end of either list is reached, no additional elements are added. For example, if list1 contained [1, 2, 3] and list2 contained [4, 5, 6, 7, 8], then the new list should contain [1, 4, 2, 5, 3, 6]. Associate the new list with the variable list3.
Explanation / Answer
1)
letters = ['a', 'b','c','d','e'] #List of all needed characters
for index1 in range(len(letters)): #Iterator over letters from 'a' to 'e' for ascending order
for index2 in range(len(letters)): #Iterator over letters
print(letters[index1],letters[index2]) #Printing them
2)
data=1
sum=0 # to store sum of even numbers
while(data>0): #perform till data is not negative
data = int(input()); #read data from console
if (data%2)==0: #condition for even number
sum=sum+data #adding even number in sum
print (sum) #printing even number
SAMPLE INPUT
Sample Output
8
3)
data=1
while(data>0): #perform till data is not negative
data = int(input()); #read data from console
if (data)>100: #condition for greater than 100
print("Value greater than 100 is",data)
SAMPLE EXECUTION
4)
list1=[1,2,3,9,11,13] #List 1
list2=[4,5,6,7,8] #List 2
list3=[] # The output list
k=len(list1) #Code to find smaller list's length
if(len(list1)>len(list2)):#Code to find smaller list's length
k=len(list2)#Code to find smaller list's length
for iterate in range(k): #iterator over the length
list3.append(list1[iterate]) #append list1 element first
list3.append(list2[iterate]) #append list2 element next
if(len(list1)!=k): #if list1 element is still left and is constrained dut to size of list2
list3.append(list1[k])
print (list3) #print list3 element
Output for above code
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.