Question

Write a function in PYTHON that reads a sequence of numbers ended by 0 and prints...

Write a function in PYTHON that reads a sequence of numbers ended by 0 and prints “Sorted” if the numbers were input in increasing or decreasing order, otherwise the program must print “Not sorted” (Do not calculate 0)

Sample Input

4

3

-1

-5

0

Sample Output

Sorted

0 0
Add a comment Improve this question Transcribed image text
Answer #1

def isSorted():  
    a=int(input())
    b=0
    flag=0
    if a!=0:
        b=int(input())
    else:
        print('Sorted')
    if b!=0:
        if a>b:
            while b!=0:
                if a<b:
                    flag=1
                a=b
                b=int(input())
        else:
            while b!=0:
                if a>b:
                    flag=1
                a=b
                b=int(input())
    else:
        print('sorted')

    if flag!=0:
        print('Not sorted')
    else:
        print('sorted')
  
       
           

OUTPUT:

>isSorted ) 2 sorted >>isSorted () 2 sorted >>>isSorted ) 2 2 Not sorted

Add a comment
Know the answer?
Add Answer to:
Write a function in PYTHON that reads a sequence of numbers ended by 0 and prints...
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
  • Write a Python program that reads from user the input file called data.txt that consists of...

    Write a Python program that reads from user the input file called data.txt that consists of a  keyword followed by a sequence of numbers separated by commas. If the keyword is UP, the  numbers are sorted in increasing order, if the key word is DOWN, the numbers are sorted in  decreasing order. The sorted sequence of numbers are saved in sorted.txt

  • Python 3 Write a program that reads a sequence of words and prints every word whose...

    Python 3 Write a program that reads a sequence of words and prints every word whose frequency is equal to its length. You can assume that there will always be a word that meets this condition. If more than one word have this condition, you must print first the most frequent one. If two or more words with equal frequencies meet this condition, print them from the smallest to the largest in alphabetical order. Sample Input lee john lee peter...

  • •• E3.5Write a program that reads three numbers and prints “increasing” if they are in increasing...

    •• E3.5Write a program that reads three numbers and prints “increasing” if they are in increasing order, “decreasing” if they are in decreasing order, and “neither” otherwise. Here, “increasing” means “strictly increasing”, with each value larger than its predecessor. The sequence 3 4 4 would not be considered increasing. •• E3.6Repeat Exercise •• E3.5, but before reading the numbers, ask the user whether increasing/decreasing should be “strict” or “lenient”. In lenient mode, the sequence 3 4 4 is increasing and...

  • Write a program that reads a list of integers in the range (0 – 49) and prints out the numbers that does not repeat twice

    IN PYTHONWrite a program that reads a list of integers in the range (0 – 49) and prints out the numbers that does not repeat twice.The first input of the program is the number of integers contained in this list, followed by the integers contained in the list. Print the numbers in in ascending order.Case 1:INPUT: 5 2 2 3 3 1OUTPUT:1Case 2:INPUT:6 1 2 1 2 2 2OUTPUT:2Case 3:INPUT:4 3 2 1 2OUTPUT: 1 3343 2 1 213

  • C programming! Write a program that reads integers until 0 and prints the sum of values...

    C programming! Write a program that reads integers until 0 and prints the sum of values on odd positions minus the sum of values on even positions. Let ?1, ?2, … , ??, 0 be the input sequence. Then the program prints the value of ?1 − ?2 + ?3 − ?4 + ⋯ ??. The input is a sequence of integers that always contains at least 0 and the output will be a single number. For example, for input...

  • 1) Translate the following equation into a Python assignment statement 2) Write Python code that prints...

    1) Translate the following equation into a Python assignment statement 2) Write Python code that prints PLUS, MINUS, O ZERO, depending on the value stored in a variable named N. 3) What is printed by: 3 - 1 while 5: while 10 Print ) Page 1 of 9 4) Write a Python while loop that reads in integers until the user enters a negative number, then prints the sum of the numbers. 1-2 of 9 4) Write a Python while...

  • 1. Write a python program that reads a file and prints the letters in increasing order...

    1. Write a python program that reads a file and prints the letters in increasing order of frequency. Your program should convert entire input to lower case and only counts letters a-z. Special characters or spaces should not be counted. Each letter and it's occurrences should be listed on a separate line. 2. Test and verify your program and it's output. ---Please provide a code and a screenshot of the code and output. Thank you. ----

  • write a python program that reads in 5 numeric values,store them in an array ,then prints...

    write a python program that reads in 5 numeric values,store them in an array ,then prints them out in the reverse order that they were entered

  • Write a program (python) that multiplies two hard-coded numbers, then prints the individual numbers out and...

    Write a program (python) that multiplies two hard-coded numbers, then prints the individual numbers out and prints their product out, all on separate lines. You can choose the two numbers that are multiplied together. Make a copy of previous exercise then modify it to print output exactly like this, rather than just the numbers on separate lines: 10 x 7 = 70 Do this using the string.format() function discussed in the lecture.

  • Python Programming Write a program that reads the dimension of a rectangle and prints its area....

    Python Programming Write a program that reads the dimension of a rectangle and prints its area. The program must handle errors such invalid input. If it encounters an error, it should ask the user to reenter the input. Sample run: Enter height:abc abc is not a vaid input. Try again. Enter height:10 Enter width:hello hello is not a vaid input. Try again. Enter width:world world is not a vaid input. Try again. Enter width:xyz xyz is not a vaid input....

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