Question

In: Computer Science

Using the following list and a “for” loop, display differences of all consecutive pairs of numbers...

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]

Solutions

Expert Solution

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)))


Related Solutions

Write a for loop in .java to display all numbers from 13 - 93 inclusive, ending...
Write a for loop in .java to display all numbers from 13 - 93 inclusive, ending in 3. • Write a for loop to display a string entered by the user backwards.
Using Python: 1. Compute the difference of differences between consecutive numbers of a series: input ser...
Using Python: 1. Compute the difference of differences between consecutive numbers of a series: input ser = pd.Series([1, 3, 6, 10, 15, 21, 27, 35]) output: [nan, 2.0, 3.0, 4.0, 5.0, 6.0, 6.0, 8.0] [nan, nan, 1.0, 1.0, 1.0, 1.0, 0.0, 2.0] 2. Compute the euclidean distance between two series: Input: p = pd.Series([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) q = pd.Series([10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) Desired Output: 18.165
Using Excel, create scatter plots and display the regression equations for the following pairs of variables:...
Using Excel, create scatter plots and display the regression equations for the following pairs of variables: “MedAge” versus “Sales/SqFt” In your report, include the scatter plots. For each scatter plot, designate the type of relationship observed (increasing/positive, decreasing/negative, or no relationship) and determine what you can conclude from these relationships. Sales/SqFt 701.97 209.93 364.92 443.04 399.20 264.64 571.59 642.25 461.45 638.82 484.38 581.09 267.71 572.84 586.48 368.73 351.47 458.24 987.12 357.45 405.77 680.80 368.02 303.95 393.90 562.12 494.88 310.07 373.46...
1. Write a for loop that will display all of the multiples of 3, one per...
1. Write a for loop that will display all of the multiples of 3, one per line. The starting point is a variable called lower, and the ending point is an integer called upper, inclusive. The "lower" and "upper" variables have been properly declared and assigned values where the value of lower is less than or equal to the value of upper. Declare any other variables that are needed. 2. Write a "while" loop that does the same thing as...
Write a for-loop in MATLAB that generates a list of numbers such that each number is...
Write a for-loop in MATLAB that generates a list of numbers such that each number is the sum of the previous three. Initialize your list of numbers at the values of 0, 0 and 1. In other words, "0" is the first element of the list, "0" is the second element of the list, and "1" is the third element of the list. What is the 20th value in the list?
Using a “for loop” print all even numbers in range from 1 to 1000. Also, please...
Using a “for loop” print all even numbers in range from 1 to 1000. Also, please count and print how many even numbers you have found.
Let V be the set of all ordered pairs of real numbers. Consider the following addition...
Let V be the set of all ordered pairs of real numbers. Consider the following addition and scalar multiplication operations V. Let u = (u1, u2) and v = (v1, v2). Show that V is not a vector space. • u ⊕ v = (u1 + v1 + 1, u2 + v2 + 1 ) • ku = (ku1 + k − 1, ku2 + k − 1) 1)Show that the zero vector is 0 = (−1, −1). 2)Find the...
public void printNumbers(int low, int high) { // using a for loop, print all numbers from...
public void printNumbers(int low, int high) { // using a for loop, print all numbers from low to high } public int sumOfNumbers(int n) { // using a for loop, calculate and return the sum of first n numbers // i.e n = 5, answer = 5+4+3+2+1 = 15 } public void printMultiplicationTable(int num) { // using a for loop, print the multiplication table of num (up to first 10!) // i.e. num = 5, 5*1=5, 5*2=10, 5*3=15, 5*4=20, 5*5=25,...
Write a loop to print a list of numbers starting at 64 and ending at 339....
Write a loop to print a list of numbers starting at 64 and ending at 339. Justify your syntax.
Write a loop to print a list of numbers starting at 64 and ending at 339....
Write a loop to print a list of numbers starting at 64 and ending at 339. Justify your syntax.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT