Starting Out with Python (3rd Edition)
3rd Edition
ISBN: 9780133582734
Author: Tony Gaddis
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Chapter 2.6, Problem 18CP
Program Plan Intro
“input” function:
In Python, the function which is used to read the input from a keyboard is “input()”.
- • This function reads a piece of input data from a user and returns that piece of data as a string to a
program. - • The “input” function is normally used for assigning the statement.
Reading numbers with the “input” function:
- • The “input” function always returns the input data as a string, even-though if the user enters the numeric data.
- • This can be a problem when the user wants to use the value in math operation, because the math operations can be performed only for numeric values, not for strings.
- • Python has built-in functions such as “int” and “float” which can be used to convert a string to a numeric data type.
Syntax:
The syntax for “input()” statement is as follows:
variable_name = datatype (input (prompt))
Example:
Consider the example of “input” function as follows:
value = int (input ('Enter the age: '))
Explanation:
Here, the statement “'Enter the age: '” is displayed on the output screen.
- • The user must enter the input data from the keyboard and finally press the Enter key.
- • After the Enter key is pressed, the “int” function is used to convert the input data into integer datatype and return to the program.
- • Finally, store it in a variable “value”.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Submit your answer in the comment section.
Days of the Week
Write a program that asks the user for a number in the range of 1 through 7. The program should display the corresponding day of the week, where 1- Monday. 2- Tuesday and so forth. If the user types in a 6 then "Saturday should be printed on the screen. For help with
Input statements see: Input Function
• The program should print an error message if the user enters a number that is outside the range of 1 through 7. For help with If statements and conditions see the following pages: If-Eke Statements and Operators
• Name the source code file yourName HW4_1.py.
• Test and run the program. Capture the output console and save it as an image file named yourName Hw3 output4 1jpg.
• Submit the py and the image files through Canvas.
i need the answer quickly
1. Write a program that prompt the user to enter product unit price and
quantity purchased. The program will then calculate the sale tax as 5% of
the sale amount. When you prompt for the unit price, do not let the user
proceed until a number between 1 and 1,000 has been entered. When you
prompt for quantity purchased, do not proceed until the user has entered a
non-negative value. After a valid purchase is entered then the program will
display a purchase's details (unit price, quantity purchased, sale tax, and
total cost). Use loop to continue prompting you for your purchase
information and calculate/display purchase details until you enter a 'n' or
'N' when prompted.
Image Source: www.istockphoto.com
2. Write a multiplication table program that accepts a multiplication base number as well as the low and high values for
the range of multipliers. It then constructs a multiplication table for the base number from the low number to the
high number. If the base number is 5, the low number…
Chapter 2 Solutions
Starting Out with Python (3rd Edition)
Ch. 2.1 - Who is a programmers customer?Ch. 2.1 - What is a software requirement?Ch. 2.1 - What is an algorithm?Ch. 2.1 - What is pseudocode?Ch. 2.1 - Prob. 5CPCh. 2.1 - Prob. 6CPCh. 2.3 - Write a statement that displays your name.Ch. 2.3 - Write a statement that displays the following...Ch. 2.3 - Write a statement that displays the following...Ch. 2.5 - Prob. 10CP
Ch. 2.5 - Which of the following are illegal variable names...Ch. 2.5 - Prob. 12CPCh. 2.5 - Is the following assignment statement valid or...Ch. 2.5 - Prob. 14CPCh. 2.5 - Look at the following assignment statements:...Ch. 2.5 - What will be displayed by the following program?...Ch. 2.6 - You need the user of a program to enter a...Ch. 2.6 - Prob. 18CPCh. 2.7 - Prob. 19CPCh. 2.7 - Prob. 20CPCh. 2.7 - Prob. 21CPCh. 2 - A ______ error does not prevent the program from...Ch. 2 - Prob. 2MCCh. 2 - A(n) __________ is a set of well-defined logical...Ch. 2 - An Informal language that has no syntax rules and...Ch. 2 - A _______ is a diagram that graphically depicts...Ch. 2 - A ______ is a sequence of characters. a. char...Ch. 2 - Prob. 7MCCh. 2 - Prob. 8MCCh. 2 - A string literal in Python must be enclosed in...Ch. 2 - Prob. 10MCCh. 2 - A(n) __________ makes a variable reference a value...Ch. 2 - This symbol marks the beginning of a comment in...Ch. 2 - Which of the following statements will cause an...Ch. 2 - In the expression 12 + 7, the values on the right...Ch. 2 - This operator performs integer division. a. // b....Ch. 2 - This is an operator that raises a number to a...Ch. 2 - This operator performs division, but instead of...Ch. 2 - Prob. 18MCCh. 2 - Which built-in function can be used to read input...Ch. 2 - Prob. 20MCCh. 2 - Programmers must be careful not to make syntax...Ch. 2 - In a math expression, multiplication and division...Ch. 2 - Variable names can have spaces in them.Ch. 2 - In Python, the first character of a variable name...Ch. 2 - If you print a variable that has not been assigned...Ch. 2 - What does a professional programmer usually do...Ch. 2 - What is pseudocode?Ch. 2 - Computer programs typically perform what three...Ch. 2 - If a math expression adds a float to an int, what...Ch. 2 - What is the difference between floating-point...Ch. 2 - Write Python code that prompts the user to enter...Ch. 2 - Write Python code that prompts the user to enter...Ch. 2 - Write assignment statements that perform the...Ch. 2 - Assume the variables result, w, x, y, and z are...Ch. 2 - Write a Python statement that assigns the sum of...Ch. 2 - Write a Python statement that subtracts the...Ch. 2 - Write a Python statement that multiplies the...Ch. 2 - Prob. 8AWCh. 2 - What would the following display? num = 99 num = 5...Ch. 2 - Assume the variable sales references a float...Ch. 2 - Assume the following statement has been executed:...Ch. 2 - What will the following statement display?...Ch. 2 - Personal Information Write a program that displays...Ch. 2 - Sales Prediction A company has determined that its...Ch. 2 - Land Calculation One acre of land is equivalent to...Ch. 2 - Total Purchase A customer in a store is purchasing...Ch. 2 - Distance Traveled Assuming there are no accidents...Ch. 2 - Sales Tax Write a program that will ask the user...Ch. 2 - Miles-per-Gallon A car's miles-per-gallon (MPG)...Ch. 2 - Tip, Tax, and Total Write a program that...Ch. 2 - Celsius to Fahrenheit Temperature Converter Write...Ch. 2 - Ingredient Adjuster A cookie recipe calls for the...Ch. 2 - Male and Female Percentages Write a program that...Ch. 2 - Stock Transaction Program Last month, Joe...
Knowledge Booster
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
- The Problem: You need to increment a variable in the fastest possible way.arrow_forwardHoul 4O Part E Question 1 Part E Question 2 Part E Question 3 Part E Question 4 Part E Question 5 Part F Question 6 Question 6 Write a program to calculate the perimeter of a square, a rectangle and the circumference of a circle. Ask user to key in the required details depending on their selected shape. The program will keep asking user for input unless the user enters 0 to exit. The following functions have to be used in the program: i. double square (double s); - this function will return perimeter of square ii. double rectangle (double 1, double w) ; - this function will return perimeter of rectangle iii. double circle (double r): - this function will return circumference of circle The following formulas are to be used to calculate the perimeter of a square, a triangle and the circumference of a circle: Perimeter of a square = 4s where s is the side of the square. Perimeter of a rectange = a +b +cwhere a, b and c are the sides of the rectangle. Circumference of a circle = 2 mr where…arrow_forwardUsing c program Use Malaysian ringgitarrow_forward
- Flow-lines indicate the actions to be performed. true or falsearrow_forwardYour program will prompt the user for the following information: current population number of yearly births from the previous year number of yearly deaths from the previous year number of years into the future for your predictive value of the future population. You will then compute the following: birth rate death rate growth rate the predicted future population Assignment Notes: To allow the user to input the numeric data (such as current population) it is necessary to use the input function. The input function takes a string in parenthesis that prompts the user what to enter. The computer then waits until the user types a response, terminated by the user typing the Enter key. A string, as a sequence of characters, is returned to the variable on the lefthand side of the assignment statement. For example: currPopulation = input(“Enter the current US population”) The data in currPopulation is a string (because that is what the input statement does) but we need it to be a number…arrow_forward""" MovieGuide.py This program allows each theater patron to enter a value from 0 to 4 indicating the number of stars that the patron awards to the Guide's featured movie of the week. The program executes continuously until the theater manager enters a negative number to quit. At the end of the program, the average star rating for the movie is displayed. """ # Initialize variables. totalStars = 0 # total of star ratings. numPatrons = 0 # keep track of number of patrons averageStars = 0 numStars = 0 # Get input. numStarsString = input("Enter rating for featured movie: ") # Convert to double. numStars = float(numStarsString) # Write while loop here while numStars >= 0 and numStars <= 4: numPatrons = numPatrons + 1 # incrementor totalStars = totalStars + numStars # Get input. numStarsString = input("Enter rating for featured movie: ") # Convert to double. numStars = float(numStarsString) # Calculate average star rating averageStars - totalStars / numPatrons print("Average…arrow_forward
- use C++ languagearrow_forwardCreate a change-counting game that gets the user to enter the number of coins required to make exactly one dollar. The program should let the user enter the num- ber of pennies, nickels, dimes, and quarters. If the total value of the coins entered is equal to one dollar, the program should congratulate the user for winning the game. Otherwise, the program should display a message indicating whether the amount entered was more than or less than one dollar.arrow_forwardThe date June 10, 1960, is special because when we write it in the following format, the month times the day equals the year: 6/10/60 Write a program that ask the user to enter a month in numeric format, a day and a two-digit year. The program should then determine whether the month times the day is equal to the year. If so, it should display a message saying the date is Magic. Otherwise, it should display a message saying the date is not Magic. Output should look as shown below. Create test data and place in a file. Name the code file Last Name + First Initial + "-MagicDates.s", for example "SmithJ- MagicDates.s". Name the test data file in a similar manner. Upload the program and test data files to the Dropbox. 6/10/60 is Magic! 6/10/70 is not Magic. 2/11/22 is Magic!arrow_forward
- 3. A car's miles-per-gallon (MPG) can be calculated with the following formula: MPG = Miles driven / Gallons of gas used Write a program that asks the user for the number of miles driven and the gallons of gas used. It should calculate the car's miles-per-gallon and display the result on the screen.arrow_forwardQUESTION5: The Speed of Sound. The following table shows the approximate speed of sound in air, water, and steel: Medium Speed Air Water Steel 2,100 feet per second. 3,900 feet per second. 14,400 feet per second. Write a program that asks the user to enter "air", "water", or "steel", and the distance that a sound wave will travel in the medium. The program should then display the amount of time it will take. You can calculate the amount of time it takes sound to travel in air with the following formula: Time = Distance* 1,100 You can calculate the amount of time it takes sound to travel in water with the following formula: Time = Distance/ 14,900. You can calculate the amount of time it takes sound to travel in steel with the following formula: Time - Distance/ 16.400.arrow_forwardMalaysia ringgitsarrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Programming with Microsoft Visual Basic 2017Computer ScienceISBN:9781337102124Author:Diane ZakPublisher:Cengage Learning
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:9781337102124
Author:Diane Zak
Publisher:Cengage Learning