: Introduction to Programming Laboratory I

**Subject: **Loops, conditional statements, basic arithmetic operations, and their functions

# The Aim of This Quiz

In this quiz, we expect you all to get practice on basic python commands, and also get experience with the programming environments, the user interface of the Integrated Development Environment (or IDE), python programming console, or terminal.

This quiz consists of two separate parts: Problem1 and Problem2. You should handle each problem in a separate *.py *file and name it with the problem index; i.e., your solution should be named *1.py *for the problem1.

## Problem1: Quadratic Equation Solver

In problem1 you are to solve a quadratic equation in a form of *ax*^{2 }+ *bx *+ *c *= 0 The roots of a quadratic equation can be calculated using the **Quadratic Formula:**

Before finding the solution to the equation, your program should first output if the equation has a real solution. If a solution exists then you should display how many solutions there are in the equation.

In order to check if a formula has a real solution, you need to calculate the *discriminant *of that formula using the equation below:

*b*^{2}− 4*ac*

The discriminant can be positive, zero, or negative, and this determines how many solutions there are to the given quadratic equation

- A
**positive**discriminant indicates that the quadratic has two distinct real number solutions. - A discriminant of
**zero**indicates that the quadratic has a repeated real number solution. - A
**negative**discriminant indicates that neither of the solutions are real numbers.

1

Fall 2020

BBM 103: Introduction to Programming Laboratory I

The constant values (*a*, *b*, and *c*) are provided as the command line arguments. The output of this problem (for *a *= 1*,b *= 4*,c *= 3) should match the format provided below including white spaces and punctuations:

There are two solutions

Solution(s): -1.00 -3.00

The order of command-line arguments:

python3 1.py a b c => python3 1.py 1 4 3

## Problem2: Even Number Evaluator

In problem2, you are expected to consider only even numbers (E) within a string (S). The numbers in the string should be; a) greater than zero, b) provided in command line arguments and, c) separated by commas. Once you have obtained the even numbers from the string, you should print the following output considering the output format (for *S *= ”75*,*41*,*14*,*8*,*73*,*45*,*−16”) :

Even Numbers: “14,8”

Sum of Even Numbers: 22

Even Number Rate: 0.086

While calculating the even number rate, you should divide the sum of even numbers by the sum of all numbers in the string.

Note: Your program should discard the numbers less than zero!

The order of command-line arguments:

python3 2.py S => python3 2.py “75,41,14,8,73,45,-16”

# Notes

- Do not miss the submission deadline.
- Save all your work until the quiz is graded.
- You can ask your questions via Piazza and you are supposed to be aware of everything discussed on Piazza.
- You must submit your work with the file hierarchy as stated below:

→ *<*1.py*>*

→ *<*2.py*>*

2

## Reviews

There are no reviews yet.