
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 code. Instructions are given below for each function. Run function is already done.
1) def num_to_digit_rec(num, base):
"""
Return a list of digits for num with given base;
Return an empty list [] if base < 2 or num <= 0
"""
# Write your code here
return []
2) def digit_sum(num, base):
"""
Return the sum of all digits for a num with given base
Your implementation should use num_to_digit_rec() function
"""
# Write your code here
return 0
3) def digit_str(num, base):
"""
Given a number and a base, for base between [2, 36] inclusive
Converts the number to its string representation using digits
0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ
to represent digits 0 to 35.
Return the string representation of the number
Return an empty string '' if base is not between [2, 36]
Your implementation should use num_to_digit_rec() function
"""
digits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
# Can not find str representations for base not in [2, 36]
if base > 36 or base < 2:
return ""
# Calculate and return the str representation for num for the given base
# Write your code here
return ""
4) def digit_to_num(rep, base):
"""
Return -1 if base is not between [2,36] inclusive;
or if the string rep contains characters not a digit for the base;
Return the number represented by the string for the given base otherwise.
For example digit_to_num("1001", 2) is 9; digit_to_num("ABC", 16) is 2748.
"""
# Check if the base is valid
if base > 36 or base < 2:
return -1
digits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
rep = rep.upper()
# Check if the rep only uses proper digits
# Write your code here
return 0
5) def uses_only(word, letters):
"""
Return True if word only uses characters from letters;
otherwise return False
"""
# Write your code here
return True
6) def run():
num = int(input("Enter a num: "))
base = int(input("Enter a base: "))
print(f"Digit list is {num_to_digit_rec(num, base)}")
print(f"Digit sum is {digit_sum(num, base)}")
print(f"String Rep is {digit_str(num, base)}")
rep = input(f"Enter a string rep of a num with base {base}: ")
print(f"The number is {digit_to_num(rep, base)}")
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 3 steps with 4 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
- Python programming only NEED HELParrow_forwardPlease do fastarrow_forwardCode following instructions using pyhton: 1. Write a function that accepts a list as an argument (assume the list contains integers) and returns the total of the values in the list 2.Draw a flowchart showing the general logic for totaling the values in a list. 3.Assume the names variable references a list of strings. Write code that determines whether 'Ruby' is in the names list. If it is, display the message 'Hello Ruby'. Otherwise, display the message 'No Ruby'.arrow_forward
- Python programming only NEED HELP PLEASEarrow_forwardNeed help with Python. Paste indented code QUESTION 8 Implement the following:1) Define a function oddList() with an arbitrary parameter a.2) This function accepts any number of integer arguments.3) oddList() stores all odd numbers into a list and returns the list.4) Call the function with 1, 2, 3, 4, 5 as arguments.5) Print the result of the function call. Example Output[1, 3, 5]arrow_forwardWrite a function that accepts two arguments, a list and a number n. The list contains numbers. The function return a list of all the numbers from the input list that are greater than number n. greater_than_n(list, n)arrow_forward
- python LAB: Subtracting list elements from max When analyzing data sets, such as data for human heights or for human weights, a common step is to adjust the data. This can be done by normalizing to values between 0 and 1, or throwing away outliers. Write a program that adjusts a list of values by subtracting each value from the maximum value in the list. The input begins with an integer indicating the number of integers that follow.arrow_forwardTo determine if two lists of integers are equivalent, you must write a function that accepts the lists as input and returns true or false (i.e. contain the same values). The greatest value of each list must be shown if the lists are dissimilar and the procedure is effective.arrow_forwardThe function sum_evens in python takes a list of integers and returns the sum of all the even integers in the list. For example: Test Result print(sum_evens([1, 5, 2, 5, 3, 5, 4])) 6 print(sum_evens([5, 5, -5, -5])) 0 print(sum_evens([16, 24, 30])) 70arrow_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