0% found this document useful (0 votes)
38 views2 pages

"Enter The First Number: " "Enter The Second Number: " "Addition:" "Subtraction:" "Multiplication:" "Division:" "Floor Division:" "Modulo:"

The document contains code snippets that demonstrate various Python programming concepts: 1) A program that takes two numbers as input and performs basic math operations on them (addition, subtraction, etc.) and displays the results. 2) Code evaluating the order of operations in an expression. 3) Code evaluating a math expression. 4) Code solving a quadratic equation. 5) Code generating a multiplication table for a number input by the user.
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)
38 views2 pages

"Enter The First Number: " "Enter The Second Number: " "Addition:" "Subtraction:" "Multiplication:" "Division:" "Floor Division:" "Modulo:"

The document contains code snippets that demonstrate various Python programming concepts: 1) A program that takes two numbers as input and performs basic math operations on them (addition, subtraction, etc.) and displays the results. 2) Code evaluating the order of operations in an expression. 3) Code evaluating a math expression. 4) Code solving a quadratic equation. 5) Code generating a multiplication table for a number input by the user.
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
You are on page 1/ 2

11/07/2023, 10:22 2140201 - Jupyter Notebook

1.Write a Python program that takes two numbers (integer or floating- point) as input from the user and
performs the following operations: addition, subtraction, multiplication, division, floor division, and modulo.
Display the results of each operation.

In [2]:

num1 = float(input("Enter the first number: "))


num2 = float(input("Enter the second number: "))
addition = num1 + num2
print("Addition:", addition)
subtraction = num1 - num2
print("Subtraction:", subtraction)
multiplication = num1 * num2
print("Multiplication:", multiplication)
division = num1 / num2
print("Division:", division)
floor_division = num1 // num2
print("Floor Division:", floor_division)
modulo = num1 % num2
print("Modulo:", modulo)

Enter the first number: 12


Enter the second number: 13
Addition: 25.0
Subtraction: -1.0
Multiplication: 156.0
Division: 0.9230769230769231
Floor Division: 0.0
Modulo: 12.0

2.Is 5 + 5 * 5 = (5 + 5) * 5? Justify your answer.

In [3]:

expression1 = 5 + 5 * 5
expression2 = (5 + 5) * 5
if expression1 == expression2:
print("The expressions are equal.")
else:
print("The expressions are not equal.")

# Justification: Due to the PEMDAS RULE.

The expressions are not equal.

3.29/8+(5*2) +3=?

In [4]:

result = 29/8 + (5*2) + 3


print("Result:", result)

Result: 16.625

localhost:8888/notebooks/2140201.ipynb 1/2
11/07/2023, 10:22 2140201 - Jupyter Notebook

4.Solve x^2 + 2x + 1

In [5]:

import cmath
a = 1
b = 2
c = 1
discriminant = (b**2) - (4*a*c)
solution1 = (-b - cmath.sqrt(discriminant)) / (2*a)
solution2 = (-b + cmath.sqrt(discriminant)) / (2*a)
print("Solution 1:", solution1)
print("Solution 2:", solution2)

Solution 1: (-1+0j)
Solution 2: (-1+0j)

5.generate a multiplication table for the integer given by the user.

In [6]:

num = int(input("Enter an integer: "))


print("Multiplication Table for", num)
for i in range(1, 11):
result = num * i
print(num, "x", i, "=", result)

Enter an integer: 10
Multiplication Table for 10
10 x 1 = 10
10 x 2 = 20
10 x 3 = 30
10 x 4 = 40
10 x 5 = 50
10 x 6 = 60
10 x 7 = 70
10 x 8 = 80
10 x 9 = 90
10 x 10 = 100

localhost:8888/notebooks/2140201.ipynb 2/2

You might also like