Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
4th Edition
ISBN: 9780134444321
Author: Tony Gaddis
Publisher: PEARSON
bartleby

Concept explainers

bartleby

Videos

Textbook Question
100%
Chapter 4, Problem 4PE

Distance Traveled

The distance a vehicle travels can be calculated as follows:

  distance = speed x time

For example, if a train travels 40 miles per hour for three hours, the distance traveled is 120 miles. Write a program that asks the user for the speed of a vehicle (in miles per hour) and the number of hours it has traveled. It should then use a loop to display the distance the vehicle has traveled for each hour of that time period. Here is an example of the desired output:

What is the speed of the vehicle in mph? 40 Enter

How many hours has it travelled? 3 Enter

Hour Distance Traveled
1 40
2 80
3 120
Blurred answer
02:27
Students have asked these similar questions
The distance a vehicle travels can be calculated as follows: Distance = Speed X TimeDesign a program that asks a user for the speed of a vehicle in miles per hour and how many hours it has travelled (Assume the two values are integers). Your program should then use a loop to display the distance the vehicle has traveled for each hour of that time period. (For example, entering 50 mph and 4 hours should produce output like: Hour 1: 50 miles, Hour 2: 100 miles, Hour 3: 150 miles, Hour 4: 200 miles. )
The distance a vehicle travels can be calculated asfollows: distance = speed time. For example, if a traintravels 40 miles per hour for 3 hours, the distancetraveled is 120 miles. Write a program that asks the userfor the speed of a vehicle (in miles per hour) and howmany hours it has traveled. The program should then usea loop to display the distance the vehicle has traveledfor each hour of that time period.
Programming Problem 1Write a program that has the user input their height in inches and convert it to meters. Print the inches and the converted meters. The program should allow the user to enter as many heights as they want (use a loop for this).

Chapter 4 Solutions

Starting Out with Python (4th Edition)

Ch. 4.3 - What will the following code display? for number...Ch. 4.3 - What will the following code display? for number...Ch. 4.4 - Prob. 13CPCh. 4.4 - Should an accumulator be initialized to any...Ch. 4.4 - What will the following code display? total - 0...Ch. 4.4 - What will the following code display? number 1 =...Ch. 4.4 - Rewrite the following statements using augmented...Ch. 4.5 - Prob. 18CPCh. 4.5 - Why should you take care to choose a distinctive...Ch. 4.6 - What does the phrase garbage in, garbage out mean?Ch. 4.6 - Give a general description of the input validation...Ch. 4.6 - Describe the steps that are generally taken when...Ch. 4.6 - Prob. 23CPCh. 4.6 - If the input that is read by the priming read is...Ch. 4 - A_________-controlled loop uses a true/false...Ch. 4 - A _____-controlled loop repeats a specific number...Ch. 4 - Each repetition of a loop is known as a(n) a cycle...Ch. 4 - The while loop is a _______ type of loop. a....Ch. 4 - A(n) ______ loop has no way of ending and repeats...Ch. 4 - The -= operator is an example of a(n) _________...Ch. 4 - Prob. 7MCCh. 4 - A(n) ____________ is a special value that signals...Ch. 4 - Prob. 9MCCh. 4 - The integrity of a programs output is only as good...Ch. 4 - The input operation that appears just before a...Ch. 4 - Validation loops are also known as _________. a....Ch. 4 - A condition-controlled loop always repeats a...Ch. 4 - The while loop is a pretest loop.Ch. 4 - The following statement subtracts 1 from x: x = x ...Ch. 4 - It is not necessary to initialize accumulator...Ch. 4 - In a nested loop, the inner loop goes through all...Ch. 4 - To calculate the total number of iterations of a...Ch. 4 - The process of input validation works as follows:...Ch. 4 - What is a condition-controlled loop?Ch. 4 - What is a count-controlled loop?Ch. 4 - What is an infinite loop? Write the code for an...Ch. 4 - Why is it critical that accumulator variables are...Ch. 4 - What is the advantage of using a sentinel?Ch. 4 - Prob. 6SACh. 4 - What does the phrase garbage in, garbage out mean?Ch. 4 - Give a general description of the input validation...Ch. 4 - Write a while loop that lets the user enter a...Ch. 4 - Write a while loop that asks the user to enter two...Ch. 4 - Write a for loop that displays the following set...Ch. 4 - Write a loop that asks the user to enter a number....Ch. 4 - Write a loop that calculates the total of the...Ch. 4 - Rewrite the following statements using augmented...Ch. 4 - Write a set of nested loops that display 10 rows...Ch. 4 - Write code that prompts the user to enter a...Ch. 4 - Write code that prompts the user to enter a number...Ch. 4 - Bug Collector The Bug Collector Problem A bug...Ch. 4 - Calories Burned Running on a particular treadmill...Ch. 4 - Budget Analysis Write a program that asks the user...Ch. 4 - Distance Traveled The distance a vehicle travels...Ch. 4 - Average Rainfall Write a program that uses nested...Ch. 4 - Celsius to Fahrenheit Table Write a program that...Ch. 4 - Pennies for Pay Write a program that calculates...Ch. 4 - Sum of Numbers Write a program with a loop that...Ch. 4 - Ocean Levels Assuming the ocean's level is...Ch. 4 - Tuition Increase At one college, the tuition for a...Ch. 4 - Weight Loss If a moderately active person cuts...Ch. 4 - Calculating the Factorial of a Number In...Ch. 4 - Population Write a program that predicts the...Ch. 4 - Prob. 14PECh. 4 - Prob. 15PECh. 4 - Turtle Graphics: Repeating Squares In this...Ch. 4 - Turtle Graphics: Star Pattern Use a loop with the...Ch. 4 - Turtle Graphics: Hypnotic Pattern Use a loop with...Ch. 4 - Turtle Graphics: STOP Sign In this chapter, you...

Additional Engineering Textbook Solutions

Find more solutions based on key concepts
Knowledge Booster
Computer Science
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.
Similar questions
  • a. A bowling team consists of five players. Each player bowls three games. Write a program that uses a nested loop to enter each player's individual scores and then computes and displays the average score for each bowler. Assume that each bowler has the following scores. Use two different loop structures for outer loop and inner loop. For example, if you use "for" as the outer loop structure, the inner loop should be "while" or "do.... while". 1st bowler: 286 2nd bowler: 212 3rd bowler: 252 232 4th bowler: 192 201 265 215 216 235 5th bowler: 186 252 186 236 272 b. Modify the program written for Exercise 3a to calculate and display the average team score. (Hint: Use a second variable to store the total of all the players' scores.)
    Budget Analysis (Running Total)Write a program BudgetAnalysis.py) that asks the user to enter the amount of money that he or she has available to spend on electronics this year. A loop should then prompt the user to enter each of his or her expenses for electronics and keep a running total. When the loop finishes, the program should display the total amount that the user spent, and analyse if there is still money to buy more electronics. Here are two test runs of the program: Enter your available amount for electronics in 2020: 1500 Enter your expense (-1 for stop): 340 Enter your expense (-1 for stop): 450 Enter your expense (-1 for stop): -1 So far you spent $ 790.0 You can buy more electronics. >>> ========= RESTART: C: \Users \Rita \Desktop \Lab5-1 B BudgetA Enter your available amount for electronics in 2020: 900 Enter your expense (-1 for stop): 730 Enter your expense (-1 for stop): 290 Enter your expense (-1 for stop): -1 So far you spent $ 1020.0 No more electronics in…
    Write a program that uses nested loops to collect data and calculate the average rainfall over a period of years. The program should first ask for the number of years. The outer loop will iterate once for each year. The inner loop will iterate twelve times, once for each month. Each iteration of the inner loop will ask the user for the inches of rainfall for that month. After alliterations, the program should display the number of months, the total inches of rainfall, and the average rainfall per month for the entire period.
  • Python Coding-While Loops  (In PyCharm Community edition)   Create a while loop that SUMS up ALL the numbers given from an initial number and an ending number.   Example would be : Input1 : What is the first number?  0 Input2 : What is the last number? 3   DO NOT SHOW but these are the computations inside the code : 0 + 1 + 2 + 3 = 6   This is the Output : The sum of all the number from 0 to 3, is 6   In the code you are going to use a total variable and add each additional time it runs through the loop to that total. REMEMBER the assignment from the first unit of programming where we used this formula :    BUT you are going to create your own method using a while loop to emulate what formula accomplishes WITHOUT using this formula.  The user will put in the first number and the last to be SUMMED - you will use the while loop to calculate all of the additions leading to the final number.
    Exercise # 2: Write a while loop that prints all positive numbers that are divisible by 10 and less than the user input value n. For example, if the user enters 100, the program shall print 10 20 30 40 50 60 70 80 90.
    Write a for loop that repeats seven times, asking the user to enter a number. The loop should also calculate the sum of the numbers entered and display the final sum.       Write a for loop that displays the following set of numbers:       0, 10, 20, 30, 40, 50 . . . 1000 What’s the initialization step? The Boolean test/condition? Update action/incrementation?     Convert the while loop in the following code segment to a for loop: int count = 0; while (count < 50) { System.out.println("count is " + count); count++; } please solve three of them
  • Write a program that uses nested loops to collect data and calculate the average rainfall over a period of years.  The program should first ask the user for the number of years.  The outer loop will iterate once for each year.  The inner loop will iterate 12 times, once for each month.  Each iteration of the inner loop will ask the user for the inches of rainfall for that month.   After all iterations, the program should display the number of months, the total inches of rainfall, and the average rainfall per month for the entire period.   Add additional loops to validate the input: Do not accept a number less than 1 for the number of years.  Continue to prompt the user for a number until a valid number is entered. Do not accept negative numbers for the monthly rainfall.  Continue to prompt the user for a number until a valid number is entered
    Write a program that displays a weekly payroll report. A loop in the program should ask the user for the employee number, gross pay, state tax, federal tax, and FICA withholdings. The loop will terminate when 0 is entered for the employee number. After the date is entered, the program should display totals for gross pay, state tax, federal tax, FICA withholdings, and net pay.
    Construct a single for loop to print out the following lines.  You may use as many variables as you wish, but you may not use multiple loops. 4       4        4 8       2        7 16     1        10 32     0.5     13 64     0.25   16
    • SEE MORE QUESTIONS
    Recommended textbooks for you
  • C++ for Engineers and Scientists
    Computer Science
    ISBN:9781133187844
    Author:Bronson, Gary J.
    Publisher:Course Technology Ptr
    Programming Logic & Design Comprehensive
    Computer Science
    ISBN:9781337669405
    Author:FARRELL
    Publisher:Cengage
    Microsoft Visual C#
    Computer Science
    ISBN:9781337102100
    Author:Joyce, Farrell.
    Publisher:Cengage Learning,
  • C++ for Engineers and Scientists
    Computer Science
    ISBN:9781133187844
    Author:Bronson, Gary J.
    Publisher:Course Technology Ptr
    Programming Logic & Design Comprehensive
    Computer Science
    ISBN:9781337669405
    Author:FARRELL
    Publisher:Cengage
    Microsoft Visual C#
    Computer Science
    ISBN:9781337102100
    Author:Joyce, Farrell.
    Publisher:Cengage Learning,
    Control Structures - while loop - do-while loop - for loop - Goto - break - continue statements; Author: EzEd Channel;https://www.youtube.com/watch?v=21l11_9Osd0;License: Standard YouTube License, CC-BY