Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Question
zeroTriples.py: Write a program that reads a list of integers from the user, until they enter -12345 (the -12345 should not be considered part of the list). Then find all triples in the list that sum to zero. You can assume the list won’t contain any duplicates, and a triple should not use the same number more than once.
For example:
$ python3 zeroTriples.py
1
2
4
-12345
0 triples found
$ python3 zeroTriples.py
-3
1
4
2
-12345
1 triple found:
1, 2, -3
$ python zeroTriples.py
-9
1
-3
2
4
5
-4
-1
-12345
4 triples found:
-9, 4, 5
1, -3, 2
-3, 4, -1
5, -4, -1
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution
Trending nowThis is a popular solution!
Step by stepSolved in 2 steps with 4 images
Knowledge Booster
Similar questions
- Language :Python write a program that asks the user to enter a series of single digit numbers with nothing seperating them. The program should display the sum of all the single digit numbers in the string. For example, if the user enters 2514 the method should return 12, which is hw sum of 2,5,1 and 4. write a program that reads a string from the user containing a date in the form mm/dd/yy. it should print the date in the format March 12, 2018.arrow_forwardpython: numpy def not_stealing(items): """ While you're shopping, you notice that some items you've picked up do not have a price tag. Do you steal them? NO! Instead, you decide to be a good person and replace them with another item that does have a price. - Items with no price will have a value of np.nan. - Replace np.nan values with a random price between $5 and $9, inclusive. - Return the average of the new prices in the array, rounded to 2 decimal places. - DO NOT REMOVE random.seed(1) Args: items (np.array) Returns: float >> items = np.array([4.63, np.nan, 3.78, 7.12, 12.35, 7.19, np.nan, 1.50, 2.41]) >> not_stealing(items) 5.66 """ #DO NOT REMOVE# random.seed(1) ############## # items = np.array([4.63, np.nan, 3.78, 7.12, 12.35, 7.19, np.nan, 1.50, 2.41]) # print(not_stealing(items)) # items = np.array([np.nan, np.nan, 6.18, np.nan, 18.42, 2.67, 9.14, np.nan, 14.32]) #…arrow_forwardAsk the user to enter numbers: You must have a way for the user to stop entering numbers. An example would be to have the user type q. Store the numbers the user entered into a list Calculate the total Calculate the average Calculate the largest number Display the following information to the user: How many numbers the user entered The total The average The largest number Print each value with a description do not just print numbers to the console. Describe each number as they print.arrow_forward
- increasingDigits.py: Write a program to count all integers from 1 to n(inclusive) that have all digits in increasing order, where nis given as a command-line argument. For example, • 5 is in increasing order (single digit)• 237 is in increasing order (2 < 3 < 7)• 227 is not (2 !< 2)• 427 is not (4 !< 2) $ python3 increasingDigits.py 3024arrow_forwardCcxxarrow_forwardPYTHON CODE Reza Enterprises sells tickets for buses, tours, and other travel services. Because Reza frequently mistypes long ticket numbers, Reza Enterprises has asked his students to write an application that shows if a ticket is invalid. Your application/program tells the ticket agent to enter a six-digit ticket number. Ticket numbers are designed so that if you lose the last digit of the number, then divide by 7, the remainder of the division is exactly the same to the last dropped digit. This process is shown below: Step 1: Enter the ticket number; for example 123454 Step 2: Remove the last digit, leaving 12345 Step 3: Determine the remainder when the ticket number from step 2 is divided by 7. In this case, 12345 divided by 7 leaves a remainder of 4. Step 4: Display a message to the ticket agent indicating whether the ticket number is valid or not. If the ticket number is valid, save the number to a .txt file called “tickets.txt” and continue to loop your program asking…arrow_forward
- Homework* - Prime factors and prime numbers: Write a program that prompts the user to enter a positive integer which is greater than one and displays all its smallest factors in decreasing order. For example, if the integer is 140, the smallest factors are displayed as 7, 5, 2, 2. Use the StackOflntegers class to store the factors (e.g., 2, 2, 5, 7) and retrieve and display them in reverse order. After that, write a program that displays all the prime numbers less than the number – which is used in the prime factors (e.g: 140)- in decreasing order. Use the StackOflntegers class to store the prime numbers (e.g., 2, 3, 5, ...) and retrieve and display them in reverse order. Here is the sample runs: To use the prime factors you must enter a positive integer which is greater than one: 140 7 5 2 2 Printing prime numbers under 140: 139 137 131 127 113 109 107 103 101 97 89 83 79 73 71 67 61 59 53 47 43 41 37 31 29 23 19 17 13 11 7 5 3 2 * This homework has a part of Challenge Question.arrow_forwardGiven the code that reads a list of integers, complete the number_guess() function, which should choose a random number between 1 and 100 by calling random.randint() and then output if the guessed number is too low, too high, or correct. Import the random module to use the random.seed() and random.randint() functions. • random.seed(seed value) seeds the random number generator using the given seed value. • random.randint(a, b) returns a random number between a and b (inclusive). For testing purposes, use the seed value 900, which will cause the computer to choose the same random number every time the program runs.arrow_forwardC#Write a method MyMethod which takes an int parameter named x. This method calculates the sum of integers from 1 to x and returns the sum. Use a for loop.arrow_forward
- Using C# create a console app doing the following Write a method that takes two integers and displays their sum. Write a method that takes five doubles and returns their average. Write a method that returns the sum of two randomly generated integers. Write a method that takes three integers and returns true if their sum is divisible by 3, false otherwise. Write a method that takes two strings and displays the string that has fewer characters. Write a method that takes an array of doubles and returns the largest value in the array. Write a method that generates and returns an array of fifty integer values. Write a method that takes two bool variables and returns true if they have the same value, false otherwise. Write a method that takes an int and a double and returns their product. Write a method that takes a two-dimensional array of integers and returns the average of the entries.arrow_forwardPrimeAA.java Write a program that will tell a user if their number is prime or not. Your code will need to run in a loop (possibly many loops) so that the user can continue to check numbers. A prime is a number that is only divisible by itself and the number 1. This means your code should loop through each value between 1 and the number entered to see if it’s a divisor. If you only check for a small handful of numbers (such as 2, 3, and 5), you will lose most of the credit for this project. Include a try/catch to catch input mismatches and include a custom exception to catch negative values. If the user enters 0, the program should end. Not only will you tell the user if their number is prime or not, you must also print the divisors to the screen (if they exist) on the same line as shown below AND give a count of how many divisors there are. See examples below. Your program should run the test case exactly as it appears below, and should work on any other case in general. Output…arrow_forwardshow: Lists the items that the wizard is currently carrying along with the index for each item and the weight of that item. See sample runs below. As shown in the sample this function also prints the total weight of the items along with the max weight limit of 100 lbs. Hint: You can use the sum function in Python to calculate the sum of weights. E.g. sum(weights) will return the sum of all the items in the weights list. grab_item: Add a new item while enforcing the following policy: There is a limit of 4 on the number of items the wizard can carry and limit of 100 lbs on the total weight the wizard can carry. So specifically, if the wizard is already carrying 4 items, print message that “You can't carry anymore items. Drop something first.” And return out of the function. Otherwise prompt the user for the name and the weight of the new item. Next check whether with the addition of the new item, the total weight will exceed the limit of 100 lbs. If so, print a message saying weight…arrow_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