Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

Python Check if Python variable is greater than a number

hi,
I am learning python, and when I am trying practice exercises I came across the following question:

Given a two integer numbers return their product and if the product is greater than 1000, then return their sum.​


this is the code I tried:

Python:
while True:
    x=input('no 1')
    y=input('no 2')
    z = x*y
    if z >> 1000 == True:
        print(x+y)
    else:
        print(x*y)

I don't understand where i went wrong. the problem is it show only the product in any case.
Any help?
Thanks
 
Last edited by a moderator:
the important difference is in if command. I replaced if z >> 1000 == True: with if z > 1000:. I really don't know what >> operator does in Python. Comparison operators should be ==, >, >=, <, <=, or !=. if (z > 1000) == True: could work, but == True part is not necessary.

By the way, this is my first program in Python. You should test it. I'd like to know if it worked.
 
Last edited:
Can you please do it? Some of your posts are still raw code and your title hasn't been changed. I can't really do it, as I'm not sure what you're looking for.
The correct title / question should probably be "Check if Python variable is greater than a number" or "How to use Python greater than math operator"
 

New Threads

Latest posts

Buy us a coffee!

Back
Top Bottom