As a learner, you may get to solve a lot of questions related to percentages in Python Programming in your School or College.
What is Percentage?
A percentage is a way of expressing a fraction as a portion of 100.
Examples:- 1/2 can be expressed as a percentage by multiplying it by 100 = 50%
- 4/5 can be expressed as a percentage by multiplying it by 100 = 80%
- 2/3 can be expressed as a percentage by multiplying it by 100 = 66.67%
- 7/10 can be expressed as a percentage by multiplying it by 100 = 70%
- 3/8 can be expressed as a percentage by multiplying it by 100 = 37.5%
Percentages are used in finance, statistics, and other fields to compare numbers relative to a whole.
In Python, you can calculate a percentage by multiplying a number by 100 and dividing it by another number
Program 1: If a student scored 80 out of 100 on a test, what is their percentage score?
# Marks Optained
score = 80
# Of Total Marks
total = 100
# Percentage Calculation
percentage = (score / total) * 100
# Printing the result
print(f"The Percentage scored is {percentage:.2f}%")
Output:
The Percentage scored is 80.00%
Program 2: Calculate Percentage based on user input of marks scored of total marks?
'''
Example 2:
Calculate the Percentage of Python Program
using User input
Author: Code2are.org
Date: 21-02-2023
'''
# Marks Obtained
score = int(input("Enter Marks Scored: "))
# Of total Marks
total = int(input("Enter Total Marks: "))
# Percentage Calculation
percentage = (score / total) * 100
# Printing the result
print(f"The Percentage scored is {percentage:.2f}%")
Output:
Enter Marks Scored: 45
Enter Total Marks: 200
The Percentage scored is 22.50%
You can download this article in various formats for your convenience. Choose from the options below:
Facing issues? Have Questions? Post them here! I am happy to answer!
- Program 5: Find Sum of Two Integer Numbers - 1000+ Python Programs
- 34: Traverse a List in Reverse Order - 1000+ Python Programming
- 22: Send Yahoo! Email using smtplib - SMTP protocol client using Python Program
- 35: Python Program to find the System Hostname
- 27: Measure Elapsed Time for a Python Program Execution
- Program 7: Find Difference of Two Numbers - 1000+ Python Programs
- Program 12: Calculate Area and Circumference of Circle - 1000+ Python Programs
- Program 9: Divide Two Numbers - 1000+ Python Programs
- Program 2: Print your name using print() function - 1000+ Python Programs
- 25: How to rename a file using Python Program
- 17: Find Factorial of a Number - 1000+ Python Programs
- Program 6: Find Sum of Two Floating Numbers - 1000+ Python Programs
- 23: Python Programs to concatenate two Lists
- 36: Python Program Convert Hex String to Integer
- 20 - Python - Print Colors for Text in Terminal - 1000+ Python Programs
- Python Program: Use NumPy to generate a random number between 0 and 1
- 32: Python Program to Find Square Root of a Number
- Program 8: Multiply Two Numbers - 1000+ Python Programs
- Program 11: Calculate Percentage - 1000+ Python Programs
- 18: Get Sub List By Slicing a Python List - 1000+ Python Programs
- 28: Program to Lowercase a String in Python
- Program 1: Print Hello World! - 1000+ Python Programs
- 21: Program to Delete File or Folder in Python
- 29: Program to convert Python dict to dataframe
- 33: Python Program to find the current time in India (IST)
- Random Address Generator - Tools
- JavaScript: Convert an Image into Base64 String - JavaScript
- [fix] Java JDBC ConnectException: Connection refused - Java
- bash: ls command to see list files in current directory all subdirectories - Bash
- Android : Prevent App for rotation landscape or portrait - Android
- How to crop a screenshot on Mac/Macbook - MacOS
- Fix Error: Unknown command: --cask [Homebrew] - MacOS
- Java 8 Format Date and Time Examples - Java