0% found this document useful (0 votes)
2 views3 pages

Class VIII Code

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views3 pages

Class VIII Code

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

#WAP to check whether a given number is divisible by 5 or not

n = int(input("Enter a number: "))


if n%5 == 0:
print("Number is divisible by 5")
else:
print("Number is not divisible by 5")

#WAP to compute the factorial of the given number.


n = int(input("Enter the number: "))
fact = 1
for i in range(1,n+1):
fact = fact * i
print("The factorial is: ",fact)

#WAP to Print the multiplication table of 25 using while loop


i = 1
while i<=10:
print("25 * ",i," = ", 25*i)
i=i+1

#Check whether a person is retired or not.


age = int(input("Enter your age: "))
if age > 60:
print("Retired")
else:
print("Not Retired")

#Grading system
marks = int(input("Enter marks: "))
if marks < 20:
print("Grade F")
elif marks <= 40:
print("Grade E")
elif marks <= 60:
print("Grade D")
elif marks <= 80:
print("Grade C")
elif marks <= 90:
print("Grade B")
else:
print("Grade A")

#Print the Pattern


'''
55555
4444
333
22
1
'''
for i in range(5,0,-1):
for j in range(1,i+1):
print(i,end="")
print()

#WAP to display the alternate number in a given range


lower = int(input("Enter the lower range: "))
upper = int(input("Enter the upper range: "))
for i in range(lower, upper+1, 2):
print(i)

#WAP to display the digit of a number


n = input("Enter the digit: ")
for i in n:
print(i)

#Display sum of even and odd numbers separately in a given range


start = int(input("Enter start: "))
end = int(input("Enter end: "))
even_sum = 0
odd_sum = 0
for i in range(start, end + 1):
if i % 2 == 0:
even_sum += i
else:
odd_sum += i
print("Sum of even numbers:", even_sum)
print("Sum of odd numbers:", odd_sum)

#Display numbers divisible by 4 and stop if number > 100


lst = [18, 13, 16, 24, 35, 50, 60, 72, 75, 100, 120, 160]
for i in lst:
if i > 100:
break
if i % 4 == 0:
print(i)

#Count total digits in the number 542892.


num = 542892
count = 0
while num > 0:
count += 1
num //= 10
print("Total digits:", count)

#Print list items in reverse order


lst = [25, 35, 45, 55, 65, 75]
lst1 = [Link]()
print(lst1)
#Capitalize first & last letter of your name
name = input("Enter your name: ")
result = name[0].upper() + name[1:-1].lower() + name[-1].upper()
print(result)

You might also like