Exercise to Learn selections in programming
Write a function to return a string to print whether a given number is positive or negative and odd or even.
Python Function to print whether a given number is positive or negative and odd or even
Program #function def PosnegAndOddEven(n): if (n==0): x="zero" elif((n%2)==1): x="integer is odd and " else: x="integer is even and" if (n==0): x=x elif(n>0): x=x+ " Positive" else: x=x + " Negative" return x #main print(PosnegAndOddEven(0)) print(PosnegAndOddEven(2)) print(PosnegAndOddEven(-5)) Output zero integer is even and Positive integer is odd and Negative
No comments:
Post a Comment