Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conditionals #269

Open
coded92 opened this issue Feb 26, 2018 · 3 comments
Open

Conditionals #269

coded92 opened this issue Feb 26, 2018 · 3 comments

Comments

@coded92
Copy link

coded92 commented Feb 26, 2018

Please can you help solve this in Python and explain to me

mystery_int_1 = 7
mystery_int_2 = 2

You may modify the lines of code above, but don't move them! When you Submit your code, we'll change these lines to assign different values to the variables.

The variables below hold two integers, mystery_int_1 and
mystery_int_2. Complete this program below such that it
prints "Factors!" if either of the numbers is a factor of the other. If neither number is a factor of the other, do not print anything.

Hint: You can do this with just one conditional statement
by using the logical expressions (and, or, and not). You'll also use the modulus operator

Please help me with the Add your code here!

Have tried several means am just not getting it

@lionpower7
Copy link

Answer: For Python.

mystery_int_1 = int()
mystery_int_2 = int()

mystery_int_1 = input("Enter a Number:")
mystery_int_2 = input("Enter another Number:")

if mystery_int_1 % mystery_int_2 == 0 or mystery_int_2 % mystery_int_1 ==0:
print("Factors!")
else:
print(" ")

@UHungLin
Copy link

UHungLin commented May 1, 2018

Answer by Python.

mystery_int_1 = int( input("Enter a Number: "))
mystery_int_2 = int(input("Enter another Number: "))

if mystery_int_1 or mystery_int_2 == 0:
    print("Factors!")
elif mystery_int_1 % mystery_int_2 == 0 or mystery_int_2 % mystery_int_1 ==0:
    print("Factors!")
else:
    print(" ")

@19ANDY
Copy link

19ANDY commented May 14, 2018

In this the variables are assigned the value which you have given and hence the code:

mystery_int_1, mystery_int_2 = 7, 2
print("Factors!" if mystery_int_1%mystery_int_2 ==0 or mystery_int_2%mystery_int_1==0 else " ")

But if the user wants to enter the number then the code would be :

mystery_int_1, mystery_int_2 = int( input("")), int(input(""))
print("Factors!" if mystery_int_1%mystery_int_2 ==0 or mystery_int_2%mystery_int_1==0 else " ")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants