In: Computer Science
Using the following list and a “for” loop, display differences of all consecutive pairs of numbers in the list. our_list = [1,2,5,6,3,77,9,0,3,23,0.4,-12.4,-3.12] The output should look like this: 1 3 1 … 4.
Using a “while loop” ask the user for a number and add it to a list if number is even and to a different list if number is odd. Keep asking the user for a number until he says “I’m bored” and doesn't want to give you any more numbers.
5. For the following list, print each element in the list an it’s type. list5 = ['a','b',1,2,[1,2,3,4],'hello',(4,5,6),7,True,"False",2.3]
if you have any doubts, please give me comment...
our_list = [1,2,5,6,3,77,9,0,3,23,0.4,-12.4,-3.12]
for i in range(len(our_list)-1):
diff = our_list[i+1]-our_list[i]
print(diff, end=' ')
print("\n\n")
even_list = []
odd_list = []
inp = input("Enter a number(enter I’m bored to exit): ")
while inp!="I'm bored":
num = int(inp)
if num%2==0:
even_list.append(num)
else:
odd_list.append(num)
inp = input("Enter a number(enter \"I’m bored\" to exit): ")
print("\n\n")
print("Even list: "+str(even_list))
print("Odd list: "+str(odd_list))
list5 = ['a','b',1,2,[1,2,3,4],'hello',(4,5,6),7,True,"False",2.3]
for el in list5:
print(str(el)+" "+str(type(el)))