Question

In: Computer Science

PYTHON Write a program that accepts a range of input from the user and checks whether...

PYTHON Write a program that accepts a range of input from the user and checks whether the input data is sorted or not. If the data series is already sorted your program should print “True” or should print “False” otherwise. You should not use any sort function for this program. Input: How many numbers you want to input: 3 # user input 3 Input the number: 5 Input the number: 2 Input the number: 7 Output: False

Solutions

Expert Solution

Note: Done accordingly. Please comment for any problem. Please Uprate. Thanks

Code:


#asking for number of inputs
numInput=int(input("How many numbers you want to input: "))
sortedAsc=True #setting sorted by Ascending order as true
sortedDesc=True #setting sorted by descending order as true

#looping to take input
for i in range(numInput):
#taking next number
numInput=int(input("Input the number: "))
if i==0:#if number is first number then setting last number to input
lastNum=numInput
  
#checking if input is greater than last number(condition for Ascending order)
if lastNum<=numInput:
sortedAsc=sortedAsc and True #if condition is met then anding with True
else:
sortedAsc=sortedAsc and False #if condition does not met then anding with False, this makes final sortedAsc as false
  
if lastNum>=numInput:
sortedDesc=sortedDesc and True #if condition is met then anding with True
else:
sortedDesc=sortedDesc and False #if condition does not met then anding with False, this makes final sortedDesc as false
lastNum=numInput
  

#checking if sorted by either Ascending or descending
#and print True or False based on that
if sortedAsc or sortedDesc:
print("True")
else:
print("False")

Code Screenshot:

Output:


Related Solutions

2) Write a C++ program that accepts a sentence as an input from the user. Do...
2) Write a C++ program that accepts a sentence as an input from the user. Do the following with the sentence. Please use C++ style string for this question. 1) Count the number of letters in the input 2) Change all lower case letters of the sentence to the corresponding upper case
PYTHON Write a python program that encrypts and decrypts the user input. Note – Your input...
PYTHON Write a python program that encrypts and decrypts the user input. Note – Your input should be only lowercase characters with no spaces. Your program should have a secret distance given by the user that will be used for encryption/decryption. Each character of the user’s input should be offset by the distance value given by the user For Encryption Process: Take the string and reverse the string. Encrypt the reverse string with each character replaced with distance value (x)...
Need this program in python. The data must be taken from user as input. Write a...
Need this program in python. The data must be taken from user as input. Write a program that prompts the user to select either Miles-to-Kilometers or Kilometers-to-Miles, then asks the user to enter the distance they wish to convert. The conversion formula is: Miles = Kilometers X 0.6214 Kilometers = Miles / 0.6214 Write two functions that each accept a distance as an argument, one that converts from Miles-to-Kilometers and another that converts from Kilometers-to-Miles The conversion MUST be done...
MATLAB QUESTION Write a python program to request a positive float input from the user, x....
MATLAB QUESTION Write a python program to request a positive float input from the user, x. The program should check for the value of x. If x is larger than or equal to 1.0, the program should display the value of x in addition to the string “is larger than or equal to 1” and then terminate the program. If x is less than 1 the program should calculate y such that: y = 1-x+x^2/2-x^3/3+x^4/4-x^5/5……-x^99/99+x^100/100 The program should then display...
Python Program Write a program that will ask a user on how many input colored balls...
Python Program Write a program that will ask a user on how many input colored balls of the following codes: R-red, B-blue, W-white, G-green and O-orange -will he or she would like to enter in the program and print the total number of Red balls were encountered. Assume an uppercase and lower case letter will be accepted.
Design a Python script that accepts as input a user-provided list and transforms it into a...
Design a Python script that accepts as input a user-provided list and transforms it into a different list in preparation for data analysis, the transformed list replaces each numeric element in the original list with its base-10 order of magnitude and replaces string elements with blanks. Example: This script accepts as input a user-provided list expected to contain non-zero numbers and strings. It then prints a transformed list replacing numbers with their order of magnitude, and strings as blanks. Type...
Write a Python program which prompts the user to input a string. Then, print the string...
Write a Python program which prompts the user to input a string. Then, print the string in reverse to the terminal Sample output Please enter a word: "zeus" The reverse of zeus is suez Hint: There are several ways to accomplish this. Recall that a string is an itterable object and therefore can be used with a for loop
I'm making a python program that checks the users input. If the users input does not...
I'm making a python program that checks the users input. If the users input does not match the rules then the program will output "No". If the users input does match the rules it will output "Yes". The rules are : at least 5 uppercase letters at least 5 lowercase letters at least 5 numbers No more than 20 characters in total I have managed to meet these conditions in individual python files but not in one. Ideally without importing...
I'm making a python program that checks the users input. If the users input does not...
I'm making a python program that checks the users input. If the users input does not match the rules then the program will output "No". If the users input does match the rules it will output "Yes". The rules are : 5 uppercase letters 5 lowercase letters 5 numbers First letter must be capitilized The total characters must be 15 I have managed to meet these conditions in individual python files but not in one. Ideally without importing anything, still...
Question 2. Write a MARIE program that accepts an integer from the user, and if it...
Question 2. Write a MARIE program that accepts an integer from the user, and if it is a prime number the program will output 1, otherwise, the program will output 0. Examples: If the user input is 17, the output would be 1 If the user input is 2, the output would be 1 If the user input is 15, the output would be 0 If the user input is -2, the output would be 0 You should write and...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT