0% found this document useful (0 votes)
48 views

Class VIII Python Programs

The document contains 9 questions asking to write Python programs to perform various tasks like checking if a number is positive or negative, checking if a character is a vowel or consonant, checking if a number is even or odd, performing basic mathematical operations based on user input, calculating the sum and printing even/odd numbers within a range, printing the Fibonacci series, and writing HTML code to create a web page with frames and hyperlinks. Sample code is provided for each question to demonstrate how to write the program.

Uploaded by

Virendra Mishra
Copyright
© © All Rights Reserved
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views

Class VIII Python Programs

The document contains 9 questions asking to write Python programs to perform various tasks like checking if a number is positive or negative, checking if a character is a vowel or consonant, checking if a number is even or odd, performing basic mathematical operations based on user input, calculating the sum and printing even/odd numbers within a range, printing the Fibonacci series, and writing HTML code to create a web page with frames and hyperlinks. Sample code is provided for each question to demonstrate how to write the program.

Uploaded by

Virendra Mishra
Copyright
© © All Rights Reserved
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 5

Q.

1 Write a Python program to check whether a number given by user is a positive or


negative number.

Ans a=int(input("Enter any number:")

if a>0:

print("Positive")

else:

print("Negative")

Q. 2 Write a Python program to check whether a user given character is a vowel or consonant.

Ans ch=input("Enter any character:")

if ch=='a' or ch=='e' or ch=='i' or ch=='o' or ch=='u':

print("Vowel")

else:

print("Consonant")

Q. 3 Write a Python program to check whether a number given by user is an even or odd
number.

Ans a=int(input("Enter any number:")

if a%2==0:

print("Even")

else:

print("Odd")

Q. 4 Write a Python program to input two numbers and an operator from the user. Show the
result of calculation on the basis of operator entered by the user.[if operator is '+' then numbers
should be added and result should be displayed, if the operator is '-' then the difference should be
displayed etc.

Ans n1=int(input("Enter first number "))

n2=int(input("Enter second number "))

op=input("Enter any operator ")

if op=='+':

print(n1+n2)

elif op=='-':

print(n1-n2)

if op=='*':

print(n1*n2)

if op=='/':

print(n1/n2)

else:

print("Invalid operator!")

Q. 5 Write a Python program to print the sum of 10 numbers entered by the user.

Ans sum=0

for i in range(1, 11, 1):

n1=int(input("Enter any number "))

sum=sum+n1

print("Sum of 10 numbers ", sum)

Q. 6 Write a Python program to print all the even numbers in the range entered by the user.

Ans lower_limit = int(input("Enter your lower limit "))

upper_limit = int(input("Enter your upper limit "))


for i in range(lower_limit, upper_limit+1, 1):

if i%2==0:

print(i)

Q. 7 Write a Python program to print all the odd numbers in the range entered by the user.

Ans lower_limit = int(input("Enter your lower limit "))

upper_limit = int(input("Enter your upper limit "))

for i in range(lower_limit, upper_limit+1, 1):

if i%2!=0:

print(i)

Q. 8 Write a Python program to print Fibonacci series. [A Fibonacci series looks like 0, 1, 1, 2,
3, 5, 8, 13,…….]

Ans n=int(input("Enter the number of terms you want to print in the Series"))

a=0

b=1

print(a,b)

for i in range(1,n+1,1):

c=a+b

a=b

b=c

print(c)

Q. 9 Write an HTML code to create a web page with the following functionalities. Use of CSS
is expected:

1. The background colour of the page should be orange and the text colour should be
brown.

2. The page should be divided into three frames. Each frame should display three
different pages as mypage1.html, mypage2.html and mypage3.html.

3. Frames should have a border of your choice.

4. There should be a “NEXT” hyperlink created on the top of the page using which you
can switch to another web page “NewWebPage.html”.

Ans <HTML>

<HEAD><TITLE>Good Morning to All</TITLE>

<STYLE TYPE="TEXT/CSS">

body{background-color:orange;color:brown}

iframe{ border:5px solid blue}

</STYLE>

</HEAD>

<BODY>

<A HREF="NewWebPage.html">NEXT</A>

<IFRAME SRC="mypage1.html" height=200 width=300></IFRAME>

<IFRAME SRC="mypage2.html" height=400 width=500></IFRAME>

<IFRAME SRC="mypage3.html" height=300 width=400></IFRAME>

<A HREF
</BODY>

</HTML>

You might also like