1.Write a Program to print first 10 natural numbers?
2.Write a Program to print first 10 even numbers?
#printing 10 natural numbers
for i in range(1,11):
print(i)
#printing 10 even numbers
for i in range(0,10):
print(i*2)
-
For i in range(1,11):
print(i) -
For i in range(1,21):
i%2==0:
print(i)
i=1
while(i<=10):
print(i)
i+=1
-
user = int(input(“enter”))
for i in range(1,user)
print(i) -
user = int(input(“enter”))
for i in range(0,user):
if i% 2==0:
print(i)
print(‘first 10 natural numbers ‘)
for i in range(1,11):
print(i,end=’ ‘)
print(’\n’)
print('first 10 even numbers ‘)
for i in range(1,11):
if(i%2==0):
print(i,end=’ ')
txt=int(input("enter the number: "))
json=1
while json<=txt:
if json%2==0:
print(json,end=" ")
json+=1
-
i =1
while (i <= 10):
print(i)
i+=1 -
i=1
while(i<=20):
i%2==0:
print(i)
i+=1
very good. keep practicing
Here, we need to get 10 even numbers, please check on the reply for the correct solution. good try, keep it up
Very good. please try the second question as well.
Very good, but here the question is first 10 numbers
actually you could use someother name instead of json, as we have file in the name of json, yout code will print only the even numbers. please solve the 1st question as well
Good. but here you will not get 10 even numbers
Q1
for num in range(0, 10):
print(num)
Q2
nums = 1
count = 0
stop = 10
check = True
while check:
if(nums % 2 == 0 and count <= stop):
print(nums)
count += 1
elif(count >= stop):
check = False
nums += 1
@sindiya55
yes - i thought even numbers of 1st 10 numbers - so i mention range upto 11
if we need 1st 10 even numbers - I need double the range from 11 to 21
then code will be as follow
print('first 10 even numbers ‘)
for i in range(1,21):
if(i%2==0):
print(i,end=’ ')
yes. you are right.good to go
first 10 natural numbers
n = int(input(“enter the value of n :”))
sum = 0
for i in range (1, n+1):
sum = sum + 1
print(“i”, i)
print(“sum”, sum)
print(“The sum of {n} natural numbers is”)
first 10 even numbers
num = int(input(“enter the even number :”))
for num in range(1,20):
if num%2==0:
print(num)
#first 10 natural numbrs
for a in range(1,11)
print(a)
#first 10 even number
count = 0
num = 0
while count<10:
if num %2==0 :
print(num)
count += 1
num += 1
both answers provided individually. moreover the question is to write program on even numbers only. but why you are saying it will only print even numbers. is there any mistake in the code…?