Question

I'm trying to run the code in Python below and keep getting invalid syntax. What's wrong?...

I'm trying to run the code in Python below and keep getting invalid syntax. What's wrong? Thanks for any help!

def even(n):
if n%2==0

#Enter a Number


def main():
n=int(input("Enter a number: "))

#If even print "Number is even"

if(even(n)):
print("The number is even")

#If odd print "Number is odd"

else:
print("The number is odd")

main() #Call the main function

0 0
Add a comment Improve this question Transcribed image text
Answer #1
def even(n):
    if n%2==0:
        return True
    else:
        return False
        
        
#Enter a Number
def main():
    n=int(input("Enter a number: "))
    #If even print "Number is even"
    if(even(n)):
        print("The number is even")
    #If odd print "Number is odd"
    else:
        print("The number is odd")

main() #Call the main function

Add a comment
Know the answer?
Add Answer to:
I'm trying to run the code in Python below and keep getting invalid syntax. What's wrong?...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • THIS IS THE CODE I AM TRYING TO RUN code # def main():       #Reading a as...

    THIS IS THE CODE I AM TRYING TO RUN code # def main():       #Reading a as an integer       a = int(input("Enter value for a: "))       #reading b as an interger       b = int(input("Enter value for b: "))       #reading n as an integer       n = int(input("Enter value for n: "))       # displaying if a and b are congruent modulo n, this is True if a and b       #both returns same remainder when divided by n       if a % n == b...

  • while trying to run this in python, i keep getting the error TypeError: int() can't convert...

    while trying to run this in python, i keep getting the error TypeError: int() can't convert non-string with explicit base. any way to fix this? def binaryToDecimal(n): return int(n,2) if __name__ == '__main__': num3 = int(input("Enter value to be converted: ")) print(binaryToDecimal(num3))

  • In Python, please change this function so if someone inputs an invalid age (string, float, number...

    In Python, please change this function so if someone inputs an invalid age (string, float, number below 0), print "wrong". Use the "isdigit()" function -------------------------- def age_name(): name = input("Enter name:") age = int(input("Enter age:")) print("Hello", name) if(age <= 18): print("Child") elif(age <= 64): print("Adult") else: print("Senior")

  • I'm trying to simply print hello world but it's giving me invalid syntax when I try...

    I'm trying to simply print hello world but it's giving me invalid syntax when I try to run it from the terminal and I dont understand why. python ./age.py Desktop File "./age.py", line 1 >>> print('Hello World') SyntaxError: invalid syntax

  • (python) [30] Implement exception handling with ValueError here in the following code: There are three blanks...

    (python) [30] Implement exception handling with ValueError here in the following code: There are three blanks you need to fill in. Write the answers in the space given for you. class Area: def __init__(self): self.x = 0 def setX(self n): if n<=0: else: self.x = n #main code a = Areal) inputValue = int(input("Enter a Value that is greater than 0")) a.setX(inputValue) print("Invalid Input Value Entered")

  • What's wrong with my code? : I'm trying to use recursive functions to display and count...

    What's wrong with my code? : I'm trying to use recursive functions to display and count all the even numbers of an array. However, I can't seem get the program output the number of even integers . Here's the output I want: Here are the 5 even numbers: // Luckily, however, my code does output all the even numbers. But, I also want the program to tell me how may even integers there are. 2 8 14 18 22 MY...

  • IN PYTHON: The following code contains syntax errors. Assuming the code should read in a name,...

    IN PYTHON: The following code contains syntax errors. Assuming the code should read in a name, and output a message indicating if the last name is "Smith". REWRITE THIS STATEMENT CORRECTLY. value = input(" enter your name using LAST, FIRST format") val= value.split(",") if value[0] ="Smith": print("your last name is common") else val[0] != "Smith": print("not so common") print(]"ODD")

  • 1. Questions Python Code: For each line of code, write the type of error (syntax, semantics,...

    1. Questions Python Code: For each line of code, write the type of error (syntax, semantics, runt-time), cause of the error, and your fix. (1) def fun(num letter) (2) num == 7 + num (3) return 'num' - letter (4) result = fun(5, x) 2. Question Python Code: Run the code below to check the outputs of the print() call on lines 12. And : A) Analyze the application of the accumulation pattern and answer the following questions: #1. a....

  • : back to classroom run Instructions from your teacher: import random def get_message(user_num, rand_num): Eo von...

    : back to classroom run Instructions from your teacher: import random def get_message(user_num, rand_num): Eo von AwNP Complete the get_message function so if user_num is equal to rand_num, return "You picked the same number as the computer!" if user_num is less than rand_num, return "Your number is smaller than the computer's number." if user_num is greater than rand_num, return "Your number is higher than the computer's number." Comment out the call to main when trying to pass the tests. 11...

  • I'm trying to sort a list of students from a text file in python(3.7) with three separate sorting functions (Bubble, selection, insert) I'm not sure to why as its not working I'm going to...

    I'm trying to sort a list of students from a text file in python(3.7) with three separate sorting functions (Bubble, selection, insert) I'm not sure to why as its not working I'm going to guess its because I'm not using the swap function I built. Every time I run it though I get an error that says the following Traceback (most recent call last): File "C:/Users/tkoto/Desktop/SearchAndSortLab.py", line 146, in <module> main() File "C:/Users/tkoto/Desktop/SearchAndSortLab.py", line 122, in main studentArray.gpaSort() File "C:/Users/tkoto/Desktop/SearchAndSortLab.py",...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT