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

Programs List - Write A Python Program To Calcula

The document provides a list of Python programs for various tasks including calculating mean, median, and mode, generating random numbers, performing mathematical operations, determining triangle types, printing calendars, checking vowels or consonants, and calculating electricity bills based on a slab system. Each program is accompanied by code snippets ready for use. Additionally, it includes links for further reference and customization of the electricity bill program.

Uploaded by

parvkesharwani2
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)
7 views3 pages

Programs List - Write A Python Program To Calcula

The document provides a list of Python programs for various tasks including calculating mean, median, and mode, generating random numbers, performing mathematical operations, determining triangle types, printing calendars, checking vowels or consonants, and calculating electricity bills based on a slab system. Each program is accompanied by code snippets ready for use. Additionally, it includes links for further reference and customization of the electricity bill program.

Uploaded by

parvkesharwani2
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

Programs list

Write a python program to calculate mean median mode


Write a python program to print random number using randint, randrange,random function
Write a python program to calculate sqrt,pow,ceil, floor using math module
Write a python program to print whether the triangle is isosceles Scalene or equilateral
Write a python program to print calendar using module
Write a python program to print vowel or consonants
Write a python program to print electricity bill
Python programs for all the given questions are below (ready to copy in a .py file and run).

Mean, median, mode

import statistics

data = list(map(float, input("Enter numbers (space-separated): ").split()))

mean_val = [Link](data)
median_val = [Link](data)
mode_val = [Link](data) # returns one mode (the first most common) [web:3]

print("Mean :", mean_val)


print("Median:", median_val)
print("Mode :", mode_val)

Random numbers (randint, randrange, random)

import random

print("randint(1, 10) :", [Link](1, 10)) # inclusive range [web:9]


print("randrange(1, 10):", [Link](1, 10)) # 10 excluded
print("random() :", [Link]()) # float in [0.0, 1.0)

sqrt, pow, ceil, floor (math module)

import math

x = float(input("Enter a number: "))


print("sqrt(x) :", [Link](x))
print("pow(x,2):", [Link](x, 2))
print("ceil(x) :", [Link](x)) # requires math module [web:7]
print("floor(x):", [Link](x)) # requires math module [web:7]

Triangle type (isosceles / scalene / equilateral)

a = float(input("Enter side a: "))


b = float(input("Enter side b: "))
c = float(input("Enter side c: "))

# Validate triangle
if a + b <= c or a + c <= b or b + c <= a:
print("Not a valid triangle")
else:
if a == b == c:
print("Equilateral triangle")
elif a == b or b == c or a == c:
print("Isosceles triangle")
else:
print("Scalene triangle")

Print calendar (calendar module)

import calendar

year = int(input("Enter year: "))


month = int(input("Enter month (1-12): "))

print([Link](year, month)) # prints month calendar text [web:12][web:13]

Vowel or consonant

ch = input("Enter a single alphabet: ").strip()

if len(ch) != 1 or not [Link]():


print("Invalid input")
else:
if [Link]() in {'a', 'e', 'i', 'o', 'u'}:
print("Vowel")
else:
print("Consonant")

Electricity bill (slab-based)


This uses a common school-style slab system: first 50 units at 0.50, next 120 at 0.85, next 130
at 1.20, above 300 at 1.75. [1]
units = float(input("Enter units consumed: "))
bill = 0.0

if units <= 50:


bill = units * 0.50
elif units <= 170: # 50 + 120
bill = (50 * 0.50) + ((units - 50) * 0.85)
elif units <= 300: # 50 + 120 + 130
bill = (50 * 0.50) + (120 * 0.85) + ((units - 170) * 1.20)
else:
bill = (50 * 0.50) + (120 * 0.85) + (130 * 1.20) + ((units - 300) * 1.75)

print("Electricity Bill = Rs.", round(bill, 2))

Want the electricity bill program as per your state board/MP electricity slab (different slabs and
fixed charges)?

1. [Link]
2. [Link]
3. [Link]
4. [Link]
5. [Link]
6. [Link]
7. [Link]
8. [Link]
9. [Link]
10. [Link]
11. [Link]
12. [Link]
13. [Link]
14. [Link]
15. [Link]
16. [Link]
17. [Link]
18. [Link]
19. [Link]
20. [Link]
atsheet

You might also like