Starting Out with Python (3rd Edition)
3rd Edition
ISBN: 9780133582734
Author: Tony Gaddis
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Textbook Question
Chapter 3.4, Problem 13CP
Convert the following code to an if-elif-else statement:
if number == 1:
print('One')
else:
if number == 2:
print('Two')
else:
if number == 3:
print('Three')
else:
print('Unknown')
Expert Solution & Answer
Learn your wayIncludes step-by-step video
schedule04:41
Students have asked these similar questions
Write aprogram using nestedif statements that perform the following test:
If the variable employed is equal to 'Y' and if worklength is equal or greater than 5, then
display the message "Your credit card application is accepted". However, if worklength is
less than 5, then display the message "Please provide a guarantor". Otherwise, if the variable
employed is equal to 'N', then display the message "Your credit card application is rejected".
C.
The following code contains several nested if-else statements. Unfortunately, it was written without proper alignment and indentation. Rewrite the code and use the proper conventions of alignment and indentation.if score >= A_score:print('Your grade is A.')else:if score >= B_score:print('Your grade is B.')else:if score >= C_score:print('Your grade is C.')else:if score >= D_score:print('Your grade is D.')else:print('Your grade is F.')
Q7-Write a program that simulates a simple calculator. It reads two integers and
a character. If the character is a +, the sum is printed; if it is a -, the difference is
printed; if it is a *, the product is printed; if it is a /, the quotient is printed; and
if it is a %, the remainder is printed. (Use a switch statement.)
Chapter 3 Solutions
Starting Out with Python (3rd Edition)
Ch. 3.1 - What is a control structure?Ch. 3.1 - What is a decision structure?Ch. 3.1 - Prob. 3CPCh. 3.1 - Prob. 4CPCh. 3.1 - What types of relationships between values can you...Ch. 3.1 - Write an if statement that assigns 0 to x if y is...Ch. 3.1 - Write an if statement that assigns 0.2 to...Ch. 3.2 - Prob. 8CPCh. 3.2 - What statement do you use in Python to write a...Ch. 3.2 - When you write an if-else statement, under what...
Ch. 3.3 - What would the following code display? If 'z a:...Ch. 3.3 - What would the following code display? s1 = 'New...Ch. 3.4 - Convert the following code to an if-elif-else...Ch. 3.5 - Prob. 14CPCh. 3.5 - Prob. 15CPCh. 3.5 - Assume the variables a = 2, b = 4, and c = 6....Ch. 3.5 - Explain how short-circuit evaluation works with...Ch. 3.5 - Write an if statement that displays the message...Ch. 3.5 - Write an if statement that displays the message...Ch. 3.6 - Prob. 20CPCh. 3.6 - What is a flag variable?Ch. 3 - A ______ structure can execute a set of statements...Ch. 3 - A __________ structure provides one alternative...Ch. 3 - A(n) _________ expression has a value of either...Ch. 3 - The symbols , , and == are all ___________...Ch. 3 - A(n)__________ structure tests a condition and...Ch. 3 - You use a(n) _______ statement to write a single...Ch. 3 - You use a(n) ______ statement to write a dual...Ch. 3 - and, or, and not are ________ operators. a....Ch. 3 - A compound Boolean expression created with the...Ch. 3 - A compound Boolean expression created with the...Ch. 3 - The _________ operator takes a Boolean expression...Ch. 3 - A ________ is a Boolean variable that signals when...Ch. 3 - Prob. 1TFCh. 3 - A program can be made of only one type of control...Ch. 3 - A single alternative decision structure tests a...Ch. 3 - A decision structure can be nested inside another...Ch. 3 - A compound Boolean expression created with the and...Ch. 3 - Explain what is meant by the term conditionally...Ch. 3 - You need to test a condition then execute one set...Ch. 3 - Briefly describe how the and operator works.Ch. 3 - Briefly describe how the or operator works.Ch. 3 - Prob. 5SACh. 3 - What is a flag and how does it work?Ch. 3 - Write an if statement that assigns 20 to the...Ch. 3 - Write an if statement that assigns 0 to the...Ch. 3 - Write an if-else statement that assigns 0 to the...Ch. 3 - The following code contains several nested if-else...Ch. 3 - Write nested decision structures that perform the...Ch. 3 - Write an if-else statement that displays 'speed is...Ch. 3 - Write an if-else statement that determines whether...Ch. 3 - Day of the Week Write a program that asks the user...Ch. 3 - Areas of Rectangles The area of a rectangle is the...Ch. 3 - Age Classifier Write a program that asks the user...Ch. 3 - Roman Numerals Write a program that prompts the...Ch. 3 - Mass and Weight Scientists measure an objects mass...Ch. 3 - Magic Dates The date June 10, 1960, is special...Ch. 3 - Color Mixer The colors red, blue, and yellow are...Ch. 3 - Hot Dog Cookout Calculator Assume hot dogs come in...Ch. 3 - Roulette Wheel Colors On a roulette wheel, the...Ch. 3 - Money Counting Game Create a change-counting game...Ch. 3 - Book Club Points Serendipity Booksellers has a...Ch. 3 - Software Sales A software company sells a package...Ch. 3 - Shipping Charges The Fast Freight Shipping Company...Ch. 3 - Body Mass Index Write a program that calculates...Ch. 3 - Time Calculator Write a program that asks the user...
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
Look at the following partial class definition, and then respond to the questions that follow it: public class ...
Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
(This is a better version of an exercise from Chapter 1.) Write a program that reads in a line of text and then...
Absolute Java (6th Edition)
________ is the process of inspecting input values and determining whether they are valid.
Starting Out With Visual Basic (7th Edition)
Write a program to print the value of EOF.
C Programming Language
Write a simple assignment statement with one arithmetic operator in some language you know. For each component ...
Concepts Of Programming Languages
Describe the two ways in which control statements can be combined.
Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
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
- 0 When you write an If-Then-Else statement, under what circumstances do the statementsthat appear between Else and End If execute?arrow_forwardWrite simple code using the if, else if statementarrow_forwardWrite an if-else statement that displays 'Speed is normal' if the speed variable is within the range of 24 to 56. If the speed variable’s value is outside this range, display 'Speed is abnormal'arrow_forward
- C+ Programmingarrow_forwardWrite nested if statements that perform the following test : If amount1 is greater than 10 and amount 2 is less than 100, display the greater of the twoarrow_forwardComputer Fundamentals and Programming 2 Write a program that determines a student’s grade. The program will accept 3 scores and computes the average score. Determine the grade based on the following rules: - If the average score is equal or greater than 90, the grade is A. - If the average score is greater than or equal to 70 and less than 90, the grade is B. - If the average score is greater than or equal to 50 and less than 70, the grade is C. - If the average score is less than 50, the grade is F. Source Codes and Print Screen of the Outputarrow_forward
- Write an if statement for the following: use if/else statement that assigns 1 to x if y is equal to 100. Otherwise it should assign 0 to x.arrow_forwardUsing the following chart, write an if-else-if statement that assigns: S, M, L, depending on the weight: Weight Size Up to 120 lb S 120 lb to 175 lb M Over 175 lb Larrow_forwardC++ please - 24-hour time (also known in the U.S. as military time) is widely used around the world. Time is expressed as hours since midnight. The day starts at 0000, and ends at 2359. Write a program that converts am/pm time to 24-hour time. If the input is 2:30 pm, the output should be 1430. If the input is 12:01 am, the output should be 0001. Hints: Think of how each hour should be handled. 12:00 am -12:59 am becomes what? 8:00 am becomes what? 12:00 pm? 1:00 pm? Group the hours into cases that should be handled similarly (e.g., 1:00 am to 11:00 am are handled the same). Declare variables for hoursAmPm, minAmPm, and hours24. Note that minutes for 24-hour time remain the same as for am/pm, so no extra variable is needed. Use an if-else statement to detect each case, and set the hours24 appropriately. When outputting hour24, check if the hour is 0-9 (just check for < 10). If so, output a "0". So 7 will be output as 07. Do the same when outputting the minutes. #include…arrow_forward
- 5. Write an efficient if statement to assign x the value 1 if x ≤ 1.5, 2 if 1.5arrow_forwardFind the errors in the following code: The following statement should assign 0 to z if a is less than 10; otherwise, it should assign 7 to z. What is wrong with it?z = (a < 10) : 0 ? 7;arrow_forwardIn C language The if...else statement executes two different codes depending .upon whether the test expression is true or false False True * In C language is invalid identifier su_b O intarrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
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)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education
Control Structure in Data Structure - Data Structures - Computer Science Class 12; Author: Ekeeda;https://www.youtube.com/watch?v=9FTw2pXLhv4;License: Standard YouTube License, CC-BY