Starting Out with Python (4th Edition)
4th Edition
ISBN: 9780134444321
Author: Tony Gaddis
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Textbook Question
Chapter 8, Problem 1AW
Assume choice references a string. The following if statement determines whether choice is equal to ‘Y’ or ‘y’:
if choice == ‘Y’ or choice == ‘y’:
Rewrite this statement so it only makes one comparison, and does not use the or operator.
(Hint: use either the upper or lower methods.)
Expert Solution & Answer
Learn your wayIncludes step-by-step video
schedule03:43
Students have asked these similar questions
Using an instance of a string, you may determine the location of the substring.
Lab Activity for the students:
Exercise 5: Write a program that asks the user to input a letter. The program finds and prints if the letter is
uppercase or lowercase. Then, the program asks the user to input a string and get a three-character substring
from the beginning of the string. (1 Mark )
Example : If the inputs are 'y' and "Community". Then, the program will print:
y is lowercase
The substring is: Com
One of the string objects may be used to determine where the substring is.
Chapter 8 Solutions
Starting Out with Python (4th Edition)
Ch. 8.1 - Assume the variable name references a string....Ch. 8.1 - What is the index of the first character in a...Ch. 8.1 - If a string has 10 characters, what is the index...Ch. 8.1 - Prob. 4CPCh. 8.1 - Prob. 5CPCh. 8.1 - Prob. 6CPCh. 8.2 - Prob. 7CPCh. 8.2 - Prob. 8CPCh. 8.2 - Prob. 9CPCh. 8.2 - What will the following code display? mystring =...
Ch. 8.3 - Prob. 11CPCh. 8.3 - Prob. 12CPCh. 8.3 - Write an if statement that displays Digit" if the...Ch. 8.3 - What is the output of the following code? ch = 'a'...Ch. 8.3 - Write a loop that asks the user Do you want to...Ch. 8.3 - Prob. 16CPCh. 8.3 - Write a loop that counts the number of uppercase...Ch. 8.3 - Assume the following statement appears in a...Ch. 8.3 - Assume the following statement appears in a...Ch. 8 - This is the first index in a string. a. 1 b. 1 c....Ch. 8 - This is the last index in a string. a. 1 b. 99 c....Ch. 8 - This will happen if you try to use an index that...Ch. 8 - This function returns the length of a string. a....Ch. 8 - This string method returns a copy of the string...Ch. 8 - This string method returns the lowest index in the...Ch. 8 - This operator determines whether one string is...Ch. 8 - This string method returns true if a string...Ch. 8 - This string method returns true if a string...Ch. 8 - This string method returns a copy of the string...Ch. 8 - Once a string is created, it cannot be changed.Ch. 8 - You can use the for loop to iterate over the...Ch. 8 - The isupper method converts a string to all...Ch. 8 - The repetition operator () works with strings as...Ch. 8 - Prob. 5TFCh. 8 - What does the following code display? mystr =...Ch. 8 - What does the following code display? mystr =...Ch. 8 - What will the following code display? mystring =...Ch. 8 - Prob. 4SACh. 8 - What does the following code display? name = 'joe'...Ch. 8 - Assume choice references a string. The following...Ch. 8 - Write a loop that counts the number of space...Ch. 8 - Write a loop that counts the number of digits that...Ch. 8 - Write a loop that counts the number of lowercase...Ch. 8 - Write a function that accepts a string as an...Ch. 8 - Prob. 6AWCh. 8 - Write a function that accepts a string as an...Ch. 8 - Assume mystrinc references a string. Write a...Ch. 8 - Assume mystring references a string. Write a...Ch. 8 - Look at the following statement: mystring =...Ch. 8 - Initials Write a program that gets a string...Ch. 8 - Sum of Digits in a String Write a program that...Ch. 8 - Date Printer Write a program that reads a string...Ch. 8 - Prob. 4PECh. 8 - Alphabetic Telephone Number Translator Many...Ch. 8 - Average Number of Words If you have downloaded the...Ch. 8 - If you have downloaded the source code you will...Ch. 8 - Sentence Capitalizer Write a program with a...Ch. 8 - Prob. 10PECh. 8 - Prob. 11PECh. 8 - Word Separator Write a program that accepts as...Ch. 8 - Pig Latin Write a program that accepts a sentence...Ch. 8 - PowerBall Lottery To play the PowerBall lottery,...Ch. 8 - Gas Prices In the student sample program files for...
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
Why is it useful for a programmer to have some background in language design, even though he or she may never a...
Concepts of Programming Languages (11th Edition)
Grade point average (GPA) in a 4-point scale is calculated by using the following formula:
Write a program t...
Absolute Java (6th Edition)
Why is it easier to write a program in a high-level language than in machine language?
Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
This problem concerns the m. o module from Figure 7.5 and the following version of the swap, c function that co...
Computer Systems: A Programmer's Perspective (3rd Edition)
To round numbers to specific decimal places, use a statement like double y = Math.floor(x 10 + 0.5) / 10; whic...
Java How To Program (Early Objects)
Stadium Seating There are three searing categories at a stadium. For a softball game, Class A seats cost 15, Cl...
Starting Out with C++: Early Objects (9th Edition)
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 in operator can be used to determine whether one string is not contained in another string.True or Falsearrow_forwardUtilizing an instance of a string object may help you locate the substring.arrow_forwardThe != operator can be used to compare two String objects. Select one: True Falsearrow_forward
- By using one of the string objects, you may determine its location.arrow_forwardBy using one of the string objects, you will have the ability to precisely locate the place of the substring in which you are interested.arrow_forwardThis string method returns true if a string contains only alphabetic characters and is at least one character in length.a. the isalpha methodb. the alpha methodc. the alphabetic methodd. the isletters methodarrow_forward
- Assume the variable name references a String object. Write an if statement that displays “Do I know you?” if the String object contains “Timothy”.arrow_forwardExercise I- Medicine Write a program that asks the user to enter the name of the medicine (t for ThroX, f for FeliX), his mass. The user should enter as well if he has a prescription or not. The program will calculate the dosage using: age and his ThroX without prescription -The max dosage should be 0.75 mL -The dosage = mass / 150 -The number of pills per day to take is 1 ThroX with prescription -The dosage =mass * 3 / 150 -The number of pills per day to take is 5 FeliX with prescription -The dosage = 0.77 mL FeliX without prescription -The dosage should be between 0.3 and 0.7 -The dosage = mass * 0.009 -The number of pills per day to take is 2 -The number of pills per day to take is 6 The program should display the dosage and the number of pills to be taken per day if the requirements are full filled, otherwise it display "Please check your doctor for a prescription". In case the medicine does not exist in the database, the program display “Your medicine is not in our database!"…arrow_forwardMatric Number: 2. Let x be the first three digits of your matric number, AND y be the last three digits of your matric number. If the first digit of y is 0, replace it with 2. Ехатple: If you matric number is 2013034, Thus, x = 201 and y = 234 a. Write the values of x and y based on your matric number. b. If a = x (mod 7) and b = (-1) + y (mod 7), find the integer(s) c with 10arrow_forwardQ1: Which is not a Python keyword for decision structures: Else if elseif elif Q2: The result of an if's logical expression can be a string. True False Q3: The statement immediately following an if statement must: use the print() function be commented be mathematical be indented Q4: At the end of an if statement you must use a comma semi-colon period colon Q5: Assuming a and b are string variables, which is a value if statement? if a==b: if a <> b: if a = b: if a equals b:arrow_forward5. Maximum Occurring Character Given a string, return the character that appears the maximum number of times in the string. The string will contain only ASCII characters, from the ranges ('a'-'z','A'-'Z','0'-'9'), and case matters. If there is a tie in the maximum number of times a character appears in the string, return the character that appears first in the string. Example text = abbbaacc Both 'a' and 'b'occur 3 times in text. Since 'a'occurs earlier, a is the answer. Function Description Complete the function maximum Occurring Character in the editor below. maximumOccurringCharacter has the following parameter: string text: the string to be operated upon Returns char: The most occurring character that appears first in the string. Constraints • 10 ≤ |text| ≤ 104 • All characters are alphanumeric, in the ranges ('a'-'z','A'-'Z','0'-'9') ======== 999992 14 15 16 17 18 19 20 21 2 2 2 2 22 23 24 25 2222 26 class Result { * * Complete the 'maximumOccurring Character' function below. * का…arrow_forwardThe strict equal operator is Select one: a. != b.== C.=== d.=arrow_forwardarrow_back_iosSEE MORE QUESTIONSarrow_forward_ios
Recommended textbooks for you
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
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