Tips

Questions⇨

Day 1
Q1. WAP to print the first 10 natural numbers.
Q2. WAP to print the first 10 natural numbers in descending order.
Q3. WAP to print a table of a number(Accept number from the user).
Q4. WAP to print all even numbers between 10 to 30.
Q5. WAP to print all odd numbers between 50 to 60.

Day 2
Q1. WAP to print the sum of the first 10 natural numbers.
Q2. WAP to print the sum of all numbers between two numbers taken from the user.
Q3. Write a program to print factors of a number
Q4. WAP to print factorial of a number

Day 1
Q1. WAP to print the first 10 natural numbers.

For Loop -

num = 10
for x in range(1, num+1, 1):
    print(x)

While Loop-

num = 1
while(num<=10):
    print(num)
    num += 1

Q2. WAP to print the first 10 natural numbers in descending order.

For Loop-

num = 1
for x in range(10, num-1, -1):
    print(x)

While Loop-

num = 10
while(num>=1):
    print (num)
    num = num-1

Q3. WAP to print table of a number(Accept number from the user).

For Loop-

num = int(input("Enter Number"))
for i in range(1,11):
    print(num, "*", i, "=", num*i)

While Loop-

num = int(input("Enter Number"))
i = 1
while(i<=10):
    print(num, "*", i, "=", num*i)
    i = i+1
 
Q4. WAP to print all even numbers between 10 to 30.

For Loop-

for i in range(10, 31, 2%i):
    print(i)

While Loop-

i = 10
while(i<=30):
    print(i)
    i+=2

Q5. WAP to print all odd numbers between 50 to 60.

For Loop-

for i in range(50, 61):
        if i%2 != 0:
            print(i)

While Loop-

i = 50
while(i<=60):
    if i%2 != 0:
        print(i) 
    i+=1

2nd DAY
1. WAP to print the sum of the first 10 natural numbers.

For Loop- 

sum = 0
for i in range(1, 11):
    add = add+i
print(add)

While Loop-

num = 10
add = 0
while(num>0):
    add = add +num
    num = num-1
print(add)  
 
2. WAP to print the sum of all numbers between two numbers taken from the user.

For Loop-

first = int(input("Write 1st No."))
second = int(input("Write 2nd No."))

add = 0
for i in range(first, second+1):
    add = add+i
print(add)

While Loop-

first = int(input("Write 1st No."))
second = int(input("Write 2nd No."))

add = 0
while(first<=second):
    add = add+second
    second = second-1
print(add)

3. Write a program to print factors of a number

For Loop-

num = int(input("Enter No."))
for x in range(1, num+1):
    if num%x == 0:
        print(x)  

While Loop-

value = 1
num = int(input("Enter No."))
while(value<=num):
    if num%value == 0:
        print(value)
    value = value+1

4. WAP to print factorial of a number

For Loop-

num = int(input("Print No."))
fact = 1
for i in range(1, num+1):
    fact = fact*i
print(fact)

While Loop- 

num = int(input("Print No."))
fact = 1
i = 1
while(fact<=num):
    fact = fact*i
    i = i+1
print(fact)

End Of Questions.....

Hope you liked this tutorial.

Don't forget to Follow, Like, and Comment on my Social Pages ➤ Twitter ➤ Instagram ➤ Facebook

Thanks,

Dheeraj

Comments