Back to Browse

Python Lab Program 2|Perform Arithmetic Operations on Two Numbers|1st PUC Computer Science

244 views
Premiered Dec 30, 2024
15:58

In this video, we will learn how to perform arithmetic operations (addition, subtraction, multiplication, and division) on two numbers using Python. This is Program 2 in the 1st PUC Computer Science curriculum, designed to help students understand basic programming concepts, user input, and basic mathematical operations. What You Will Learn in This Video: Basic Arithmetic Operations: We will cover addition, subtraction, multiplication, and division. User Input: The program takes two numbers as input from the user. Conditional Statements: We will use if-else conditions to choose the correct operation based on user input. Error Handling: The program also handles division by zero and invalid choices gracefully. Flowchart: A flowchart explaining the step-by-step process of how the program works will be shown. Practical Example: The program displays the output for each operation based on the user's choice. Program Overview: The user is prompted to enter two numbers. The program then asks the user to select an arithmetic operation (addition, subtraction, multiplication, or division). Based on the user's choice, the program performs the corresponding arithmetic operation and displays the result. If the user chooses an invalid operation or tries to divide by zero, the program displays an appropriate error message. Python Code: python Copy code other way of writing program # Program to perform arithmetic operations on two numbers # Input: Take two numbers from the user num1 = float(input("Enter the first number: ")) num2 = float(input("Enter the second number: ")) # Display the options for arithmetic operations print("\nSelect an operation:") print("1. Addition") print("2. Subtraction") print("3. Multiplication") print("4. Division") # Take user choice for operation choice = int(input("\nEnter choice (1/2/3/4): ")) # Perform the operation based on the user's choice if choice == 1: result = num1 + num2 print(f"\n{num1} + {num2} = {result}") elif choice == 2: result = num1 - num2 print(f"\n{num1} - {num2} = {result}") elif choice == 3: result = num1 * num2 print(f"\n{num1} * {num2} = {result}") elif choice == 4: if num2 != 0: result = num1 / num2 print(f"\n{num1} / {num2} = {result}") else: print("\nError! Division by zero is not allowed.") else: print("\nInvalid input! Please choose a valid operation.") Flowchart Explanation: The flowchart will show how the program progresses from taking input to performing the selected operation, handling errors, and displaying the result. It starts with user input, moves to displaying options, and then processes the chosen operation. If division is chosen, it also checks for division by zero. Enter the first number: 10 Enter the second number: 5 Select an operation: 1. Addition 2. Subtraction 3. Multiplication 4. Division Enter choice (1/2/3/4): 1 10.0 + 5.0 = 15.0 Why Learn This Program? This program is great for beginners who are learning: How to take input from the user. How to perform basic arithmetic operations in Python. How to use conditional statements to control program flow. Handling errors like division by zero and invalid input. 🔔 Don’t forget to subscribe to our channel for more Python tutorials and programming exercises specifically designed for 1st PUC Computer Science students! #Python #PythonProgramming #ArithmeticOperations #PythonLabPrograms #1stPUCComputerScience #LearnPython #PythonTutorial #Flowchart #ProgrammingBasics #PythonForBeginners

Download

1 formats

Video Formats

360pmp418.9 MB

Right-click 'Download' and select 'Save Link As' if the file opens in a new tab.

Python Lab Program 2|Perform Arithmetic Operations on Two Numbers|1st PUC Computer Science | NatokHD