Ask Question

Q1: Write an algorithm that read a number from the user "assuming the number entered is always between 1-100", when the number entered is greater than 50, a variable X is incremented by 1, otherwise, a variable Y is incremented by 1. After that check the value of X and Y, if X is greater than Y then print (Most of your numbers are greater than 50), otherwise print (Most of your numbers are less than or equals to 50), Hint: the program stops when the user entered number 0

+3
Answers (1)
  1. 5 November, 11:59
    0
    import sys

    number = int (input ("Enter a number between 1 to 100 : "))

    x = 0

    y = 0

    if number = = 0:

    sys. exit ()

    elif number > 50:

    print ("Increment x value")

    x=x+1

    else:

    print ("Increment y value")

    y=y+1

    if x > y:

    print ("Most of your numbers are greater than 50")

    else:

    print ("Most of your numbers are less than or equals to 50")

    Explanation:

    In this User will be asked to input the number.

    If the number is 0 then it will exit

    If the number is greater than 50 then it will increment X

    If the number is less than 50 then it will increment Y

    Then X and Y will be compared and print command will be executed.

    Note : We can use quit and exit in place of sys. exit () as well. But make sure to use stderr as well.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Q1: Write an algorithm that read a number from the user "assuming the number entered is always between 1-100", when the number entered is ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers