Skip to content
  • रक्षा
  • इंडिया
  • खेल जगत
  • हेल्थ
  • स्टोरीज
  • शिक्षा
  • स्थानीय
global news and facts

Global News and facts

  • रक्षा
  • इंडिया
  • खेल जगत
  • हेल्थ
  • स्टोरीज
  • शिक्षा
  • स्थानीय
    • देवरिया
    • पूर्वांचल
    • सलेमपुर
  • Toggle search form
  • sahodaya deoria
    छात्र-छात्राओं के सर्वांगीण विकास हेतु हुई सहोदया देवरिया की महत्वपूर्ण बैठक । सहोदया देवरिया की मीटिंग में लिए गए महत्वपूर्ण फैसले देवरिया
  • globalnewsandfacts
    लेफ्टिनेंट का पद अर्जित कर खानदान की लगातार तीसरी पीढ़ी का सितारा बने विवेक, प्रधानाचार्य जी.एम.एकेडमी भी सभी अध्यापक संग रहे उपस्थित । उत्तरप्रदेश
  • सर्वजन समागम महराजगंज कार्यक्रम में मंचासीन अतिथि और FRCT टीम
    सर्वजन समागम महराजगंज में उमड़ा सर्वजन का जन सैलाव, FRCT टीम ने किया ऐतिहासिक सहयोग उत्तरप्रदेश
  • deoria
    देवरिया का विकास : 1946 से 2025 तक की भौगोलिक, राजनीतिक, सांस्कृतिक और आर्थिक यात्रा देवरिया
  • Adikarmyogi Abhiyan
    प्रधानमंत्री मोदी के नेतृत्व में शुरू हुआ “आदि कर्मयोगी अभियान”: दुनिया का सबसे बड़ा जनजातीय नेतृत्व और उत्तरदायी शासन कार्यक्रम देवरिया
  • har ghar tiranga
    राष्ट्र के प्रति अपने कर्तव्यों को अवश्य करें पालन-प्रधानाचार्य । जी एम एकेडमी में स्वतंत्रता सप्ताह पर, हर घर तिरंगा के तहत आयोजित हुए विविध कार्यक्रम । सलेमपुर
  • छठ पूजा
    जी एम एकेडमी में धूमधाम से मनाया गया लोक आस्था का महापर्व “छठ पूजा” सलेमपुर
  • संस्कृत भारती
    संस्कृत भारती की गोष्ठी में आगामी कार्यक्रमों पर हुई चर्चा देवरिया
python examples globalnewsandfacts

Python : Sample Examples and their solutions level Medium

Posted on November 2, 2024November 12, 2024 By Pramod Kumar No Comments on Python : Sample Examples and their solutions level Medium
Spread the love

Python : Sample Examples and their solutions level Class 7

Table of Contents

Toggle
  • Example 1. Write a Python program to accept alphabet from the user and display whether it it a vowel or consonant.
  • Example 2. Write a Python program to accept a number from the user and display whether it is a multiple of 7 or not.
  • Example 3. Write a Python program to accept three number from the user and display the product of the number with the message whether the product is even or odd.
  • Example 4. Write a Python program to accept two number and an operator from the user (+,-,*,/) and display the corresponding result of the operator.
  • Example 5. Write a Python program to the number of units of electricity consumed by a user in a month and calculate and display his bill . The criteria used for the calculation of the bill are as follows. Criteria Number of Units upto 200 – cost rs 0 from 201 to 300 – cost rs 5 , from 301 to 500 – cost rs 6, from 501 to above – cost rs 7
  • Example 6. Write a Python program to accept the length and breadth of a rectangle from the user and display its area and perimeter.
  • Example 7. Write a Python program to accept distance from the user in meters and convert it into kilometers and metres.
  • Example 8. Write a Python program to accept three numbers from the user and display their sum and product.
  • Example 9. Write a Python program to accept three sides of a triangle from the user and display its perimeter.
  • Example 10. Write a Python program to accept a number from the user and display its square and cube using operators.
  • Example 11. Write a Python program to accept a two numbers from the user and display their sum , product, difference, and quotient.
  • Example 12. Write a Python program to accept a number from 1 to 12 from the user and display the month of the year corresponding to the number entered. Assume to represent january, 2 to represent February, and so on.
  • Example 13. Write a Python program to accept a year in four digits from the user. Display whether the year will have 365 days or 366 days.
  • Example 14. Write a Python program to accept a year in four digits from the user. Display whether the year will have 365 days or 366 days.
  • Example 15. Write a Python program to accept two numbers from the user and check if the smaller number is a factor of the larger number or not.
  • Example 16. Write a Python program to display sequence 5, 8, 11, 14 ….up to 76.
  • Example 17. Write a Python program to accept a number from the user and display its table.
  • Example 18. Write a Python program to accept two number from the user and display all even numbers between the two numbers in decreasing order.
  • Example 19. Write a Python program to calculate and display the sum of first 10 multiples of 3.
  • Example 20. Write a Python program to accept three numbers from the user and display all even numbers between the smallest ans largest numbers, excluding the multiple of the third number.
  • Example 21. Write a Python program to accept a number from the user and display the daof the week corresponding to the number. (1 represents Monday , 2 represent Tuesday, and so on). Display an error message in case of a number different from 1,2,3,4,5,6, and 7.
  • Example 22. Write the output of the following expressions or code segment in python:
  • Question 23. Identify and underline the errors in the code given below. Also write the correct code.

Example 1. Write a Python program to accept alphabet from the user and display whether it it a vowel or consonant.

Solution:

alpha = input(“Enter an alphabet:”)
alpha = alpha.lower()
if alpha in ‘aeiou’ :
print(alpha, “is a Vowel.”)
else:
print(alpha, “is a consonant”)

Example 2. Write a Python program to accept a number from the user and display whether it is a multiple of 7 or not.

Solution
num = int(input("Enter a Number :"))
if num % 7 ==0 :
print( num, "is a Multiple of 7.")
else:
print(num, "is not a Multiple of 7.")

Example 3. Write a Python program to accept three number from the user and display the product of the number with the message whether the product is even or odd.

Solution
number1 = int(input("Enter the first Number : "))
number2 = int(input("Enter the Second Number : "))
number3 = int(input("Enter the Third Number : "))
product = number1 * number2 * number3
if product % 2 == 0 :
print("The product- ", product , "is Even.")
else :
print("The product- ", product , "is Odd.")

Example 4. Write a Python program to accept two number and an operator from the user (+,-,*,/) and display the corresponding result of the operator.

Solution
number1 = float(input("Enter First Number : "))
number2 = float(input("Enter Second Number : "))
operator = input("Enter an operator like +, -, , / :")
if operator == '+' :
result = number1 + number2
print("Result of " , number1 , operator , number2, " is :" , result)
elif operator == '-' :
result = number1 - number2
print("Result of " , number1 , operator , number2, " is :" , result)
elif operator == '' :
result = number1 * number2
print("Result of " , number1 , operator , number2, " is :" , result)
elif operator == '/' :
result = number1 / number2
print("Result of " , number1 , operator , number2, " is :" , result)
else:
print(" You enter invalid / incorrect operator.")

Example 5. Write a Python program to the number of units of electricity consumed by a user in a month and calculate and display his bill . The criteria used for the calculation of the bill are as follows. Criteria Number of Units upto 200 – cost rs 0 from 201 to 300 – cost rs 5 , from 301 to 500 – cost rs 6, from 501 to above – cost rs 7

Solution
unit = int (input("Enter the Number of Unit consumed : "))
if unit < 0 :
print("unit must be positive number ")
elif unit <= 200 :
bill = 0
print(" Electricity Bill : Rs . " , bill)
elif unit <= 300 :
bill = (unit - 200) * 5
print(" Electricity Bill : Rs . " , bill)
elif unit <= 500 :
bill = (100 * 5) + ((unit - 300) * 6)
print(" Electricity Bill : Rs . " , bill)
else :
bill = (100 * 5) + (200 * 6) + ((unit - 500) * 7)
print(" Electricity Bill : Rs . " , bill)

Example 6. Write a Python program to accept the length and breadth of a rectangle from the user and display its area and perimeter.

Solution
length = float(input("Enter the Length of a Rectangle: "))
breadth = float(input("Enter the Breadth of a Rectangle: "))
area = length * breadth
perimeter = 2 * (length + breadth)
print("Area of the Rectangle is : " , area , "m")
print("Perimeter of the Rectangle is : " , perimeter , "m")

Example 7. Write a Python program to accept distance from the user in meters and convert it into kilometers and metres.

Solution
distance = float(input("Enter the distance in meters : "))
kilometer = distance / 1000
print( distance , " meter is equal to " , kilometer ,"km")

Example 8. Write a Python program to accept three numbers from the user and display their sum and product.

Solution
number1 = int(input("Enter the first number : "))
number2 = int(input("Enter the Second number : "))
number3 = int(input("Enter the third number : "))
sum = number1 + number2 + number3
product = number1 * number2 * number3
print(" The sum of the numbers is : " , sum)
print(" The product of the numbers is : " , product)

Example 9. Write a Python program to accept three sides of a triangle from the user and display its perimeter.

Solution
side1 = float(input("Enter the length of one side of Triangle : "))
side2 = float(input("Enter the length of Second side of Triangle : "))
side3 = float(input("Enter the length of Third side of Triangle : "))
perimeter = side1 + side2 + side3
print("The perimeter of the Triangle is :", perimeter)

Example 10. Write a Python program to accept a number from the user and display its square and cube using operators.

Solution
number = int(input("Enter a number : "))
square = number ** 2
cube = number ** 3
print(" The square of ", number , "is :" , square)
print(" The cube of ", number , "is :" , cube)

Example 11. Write a Python program to accept a two numbers from the user and display their sum , product, difference, and quotient.

Solution
number1 = float(input("Enter the first number: "))
number2 = float(input("Enter the second number: "))
sum = number1 + number2
product = number1 * number2
diff = number1 - number2
quotient = number1 / number2
print(" Sum of numbers is : ", sum)
print(" product of numbers is: ", product)
print("difference of number is: ", diff)
print("Quotient of number is: ", quotient)

Example 12. Write a Python program to accept a number from 1 to 12 from the user and display the month of the year corresponding to the number entered. Assume to represent january, 2 to represent February, and so on.

Solution
months = ["January", "February", "March", "April","May", "June", "July","August","September","October","November","December"]
number = int(input("Enter a number between 1-12 :"))
if 1 <= number <= 12:
print("The month is : " , months[number - 1])
else:
print("Invalid input! Please enter a number between 1 and 12. ")

Example 13. Write a Python program to accept a year in four digits from the user. Display whether the year will have 365 days or 366 days.

solution
year = int(input("Enter a year in four digits :"))
if (year % 4 == 0) and (year % 100 != 0) or (year % 400 ==0):
print(year , "has 366 days its a Leap Year")
else:
print( year , " has 365 days which is not Leap year . its a normal year ")

Example 14. Write a Python program to accept a year in four digits from the user. Display whether the year will have 365 days or 366 days.

solution
import math
radius = float(input("Enter the radius of the circle : "))
circum = 2 * math.pi * radius
print(" The circumference of the circle is : ", circum)

Example 15. Write a Python program to accept two numbers from the user and check if the smaller number is a factor of the larger number or not.

Solution
number1 = int (input("Enter the first number :"))
number2 = int(input("Enter the second number :"))
if number1 > number2 :
larger = number1
smaller = number2
else :
larger = number2
smaller = number1
if larger % smaller == 0 :
print( smaller , " divides the :", larger )
else:
print(smaller , " cannot divides the :", larger)

Example 16. Write a Python program to display sequence 5, 8, 11, 14 ….up to 76.

SOLUTION
startv = 5 # start value
increment = 3 #increment value
maxv = 76 # maximum value
i = startv
while i <= maxv :
print( i , end=" ")
i = i + increment

Example 17. Write a Python program to accept a number from the user and display its table.

SOLUTION
number = int(input("Enter a number to diaplay table : "))
print(" Table of Number ", number , "is below: " )
for i in range(1, 11) :
print( number , "x" , i , "=" , number * i)

Example 18. Write a Python program to accept two number from the user and display all even numbers between the two numbers in decreasing order.

SOLUTION
number1 = int(input("Enter first number : "))
number2 = int(input("Enter second number : "))
if number1 > number2 :
st = number1
end = number2
else:
st = number2
end = number1
if st % 2 != 0 :
st = st - 1
if end % 2 != 0:
end = end + 1
print(" Even numbers in decreasing orders :")
for i in range(st , end - 1 , - 2) :
print(int(i) , end=" " )

Example 19. Write a Python program to calculate and display the sum of first 10 multiples of 3.

Solution
sum = 0
for i in range(1 , 11) :
multiple = 3 * i
sum = sum + multiple
print(" The sum of the first 10 multiple of 3 is : " , sum)

Example 20. Write a Python program to accept three numbers from the user and display all even numbers between the smallest ans largest numbers, excluding the multiple of the third number.

Solution
number1 = int(input("Enter first number : "))
number2 = int(input("Enter second number : "))
number3 = int(input("Enter third number : "))
small = min(number1 , number2 , number3)
larg = max( number1 , number2 , number3)
print("Even numbers between ", small , "and" , larg , " excluding multiple of :" , number3 , " : ")
for i in range(small , larg + 1) :
if i % 2 == 0 and i % number3 != 0 :
print(i , end=" ")

Example 21. Write a Python program to accept a number from the user and display the daof the week corresponding to the number. (1 represents Monday , 2 represent Tuesday, and so on). Display an error message in case of a number different from 1,2,3,4,5,6, and 7.

Solution

day = int(input(“Enter a number 1 to 7 to get the related day of the week: “))
if day ==1 :
print(“Monday”)
elif day == 2 :
print(“Tuesday”)
elif day == 3 :
print(“Wednesday”)
elif day == 4 :
print(“Thursday”)
elif day == 5 :
print(“Friday”)
elif day == 6 :
print(“Saturday”)
elif day == 7 :
print(“Sunday”)
else :
print(” Error : Please enter number between 1 and 7 “)

Example 22. Write the output of the following expressions or code segment in python:

A) print("This is a funny statement", "Ha!" * 4)
Ans) This is a funny statement Ha!Ha!Ha!Ha!

B) print((True and False) or (True and not(False)))
Ans) True

C) print((5 ** 3) - (50 * 2) + 40 % 8)
Ans) 25

D)
x = 30
if x > 20:
print("You have a large number ")
else:
print("You have a small number ")
Ans) You have a large number

Question 23. Identify and underline the errors in the code given below. Also write the correct code.

Num1 = input(Enter first number :" )
Num2 = print("Enter second number :")
If Num1 > num2
print(" Second number is smaller")
or:
print("First number is smaller")

Ans)
Num1 = input("Enter first number :" )
Num2 = input("Enter second number :")
if Num1 > Num2 :
print(" Second number is smaller")
else:
print("First number is smaller")

Read More : Quiz for Python

Computer Tags:python programs, python sample examples and solution level class 7th

Post navigation

Previous Post: Tata Advance System (TAS) और स्पेन की Airbus मिलकर ‘मेक इन इंडिया’ के तहत गुजरात के बड़ोदरा में बनेगा दुनिया का सबसे पॉपुलर C-295 मिलिट्री ट्रासपोर्ट एयरक्राफ्ट . भारत के लिए क्यों है ख़ास ?
Next Post: Computer Python Quiz Level Class 7th

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

  • G.M. Academy के जूनियर विंग का शानदार रिज़ल्ट, अक्षत तिवारी बने ‘Student of the Year’
  • जी एम एकेडमी में गणतंत्र दिवस के साथ जनपद की सबसे बड़ी विज्ञान प्रदर्शनी “नोवा विस्टा 2026” का ऐतिहासिक आयोजन
  • जी.एम. एकेडमी सलेमपुर में श्रद्धा और उल्लास के साथ संपन्न हुआ सरस्वती पूजा समारोह
  • अंतर्राष्ट्रीय हिंदी ओलंपियाड 2025 में जी एम एकेडमी का शानदार प्रदर्शन, 37 पदक जीतकर बढ़ाया मान
  • वीर बाल दिवस पर जी.एम. एकेडमी में देशभक्ति का संचार । छात्र–छात्राओं ने प्रतिभा प्रदर्शन कर साहिबजादों को किया नमन
  • ABOUT US
  • CONTACT US
  • DESCLAIMER
  • PRIVACY POLICY
  • TERMS AND CONDITION
  • सर्वजन समागम महराजगंज कार्यक्रम में मंचासीन अतिथि और FRCT टीम
    सर्वजन समागम महराजगंज में उमड़ा सर्वजन का जन सैलाव, FRCT टीम ने किया ऐतिहासिक सहयोग उत्तरप्रदेश
  • globalnewsandfacts
    16 की उम्र में बनी स्टार, अंडरवर्ल्ड डॉन संग जुड़ा नाम, रातोंरात छोड़ दिया देश और अपने से बड़े डायरेक्टर से की शादी एंटरटेनमेंट
  • जी एम एकेडमी सलेमपुर शिक्षक दिवस समारोह
    जी एम एकेडमी में धूमधाम से मनाया गया शिक्षक दिवस बच्चों में दिखा उत्साह सलेमपुर
  • GM Academy Navratri
    जी एम एकेडमी में धूमधाम से मनाया गया नवरात्रि उत्सव । नवदुर्गा एक्ट, डांडिया-गरबा और नवरात्रि गीत ने बांधा समां । महिषासुरमर्दिनी की मनमोहक झांकी ने सबका मन मोहा सलेमपुर
  • G.M. Academy salempur
    जी एम एकेडमी शिक्षा ही नहीं, संस्कार व संस्कृति को सहेजने का केंद्र भी–लेफ्टिनेंट विवेक | Grand celebration of the 76th Republic Day was held at G.M. Academy देवरिया
  • globalnewsandfacts.in
    स्वर्गीय गौरीशंकर द्विवेदी की जयंती पर जी . एम . एकेडमी सलेमपुर में श्रद्धांजलि समारोह : शिक्षा के क्षेत्र में उनके अमूल्य योगदान को किया गया याद | स्थानीय
  • swatantrata diwas
    स्वतंत्रता दिवस की पूर्व संध्या पर हुए कार्यक्रम ने सबको झूमने पर किया बाध्य । राष्ट्रोत्थान के लिए रहें सतत् प्रयत्नशील — मोहन द्विवेदी सलेमपुर
  • Purple and White Modern Advertising Presentation 20250612 133924 0000
    हीट स्ट्रोक से बचने के लिए जानिए जरूरी उपाय: गर्मियों में तेज धूप से रहें सतर्क स्टोरी

Copyright © 2026 Global News and facts.

Powered by PressBook News WordPress theme