程序检查数字是否为正,负,奇,偶,零?
给定数字,我们必须检查数字是偶数还是奇数,以及正数还是负数。
算法
Step 1: input number Step 2: check number is greater than equal to 0 or not. If true then positive otherwise negative and if it 0 then number is 0. Step 3: if number is divisible by 2 then it’s even otherwise its odd.
范例程式码
# Python program check if a number is Positive, Negative, Odd, Even, Zero
n=int(input("Enter Number ::>"))
if n >= 0:
if n == 0:
print("The Number Is Zero")
else:
print("This Is Positive Number")
else:
print("This Is Negative Number")
# checking for odd and even
if (n % 2) == 0:
print("{0} is Even".format(n))
else:
print("{0} is Odd".format(n))输出结果
Enter Number ::>20 This Is Positive Number 20 is Even
热门推荐
10 老公生日祝福语简短好看
11 枣庄人事考试祝福语简短
12 简短创意祝福语有什么
13 阳历新年祝福语大全 简短
14 朋友结婚致辞祝福语简短
15 毕业祝福语简短英语小学
16 出院祝福语简短8字
17 朋友弟弟生日祝福语简短
18 免费生日祝福语简短独特