Starting Out with Python (4th Edition)
4th Edition
ISBN: 9780134444321
Author: Tony Gaddis
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Chapter 7, Problem 6AW
Program Plan Intro
Operator “in”:
- • The easiest way to search an item in a list is by means of “in” operator.
- • The “in” operator in Python determines whether the searching item is present in a list.
- • If the searching item is present in the list, then this operator returns a “True” value.
- • If the searching item is not present in the list, then this operator returns a “False” value.
Algorithm to find whether the name “Ruby” is present in the “names” list is as follows:
- • Create a list of strings that stores names and assigns it to “names”.
- • Then, use the “in” operator along with “if” statement to check whether the name “Ruby” is present in the list “names”.
- • If the name “Ruby” is present in the “names” list, then print the message “Hello Ruby”.
- • If the name “Ruby” is not present in the “names” list, then print the message “No Ruby”.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
C++ Language
Allowed libraries:
Alternate Character DisplayWrite a method that accepts a String object as an argument and then returns the alternate characters as substring starting from index 0. For instance, if the string argument passed is “GREAT”, the method should return “GET”. Demonstrate the method in a program that asks the user to input a string and then passes it to the method.
Chapter 7 Solutions
Starting Out with Python (4th Edition)
Ch. 7.2 - What will the following code display? numbers =...Ch. 7.2 - Prob. 2CPCh. 7.2 - Prob. 3CPCh. 7.2 - Prob. 4CPCh. 7.2 - Prob. 5CPCh. 7.2 - Prob. 6CPCh. 7.2 - Prob. 7CPCh. 7.2 - Prob. 8CPCh. 7.3 - Prob. 9CPCh. 7.3 - Prob. 10CP
Ch. 7.3 - Prob. 11CPCh. 7.3 - Prob. 12CPCh. 7.3 - Prob. 13CPCh. 7.4 - What will the following code display? names =...Ch. 7.5 - Prob. 15CPCh. 7.5 - Prob. 16CPCh. 7.5 - Prob. 17CPCh. 7.5 - Prob. 18CPCh. 7.8 - Prob. 19CPCh. 7.8 - Prob. 20CPCh. 7.8 - Write a set of nested loops that display the...Ch. 7.9 - Prob. 22CPCh. 7.9 - Prob. 23CPCh. 7.9 - Prob. 24CPCh. 7.9 - Prob. 25CPCh. 7.10 - Prob. 26CPCh. 7.10 - Prob. 27CPCh. 7.10 - Prob. 28CPCh. 7.10 - Prob. 29CPCh. 7.10 - Prob. 30CPCh. 7.10 - To create a bar chart with the bar function, what...Ch. 7.10 - Assume the following statement calls the bar...Ch. 7.10 - Prob. 33CPCh. 7 - This term refers to an individual item in a list....Ch. 7 - This is a number that identifies an item in a...Ch. 7 - Prob. 3MCCh. 7 - This is the last index in a list. a. 1 b. 99 c. 0...Ch. 7 - This will happen if you try to use an index that...Ch. 7 - This function returns the length of a list. a....Ch. 7 - When the operator's left operand is a list and...Ch. 7 - This list method adds an item to the end of an...Ch. 7 - This removes an item at a specific index in a...Ch. 7 - Prob. 10MCCh. 7 - If you call the index method to locate an item in...Ch. 7 - Prob. 12MCCh. 7 - This file object method returns a list containing...Ch. 7 - Which of the following statement creates a tuple?...Ch. 7 - Prob. 1TFCh. 7 - Prob. 2TFCh. 7 - Prob. 3TFCh. 7 - Prob. 4TFCh. 7 - A file object's writelines method automatically...Ch. 7 - You can use the + operator to concatenate two...Ch. 7 - Prob. 7TFCh. 7 - You can remove an element from a tuple by calling...Ch. 7 - Prob. 1SACh. 7 - Prob. 2SACh. 7 - What will the following code display? values = [2,...Ch. 7 - Prob. 4SACh. 7 - Prob. 5SACh. 7 - Prob. 6SACh. 7 - Prob. 1AWCh. 7 - Prob. 2AWCh. 7 - Prob. 3AWCh. 7 - Prob. 4AWCh. 7 - Write a function that accepts a list as an...Ch. 7 - Prob. 6AWCh. 7 - Prob. 7AWCh. 7 - Prob. 8AWCh. 7 - Total Sales Design a program that asks the user to...Ch. 7 - Prob. 2PECh. 7 - Rainfall Statistics Design a program that lets the...Ch. 7 - Prob. 4PECh. 7 - Prob. 5PECh. 7 - Larger Than n In a program, write a function that...Ch. 7 - Drivers License Exam The local driver s license...Ch. 7 - Name Search If you have downloaded the source code...Ch. 7 - Prob. 9PECh. 7 - World Series Champions If you have downloaded the...Ch. 7 - Prob. 11PECh. 7 - Prob. 12PECh. 7 - Magic 8 Ball Write a program that simulates a...Ch. 7 - Expense Pie Chart Create a text file that contains...Ch. 7 - 1994 Weekly Gas Graph In the student sample...
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
- Programming language: SWIFT Write a function that takes a string as a parameter and returns the string "Swift" if the string passed as parameter begins with "SWIFT" or "swift". Otherwise, returns an empty string.arrow_forwardTrue or False: The strings provided by the C++ Standard library are mutable. In a string, including the newline character \n as part of the string is a syntax error.arrow_forward. Look at the following statement:mystring = 'cookies>milk>fudge>cake>ice cream'Write a statement that splits this string, creating the following list:['cookies', 'milk', 'fudge', 'cake', 'ice cream']arrow_forward
- C++ languagearrow_forwardCode in c language, please. Thank you in advance. Assign listOfPizzas's first element's numberOfCalories with the value in listOfPizzas's second element's numberOfCalories. #include <stdio.h>#include <string.h> typedef struct Pizza_struct { char pizzaName[75]; int numberOfCalories;} Pizza; int main(void) { Pizza listOfPizzas[2]; scanf("%s", listOfPizzas[0].pizzaName); scanf("%d", &listOfPizzas[0].numberOfCalories); scanf("%s", listOfPizzas[1].pizzaName); scanf("%d", &listOfPizzas[1].numberOfCalories); /* Your code goes here */ printf("A %s slice contains %d calories.\n", listOfPizzas[0].pizzaName, listOfPizzas[0].numberOfCalories); printf("A %s slice contains %d calories.\n", listOfPizzas[1].pizzaName, listOfPizzas[1].numberOfCalories); return 0;}arrow_forwardIn c++ is it possible to assign a string with two separate values?arrow_forward
- Fix the errors and find the lowest marks entered by the user struct std{string name;int reg_no;int marks[5];}s1;getline(cin,s1.name);cin>>s1.reg_no;for(int i =0;i<5;i++)cin>>s1.marks[i]arrow_forwardpython programing: You are going to create a race class, and inside that class it has a list of entrants to the race. You are going to create the daily schedule of three or so races and populate the races with the jockey/horse entries and then print out the schedule. Create a race class that has The name of the race as a character string, ie “RACE 1” or “RACE 2”, The time of the race A list of entries for that race Create a list of of 3 (or 4) of those race objects(races) for the day For the list of entries for a particular race, make a entrant class (the building block of your entrants list) you should have The horse name The jockey name Now you need to Populate the structure (ie set up three races on the schedule, add 2-3 horses entries to each race. You can hardcode the entries if you want to, rather than getting them from the user, just to save the time of making a menu interface and whatnot. Be able to print the days schedule So example output would be…arrow_forwardwrite programs date formarrow_forward
- Urgent solve using C++ Notes: The maximum size of any c-string in this lab is 100 characters and it should be dynamically allocated in the constructor and de-allocated in the destructor. For Visual Studio you need to put the following line as first top line in your source code file: #define _CRT_SECURE_NO_WARNINGS Question 1: The class Person contains the following properties and functions: Name (c-string ), private Age (int), private Address (c-string), private Constructors ( default and non-default) Getters and Setters Destructor: to free the memory and print the message “Object with name [PERSON_NAME] is dead” where PERSON_NAME is the person name for the object being disposed. Print function to print the details of the employee. Test your class with the following main: int main() { Person per1; Person per2("Ahmad", "AUS Campus", 21); cout << "Person per1 :\n"; per1.print(); cout << "\nPerson per2 :\n"; per2.print(); cout<<"\nTesting the setters…arrow_forwardC++ Language Write a program that prints a custom conversion table from Celsius temperatures to Fahrenheit and Newton (Links to an external site.) temperatures. The formula for the conversion from Celsius to Fahrenheit is : F=9/5*C+32 F is the Fahrenheit temperature, and C is the Celsius temperature. The formula for the conversion from Celsius to Newton is C = 100/33*N N is the Newton Temperature and C is the Celsius temperature Your program should prompt the user for a lower value and upper value for a range of temperatures in Celsius. It should then prompt the user for the amount they want to increment by. Then use a loop to output to a file named conversion_table.txt a table of the Celsius temperatures and their Fahrenheit and Newton equivalents within the range of values using the increment given by the user. Make sure to format your output to 2 decimal places. INPUT VALIDATION: Ensure the second number is greater than the first number, and make sure the increment is greater…arrow_forward//main.cpp #include "Person.h"#include "Seller.h"#include "Powerseller.h"#include <iostream>#include <list>#include <fstream>#include <string> using namespace std; void printMenu();void printSellers(list<Seller*> sellers);void checkSeller(list<Seller*> sellers);void addSeller(list<Seller*> sellers);void deleteSeller(list<Seller*> &sellers); int main() { list<Seller*> sellers; ifstream infile; infile.open("sellers.dat"); if (!infile) { cerr << "File could not be opened." << endl; exit(1); } char type; while (!infile.eof()) { infile >> type; if (type == 'S') { Seller* newseller = new Seller; newseller -> read(infile); sellers.push_back(newseller); } if (type == 'P') { Powerseller* newpowerseller = new Powerseller; newpowerseller -> read(infile); sellers.push_back(newpowerseller); } } infile.close();…arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_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