Page 322 - Artificial Intellegence_v2.0_Class_9
P. 322
i = 1 1
while i < 6: 2
print(i) 3
i += 1 4
5
#input a number and check for enter a number :3
#even or odd. The whole process 3 is Odd
#should continue till the user wants Press 'y' to continue :y
ans = "y" enter a number :6
while ans=="y": 6 is Even
num=int(input("enter a number :")) Press 'y' to continue :y
if num%2==0: enter a number :12
print(num," is Even") 12 is Even
else: Press 'y' to continue :n
print(num," is Odd") Program ends here
ans=input("Press 'y' to continue :")
print("Program ends here")
#display the digits of a number Enter a number 594
#in a reverse order 4
num=int(input("Enter a number ")) 9
while num>0: 5
r=num%10
print(r)
num//=10
Program 9: To print the sum of first five natural numbers.
Algorithm
Start
num=1
sum=0
while num is less than 6
sum=sum + num
num = num + 1
Display "Sum is ", sum
Stop
320 Touchpad Artificial Intelligence (Ver. 2.0)-IX

