2. Loop and Input a) Request two numbers, n1 and n2 from the console. b) n1 and n2 can be any integer value. c) Use a while loop to horizontally print n1 to n2 with increment by 1 if n1 is smaller than n2. d) Use a for loop to horizontally print n1 to n2 with decrement by 1 if n1 is greater than n2. e) Print a message, “n1 = n2" if n1 is equal to n2.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Need help with python code

**2. Loop and Input**

a) Request two numbers, n1 and n2 from the console.

b) n1 and n2 can be any integer value.

c) Use a while loop to horizontally print n1 to n2 with increment by 1 if n1 is smaller than n2.

d) Use a for loop to horizontally print n1 to n2 with decrement by 1 if n1 is greater than n2.

e) Print a message, “n1 = n2” if n1 is equal to n2.

**Output Example 1:**

```
Enter a number n1: 1
Enter a number n2: 11
1 2 3 4 5 6 7 8 9 10 11
```

**Output Example 2:**

```
Enter a number n1: 11
Enter a number n2: 1
11 10 9 8 7 6 5 4 3 2 1
```

**Output Example 3:**

```
Enter a number n1: 10
Enter a number n2: 10
n1 = n2
```

**Explanation:**

- **Example 1** uses a while loop to incrementally print numbers from 1 to 11.
- **Example 2** uses a for loop to decrementally print numbers from 11 to 1.
- **Example 3** checks the condition where the two numbers are equal and prints "n1 = n2".
Transcribed Image Text:**2. Loop and Input** a) Request two numbers, n1 and n2 from the console. b) n1 and n2 can be any integer value. c) Use a while loop to horizontally print n1 to n2 with increment by 1 if n1 is smaller than n2. d) Use a for loop to horizontally print n1 to n2 with decrement by 1 if n1 is greater than n2. e) Print a message, “n1 = n2” if n1 is equal to n2. **Output Example 1:** ``` Enter a number n1: 1 Enter a number n2: 11 1 2 3 4 5 6 7 8 9 10 11 ``` **Output Example 2:** ``` Enter a number n1: 11 Enter a number n2: 1 11 10 9 8 7 6 5 4 3 2 1 ``` **Output Example 3:** ``` Enter a number n1: 10 Enter a number n2: 10 n1 = n2 ``` **Explanation:** - **Example 1** uses a while loop to incrementally print numbers from 1 to 11. - **Example 2** uses a for loop to decrementally print numbers from 11 to 1. - **Example 3** checks the condition where the two numbers are equal and prints "n1 = n2".
### Loop and Input

#### a) Request the lower bound, `lower`, and the upper bound, `upper`, from the console.
#### b) Request an increment value, `incVal`, from the console.
#### c) Use a `while` loop to increment from `lower` to `upper` by increments of `incVal` such as 0, 3, 6, 9, 12 given `lower` of 0 and `upper` of 12 and increment of 3.
#### d) Use a `while` loop to vertically print all values in between each increment.
#### e) Use a `for` loop to vertically print all values in between each increment.

### Output Example:

**Using While Loop:**
- Prompts:
  - Enter the lower bound: `5`
  - Enter the upper bound: `15`
  - Enter a number to increment by: `5`
- Output:
  ```
  5
  10
  15
  ```

**Using For Loop:**
- Prompts:
  - Enter the lower bound: `5`
  - Enter the upper bound: `55`
  - Enter a number to increment by: `10`
- Output:
  ```
  5
  15
  25
  35
  45
  55
  ```
Transcribed Image Text:### Loop and Input #### a) Request the lower bound, `lower`, and the upper bound, `upper`, from the console. #### b) Request an increment value, `incVal`, from the console. #### c) Use a `while` loop to increment from `lower` to `upper` by increments of `incVal` such as 0, 3, 6, 9, 12 given `lower` of 0 and `upper` of 12 and increment of 3. #### d) Use a `while` loop to vertically print all values in between each increment. #### e) Use a `for` loop to vertically print all values in between each increment. ### Output Example: **Using While Loop:** - Prompts: - Enter the lower bound: `5` - Enter the upper bound: `15` - Enter a number to increment by: `5` - Output: ``` 5 10 15 ``` **Using For Loop:** - Prompts: - Enter the lower bound: `5` - Enter the upper bound: `55` - Enter a number to increment by: `10` - Output: ``` 5 15 25 35 45 55 ```
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 2 images

Blurred answer
Knowledge Booster
Function Arguments
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education