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
Aim: Read a string, S and print its integer value. If S cannot be converted to | |
an integer, print Bad String. | |
''' | |
# getting the input | |
S = input().strip() | |
try: | |
# if it's possible to convert the entered string into an integer then this block will execute | |
print(int(S)) | |
except: | |
# if it's not possible, then this block will be executed | |
print('Bad String') | |
''' | |
COMPLEXITY: | |
Time Complexity -> O(1) | |
Space Complexity -> O(1) | |
Sample Input 1: | |
3 | |
Sample Output 1: | |
3 | |
Sample Input 2: | |
SB | |
Sample Output 2: | |
Bad String | |
Explaination: | |
'3' as a string can be converted into the integer 3, whereas SB can't be | |
converted to an integer hence the 'except' block is executed and 'Bad String' | |
is printed. | |
|
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by stepSolved in 3 steps with 1 images
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
- 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: Comarrow_forward// Write a function that takes 1 argument, a string. // It returns true if the string is a palindrome (the same forwards and backwards). // It returns false if the string is not a palindrome. const isPalindrome = (string) => { // your code here... // Examples isPalindrome("cat") // returns false //isPalindrome("level") // returns true }arrow_forwardsloc) 1. # Given an encoded string, return it's decoded string. # The encoding rule is: k[encoded_string], where the encoded_string# inside the square brackets is being repeated exactly k times.# Note that k is guaranteed to be a positive integer. # You may assume that the input string is always valid; No extra white spaces,# square brackets are well-formed, etc. # Furthermore, you may assume that the original data does not contain any# digits and that digits are only for those repeat numbers, k.# For example, there won't be input like 3a or 2[4]. # Examples: # s = "3[a]2[bc]", return "aaabcbc".# s = "3[a2[c]]", return "accaccacc".# s = "2[abc]3[cd]ef", return "abcabccdcdcdef".arrow_forward
- String personName is read from input. Output personName left aligned with a width of 6, followed by " Taylor". End with a newline. Ex: If the input is Juno, then the output is: Juno Taylorarrow_forward(1) Prompt the user for a string that contains two strings separated by a comma • Examples of strings that can be accepted: • Jill, Allen • Jill, Allen • Jill, Allen Ex: Enter input string: Jill, Allen (2) Print an error message if the input string does not contain a comma. Continue to prompt until a valid string is entered. Note: If the input contains a comma, then assume that the input also contains two strings Ex: Enter input string: Jill Allen Error: No comma in string. Enter input strings ming Fundamentals home > 9.11: LAB: Warm up: Parsing strings Ex: (3) Extract the two words from the input string and remove any spaces. Store the strings in two separate variables and output the strings. Enter input string: Jill, Allen First word: Jill Second word: Allen (4) Using a loop, extend the program to handle multiple lines of input. Continue until the user enters q to quit Ex: Enter input string: Jill, Allen First word: Jill Second word: Allen 0 Enter input string: Golden Monkey , First…arrow_forwardJava Programming: Question 12 Not sure how to do this question. Help of any input and output would be appreciated.arrow_forward
- Python question Application: Python Fragment Formulation (Q1 – Q4) In this group of questions you are asked to produce short pieces of Python code. When you are asked to "write a Python expression" to complete a task, you can either give the expression in one line or break down the task into several lines. The last expression you write must represent the required task. Question 1 (Reduce parentheses) Give an equivalent version of this expression by removing as many redundant parentheses as possible, without expanding the brackets or simplifying. (x**(2**y))+(y*((z+x)**3)) Question 2 (Translate arithmetic concept into Python) You are given a list of numbers, named numbers, containing 3 integers. Write a python expression (one line) that evaluates to True if and only if the product of any two numbers in the given list is greater than the sum of all three numbers. Note: the product of two numbers, x and y is x*y. Question 3 (List/table access) You are given a table,…arrow_forward1 # Write a program that reads a single integer N from the user. 2 # It then prints the string: "Is N your favorite number?"arrow_forwardcorrect all errors.arrow_forward
- JAVA PPROGRAM ASAP Please create this program ASAP BECAUSE IT IS MY LAB ASSIGNMENT #2 so it passes all the test cases. The program must pass the test case when uploaded to Hypergrade. Chapter 9. PC #8. 8. Sum of Numbers in a String (page 610) Write a program that asks the user to enter a series of numbers separated by commas. Here are two examples of valid input: 7,9,10,2,18,6 8.777,10.9,11,2.2,-18,6 The program should calculate and display the sum of all the numbers. Input Validation 1. Make sure the string only contains numbers and commas (valid symbols are '0'-'9', '-', '.', and ','). 2. If the string is empty, a messages should be displayed, saying that the string is empty. Test Case 1 Enter a series of numbers separated only by commas or type QUIT to exit:\n7,9,10,2,18,6ENTERThe sum of those numbers is 52.00\nEnter a series of numbers separated only by commas or type QUIT to exit:\nENTEREmpty string.\nEnter a series of numbers separated only by…arrow_forward9. Use string methods to extract the website domain from an email, e.g., from the string "tomas.beuzen@fakemail.com", you should extract "fakemail". [) enail = "tonas. beuzengfakenail.com # Your answer here. • 10. Given the variable language which contains a string, use if/elif/else to write a program that: • return "I love snakes!" if language is "python" (any kind of capitalization) • return "Are you a pirate?" if language is "R" (any kind of capitalization) • else return "What is language ?" if language is anything else. O language = "python" # Your answer here.arrow_forward
arrow_back_ios
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