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
Python!
Why is there no output to this? It should be "6" as the output but there is nothing. Can someone help me with this in python?
def foo(n):
if (len(n)==0):
return "even"
elif (len(n) == 1):
return "odd"
else:
return foo(n[0:(len(n-2))])
def main():
print(foo("George"))
if __name__ == "main":
main()
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 2 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
- Please explain this Python code def digitalroot(word):if len(word) == 1:print(int(word))return int(word)value = 0for c in word: #loops to sum values of all the chars in the wordvalue += int(c)if (value > 10):print(value)return digitalroot(str(value))#print(ismultiple(2,100))#print(ismultiple(3,100))#fizzbuzzpop()#longstring = input("Sentence to check") #target = ""#while len(target) != 3:# target = input("three letter string")#print(trigrams(longstring,target))#print(trigrams(longstring))w = ""while not w.isdigit():w = input("Number") digitalroot(w)arrow_forwardNeeds to be written in java and completed using "for loops" or "nested for loops" and in one program just seperate methods: Write a program that calls these three methods. method 1 should print: 5 4 3 2 1 4 3 2 1 3 2 1 2 1 1 method 2 should print: 1 2 3 4 5 1 2 3 4 1 2 3 1 2 1 method 3 should create and array and store 10 multiples of 5 and print it out. Use for loop to generate the multiples and then print them out using a second for loop.arrow_forwarddef hailstone(n): h.append(int(n)) if n == 1: return h while n != 1: if n % 2 == 0: return hailstone(int(n/2)) else: return hailstone(int(3*n + 1))y=int(input("N: "))if y <= 0: print("N must be positive!")else: print("Hailstone sequences for 1 to " + str(y) + ":") m=0; i=1 for x in range(1, y+1): n = i h = [] h = hailstone(n) print(h) s=len(h) if s > m: m=s flag=n i=i+1 print("First longest sequence found in n =", + flag ) If i don't one the output have the square braket? How can I fix this code? Can you pleasw help me?arrow_forward
- JAVA Language: Transpose Rotate. Question: Modify Transpose.encode() so that it uses a rotation instead of a reversal. That is, a word like “hello” should be encoded as “ohell” with a rotation of one character. (Hint: use a loop to append the letters into a new string) import java.util.*; public class TestTranspose { public static void main(String[] args) { String plain = "this is the secret message"; // Here's the message Transpose transpose = new Transpose(); String secret = transpose.encrypt(plain); System.out.println("\n ********* Transpose Cipher Encryption *********"); System.out.println("PlainText: " + plain); // Display the results System.out.println("Encrypted: " + secret); System.out.println("Decrypted: " + transpose.decrypt(secret));// Decrypt } } abstract class Cipher { public String encrypt(String s) { StringBuffer result = new…arrow_forwarddef hailstone(n): h.append(int(n)) if n == 1: return h while n != 1: if n % 2 == 0: return hailstone(int(n/2)) else: return hailstone(int(3*n + 1))y=int(input("N: "))if y <= 0: print("N must be positive!")else: print("Hailstone sequences for 1 to " + str(y) + ": ") m=0; i=1 for x in range(1, y+1): n = i h = [] h = hailstone(n) print(*h) print(",") s=len(h) if s > m: m=s flag=n i=i+1 print("First longest sequence found in n =", + flag ) How can I fix this code if I want a comma between each number, not each line?arrow_forwardIn Java: Forms often allow a user to enter an integer. Write a program that takes in a string representing an integer as input, and outputs yes if every character is a digit 0-9. Ex: If the input is: 1995 the output is: yes Ex: If the input is: 42,000 or 1995! the output is: no Hint: Use a loop and the Character.isDigit() function.arrow_forward
- In PYTHON, what is the order of execution sequence for the following code? The digits at the beginning of each line of code only indicate the line numbers. 0:m = 0; n = 1 1: smaller -0 2:for p in range (n + 1) 3: smaller += p 4:if smaller > n: 5: smaller 6:print (smaller) a) 0, 1, 2, 3, 4, 5, 6. b) 0, 1, 2, 3, 4, 6. c) 0, 1, 2, 4, 6. d) 0, 1, 2, 3, 2, 3, 4, 6.arrow_forwardI have two questions: Is my programs code the most effective way at finding recursion or is there a much better and cleaner way? Why is the program showing 0 when I implement a number that depth is greater than 100? Shouldn't it show the number 1? Source code: package recursiveModule; public class RecursiveMethod { public static long calculateFactorial(int n, int depth) { if (depth > 100 || n <= 1) { return 1; } return n * calculateFactorial(n - 1, depth + 1); } public static void main(String[] args) { System.out.println("Factorial of 1 is " + RecursiveMethod.calculateFactorial(1, 0)); System.out.println("Factorial of 8 is " + RecursiveMethod.calculateFactorial(8, 0)); System.out.println("Factorial of 101 is " + RecursiveMethod.calculateFactorial(101, 0)); } }arrow_forwardKeeping data structures and algorithms in mind, can you help me to write these two functions in java? The factorial of a positive integer n —which we denote as n!—is the product of n and the factorial of n − 1. The factorial of 0 is 1. Write two different recursive methods that each return the factorial of n. Include the two methods in a file called Test.java What to submit: The Test.javaarrow_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