
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN: 9780133594140
Author: James Kurose, Keith Ross
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
Note: it python code
Try to convert for to while as one of the requirements is to do with while loop is use a while loop to horizontally print n1 to n2 with increment by 1 if n1 is smaller than n2.
Here is the given code:
n1=int(input("Enter a number n1: "))
n2=int(input("Enter a number n2: "))
if n1<n2:
for i in range(n1,n2+1):
print(i,":",end=' ')
elif n1>n2:
for i in range(n1,n2-1,-1):
print(i,":",end=' ')
else:
print("n1=n2")
Expert Solution

arrow_forward
Step 1
Hi.
Let's move on to the code in the next step.
I have included comments in the code wherever I had made a change that will help you in understanding the code better.
Step by stepSolved in 2 steps with 2 images

Knowledge Booster
Similar questions
- write an algorithm code it in Python Tuition Fees Increase In 2008, BC charged $115 per credit for a course. BC announced it would increase its cost per credit by 4% each year for the next five years. Write a program that uses a for loop to display the projected rates for the next five years as follows: Year Cost per Credit -------------------------- 2008 $115.00 2009 $119.60 2010 $124.38 2011 $129.36 2012 $134.53 2013 $139.92 ============================================================================ Pay attention to the spacing/alignment in your output. Review the Formatting Output in Python documentation in order to properly format the numerical values in your output. The output should present with two decimal places. Include your algorithm as section comments in your Python code. Upload the Python (*.py) file here.arrow_forwardAn experienced Python programmer in your company wants your assistance calculating the sum of integer multipliers of 12 between 0 and up to 100 (including both ends). As an example: while j < 100: Use the following starter code and complete the while loop: Starter code: j-0 sum12 0 ### Place your code below the print (¹) print('Total sum12 is:', sum12) ### Place your code above this ### Expected output: j: 0 sum12: 0 j: 12 sum12: 12 j: 24 sum12: 36 j: 36 sum12: 72 j: 48 sum12: 120 j: 60 sum12: 180 j: 72 sum12: 252 0 x 12+0=0 1x 12+0=12 2 × 12 + 12 = 36 3 x 12+36 72 j: 84 sum12: 336 j: 96 sum12: 432 ⠀ 6 x 12+180 252 7 x 12+252 = 336 8 x 12 +336 432 Total sum12 is: 432arrow_forwardPlease answer the ques in python with showing answersarrow_forward
- Abang Mat will give 10% discount to customers who buy more than 100 pieces of satay. The program will: • read the type of satay that the customer would like to buy • print the bill for each customer based on the quantity and discounts. loop to read and process the purchasing information of FIVE (5) customers. You may assume that the users will always key in a correct input, hence Input validation is not needed. A sample output is shown in Figure 1: Welcome to Kedai Sate Abang Mat You are customer number 0:What would you like to order? 1. Satay Ayam 2.Satay Kambing Enter your option:1 Quantity: 12 Bill RM 12.00 Type of Satay Chicken Lamb Quantity: 36 Bill RM 54.00 Price (per stick) RM1.00 RM1.50 Welcome to Kedai Sate Abang Mat You are customer number 1:What would you like to order? 1. Satay Ayam 2.Satay Kambing Enter your option:2 ******* Welcome to Kedai Sate Abang Mat You are customer number 4: What would you like to order? 1. Satay Ayam 2.Satay Kambing Enter your option:1 Quantity:…arrow_forwardComputer Science The script below demonstrates a very basic loop structure. Indicate the value of R1 after 5 iterations of the loop. (Given the very first line of code, you can assume R1 starts out as 0x00)arrow_forwardQuestion 1: Please develop a program. The program shows a O(n^2) time complexity. You may design nested loops. When you input a number, the output should be how many times of the loops. For example, if your input is 10, the number of loops should be 100 times, 200 times, 300 times, etc. The number of loops do not have to be an accurate number.arrow_forward
arrow_back_ios
arrow_forward_ios
Recommended textbooks for you
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY

Computer Networking: A Top-Down Approach (7th Edi...
Computer Engineering
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:PEARSON

Computer Organization and Design MIPS Edition, Fi...
Computer Engineering
ISBN:9780124077263
Author:David A. Patterson, John L. Hennessy
Publisher:Elsevier Science

Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:9781337569330
Author:Jill West, Tamara Dean, Jean Andrews
Publisher:Cengage Learning

Concepts of Database Management
Computer Engineering
ISBN:9781337093422
Author:Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:Cengage Learning

Prelude to Programming
Computer Engineering
ISBN:9780133750423
Author:VENIT, Stewart
Publisher:Pearson Education

Sc Business Data Communications and Networking, T...
Computer Engineering
ISBN:9781119368830
Author:FITZGERALD
Publisher:WILEY