Question

Prompt for a sequence of numbers, the last number being zero. Print the number many elements...

Prompt for a sequence of numbers, the last number being zero. Print the number many elements of this sequence are greater than their previous neighbor. (Code without using True or False values)

Example Input

Enter a Number (zero to quit): 1 
Enter a Number (zero to quit): 5 
Enter a Number (zero to quit): 2 
Enter a Number (zero to quit): 4
Enter a Number (zero to quit): 3
Enter a Number (zero to quit): 0

Example Output

Number of Values Greater Than the Previous: 2


python, sorry. But I believe I got figured out now.
thank you!
0 0
Add a comment Improve this question Transcribed image text
Answer #1
num = 1
previous = 0
i = 0
count = 0

while num != 0:
    num = int(input("Enter a Number (zero to quit): "))
    if num != 0:
        if i == 0:
            previous = num
        if num > previous:
            count += 1
        i += 1
        previous = num

print("Number of Values Greater Than the Previous:", count)

Add a comment
Know the answer?
Add Answer to:
Prompt for a sequence of numbers, the last number being zero. Print the number many elements...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Please answere using python language codes. Write a program to print out Collatz sequence for a...

    Please answere using python language codes. Write a program to print out Collatz sequence for a user-supplied number. Prompt the user for a positive integer which will become the first number in the sequence. Next number in the sequence is derived as follows: If previous number is odd, the next number is 3 times the previous, plus 1. If previous number is even, the next number is half of the previous According to Collatz proposition, the sequence ultimately reaches 1...

  • Fibonacci Sequence The Fibonacci Sequence is the series of numbers: 0, 1, 1, 2, 3, 5,...

    Fibonacci Sequence The Fibonacci Sequence is the series of numbers: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, ... The next number is found by adding up the two numbers before it. The 2 is found by adding the two numbers before it (1+1) The 3 is found by adding the two numbers before it (1+2), And the 5 is (2+3), and so on!         Example: the next number in the sequence above is 21+34 = 55 Source:...

  • F a as a sequence of adjacent array elements such that each value in the run array was of size 10...

    f a as a sequence of adjacent array elements such that each value in the run array was of size 10 9. We define a "run" of elements o (except for the first) is one greater than the previous and looked like: value. For example, say the 3 2 16 9 7 8 9 2 a: position 0 3 We have three runs in this array: (1) between 9,10,1, 12) and, (3) between positions 7 and 8, (15, 16) positions...

  • Write a program that receives a series of numbers from the user and allows the user...

    Write a program that receives a series of numbers from the user and allows the user to press the enter key to indicate that he or she is finished providing inputs. After the user presses the enter key, the program should print the sum of the numbers and their average.   >>> totalSum =0 >>> count=0 >>> while True:    number=input("Enter a number or press enter to quit:")    if number =="":        break    totalSum += float(number)    count+=1...

  • USING MATLAB 7. A Fibonacci sequence is composed of elements created by adding the two previous...

    USING MATLAB 7. A Fibonacci sequence is composed of elements created by adding the two previous elements. The simplest Fibonacci sequence starts with 1, 1 and proceeds as follows: 1,1,2,3,5,8,13, So, if f(1)-1 and f(2) -1, then f(3)-2)+f(1) We can represent this pattern as f(x) - f(x-1)+f(x-2). A Fibonacci sequence can be created with any two numbers. Prompt the user to enter the first two numbers in a Fibonacci sequence and the total number of elements requested in the sequence....

  • A Fibonacci sequence is a series of numbers where the next number in the series is...

    A Fibonacci sequence is a series of numbers where the next number in the series is the sum of the previous two numbers. The sequence starts with the numbers 0 and 1. Here are the first ten numbers of the Fibonacci sequence:             0 1 1 2 3 5 8 13 21 34 Write a Java program to print out the first fifteen numbers of the Fibonacci sequence using a loop. You will need three variables previous, current, and next...

  • Question 1 The code used to output messages to the screen begins with run # print...

    Question 1 The code used to output messages to the screen begins with run # print output Flag this Question Question 2 The code used to begin a comment in the Python program source code is # Hello * Comment Flag this Question Question 3 A variable name is like a(n) input typed on a keyboard address in computer memory where values can be stored output to a computer screen value assigned to an address in computer memory Flag this...

  • The Fibonacci sequence is the sequence of numbers: 0, 1, 1, 2, 3, 5, 8, 13,...

    The Fibonacci sequence is the sequence of numbers: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, … The next number is found by adding up the two numbers before it. For example, the 2 is found by adding the two numbers before it (1+1). The 3 is found by adding the two numbers before it (1+2). The 5 is found by adding the two numbers before it (2+3), and so on! Each number in the sequence is called...

  • Please use python and show the code you used. Question 2 5 pts from sympy import...

    Please use python and show the code you used. Question 2 5 pts from sympy import sieve sieve.extend_to_no(999) primes - set (sieve._list) The code above creates a set of prime numbers, stored in the variable primes. Check whether or not the following list of numbers is prime, by checking if it is in the set primes. Keep the sequence of True/False values in the order given, and express that sequence as a 14-digit binary number. Enter the equivalent decimal integer...

  • IN PYTHON 1.Choose a positive integer 2. To get the next number in the sequence we...

    IN PYTHON 1.Choose a positive integer 2. To get the next number in the sequence we do the following: If the integer is odd, we multiply by 3 and add 1. If the integer is even, we divide by 2. It is hypothesized that the above sequence will always converge to the value of 1, regardless of any valid initial choice. This hypothesis is known as the Collatz Conjecture. For example, if we start at 5, the numbers generated by...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT