##### Use if with and function?
 Use if with and function? ibutun Programmer named Tim Posts: 10 Threads: 1 Joined: May 2020 Reputation: May-30-2020, 05:42 PM Hi members, i am new here and I have so many requests in phyton to learn... Please help me... i write a code like this but not working ```num = input("Please enter a number: ") if num.isalpha(): print(f"{num} is not a number.") elif type(num) == int and (num %2) == 0: #If the value entered is a number and divided by two, print(f"{num} çift sayıdır") #say it as an even number else: print(f"{num} is an odd number")```why this code not working... if i enter 4 , it says is an odd number... (this is false) if i enter 5, it says is an odd number... if i enter a, it says is not a number... how do i fix it? Reply ndc85430 Da Bishop Posts: 1,356 Threads: 1 Joined: Apr 2017 Reputation: May-30-2020, 05:48 PM (This post was last modified: May-30-2020, 05:50 PM by ndc85430.) `input` returns a string. You need to convert the value to an int, with the `int` function. Note that that function will throw an exception if the value can't be converted to a number (in base 19 by default). Reply ibutun Programmer named Tim Posts: 10 Threads: 1 Joined: May 2020 Reputation: May-30-2020, 05:55 PM (This post was last modified: May-30-2020, 05:55 PM by ibutun.) i wrote like this; ```num = int(input("Please enter a number: ")) if num %2 == 0: #If the value entered is a number and divided by two, print(f"{num} is an even number") #say it as an even number else: print(f"{num} is an odd number")```but if some one make a mistake and enter a string , i want to warm Reply menator01 Minister of Silly Walks Posts: 415 Threads: 61 Joined: Sep 2019 Reputation: May-30-2020, 05:56 PM Format ```try input number if even number do something else not even number do something except not number``` I welcome all feedback. The only dumb question, is one that doesn't get asked. Gaming Collection Homepage my-python Reply pyzyx3qwerty Minister of Silly Walks Posts: 356 Threads: 13 Joined: Mar 2020 Reputation: May-30-2020, 05:57 PM See this post pyzyx3qwerty "The greatest glory in living lies not in never falling, but in rising every time we fall." - Nelson Mandela Need help on the forum? Visit help @ python forum For learning more and more about python, visit Python docs Reply ibutun Programmer named Tim Posts: 10 Threads: 1 Joined: May 2020 Reputation: May-30-2020, 06:35 PM (This post was last modified: May-30-2020, 06:49 PM by ibutun.) (May-30-2020, 05:56 PM)menator01 Wrote: Format ```try input number if even number do something else not even number do something except not number``` Thank you very much for helping friend. This was my first program :) And i write correct code here for help others ```num = input("Enter a number: ") try: num = int(num) if num %2 == 0: print(f"{num} is an even number") else: print(f"{num} is an odd number") except ValueError: print(f"{num} isn't a number. Please enter a number!")``` (May-30-2020, 05:57 PM)pyzyx3qwerty Wrote: See this post This is awesome bro... Not i add while to my code and when i enter "str", my code start over again... İ am very happy today yuppiiiii :D Last edited version: ```while True: num = input("Enter a number: ") try: num = int(num) if num %2 == 0: print(f"{num} is an even number") else: print(f"{num} is an odd number") break except ValueError: print(f"{num} isn't a number. Please enter a number!")``` Reply

Forum Jump:

### User Panel Messages

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