Python Forum
Python - Analyzing for even intergers and multiples
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python - Analyzing for even intergers and multiples
#1
Hi everyone. I'm having difficulty with an assignment today. Reviewing my textbook, I'm missing any information regarding calculating if an imputed integer is even and a multiple of a specific number.

What I figure I have to do is divide the integer the user inputed by 2 to figure if it's even. However, I don't know how to get past that.

Here is the assignment at hand...

Quote:This program should prompt the user to enter an even integer that is an exact multiple of either 13 or 19. The program should analyze the input and display a congratulatory response for good inputs and informative responses for bad ones. For correct user input, the program should also display the other factor. See sample runs below.

Sample Runs
Enter an even multiple of 13 or 19 381
No. Not EVEN and misses multiple requirement

Enter an even multiple of 13 or 19 247
No. Multiple okay but not EVEN

Enter an even multiple of 13 or 19 260
Good, 260 is 13 * 20.0

def main():
number = int(input('Enter an even multiple of 13 or 19 '))

if number // 13 or 19 == 





main()
Any tips?
Reply
#2
A way to test for whether a number is even or not, is to use the "%" operator.

is_even = int(input("Enter a number: "))
if is_even % 2 == 0:
    print("True")
else:
    print("False")
You still need a way to keep asking the user to input an even number, if in fact, they enter 0 (zero), an odd number, or any non-integer response. Then print out the result in the required format.

Also, watch you indentation, Python is verity strict about it.
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Reply
#3
Or you can do bitwise AND against 1:
In [1]: nums = list(range(1,10))

In [2]: for num in nums:
   ...:     if 1 & num:
   ...:         print(num, "Odd")
   ...:     else:
   ...:         print(num, "Even")
   ...:         
1 Odd
2 Even
3 Odd
4 Even
5 Odd
6 Even
7 Odd
8 Even
9 Odd
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Analyzing data seperated by commas Kappel 2 1,912 Aug-07-2019, 01:46 PM
Last Post: ThomasL
  multiples of 3, smaller than 100 sonxy 1 2,498 Mar-27-2018, 10:56 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020