1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
jenyasd209 [6]
3 years ago
10

Write the function powersOf3ToN(n) that takes a possibly-negative float or int n, and returns a list of the positive powers of 3

up to and including n. As an example, powersOf3ToN(10.5) returns [1, 3, 9]. If no such powers of 3 exist, you should return the empty list. You may not use loops/iteration in this problem.
Computers and Technology
1 answer:
Paha777 [63]3 years ago
4 0

Answer:

def powersOf3ToN(n):

   try:

       num = int(round(n))

   except (ValueError, NameError, TypeError):

       print("Parameter of the function must be integer or float")

       quit()

   num_list = range(num)

   val_list = [pow(3,x) for x in num_list if pow(3,x) in num_list]

   print(val_list)

powersOf3ToN(30)

Explanation:

The python code prints out a list of integer numbers that are equivalent to the power of three. The function accepts integer and floating numbers but not strings or it prints an error message and quits the program.

You might be interested in
A linear gradient can be positioned from left to right, top to bottom, or on any angle?
Harman [31]

from left to right because it is used more in expressions

3 0
3 years ago
Margaret would like to work in the Journalism and Broadcasting industry. Which set of qualifications would best assist Margaret
8_murik_8 [283]
Critical thinking, accuracy and confidence
7 0
4 years ago
Read 2 more answers
Match the cell reference to its definition
Alisiya [41]

Answer:

which cell reference:-|

6 0
3 years ago
Read 2 more answers
The feature that sets Macs apart from other operating systems is the _____.
pochemuha
What truly sets macs apart is the desktop as they don't have a separate tower system like most other systems do
8 0
3 years ago
Read 2 more answers
Why do some people have random numbers as their usernames?
Angelina_Jolie [31]
Mostly for privacy or to not get caught looking up answers probably
3 0
3 years ago
Read 2 more answers
Other questions:
  • Jason is creating a web page for his school's basketball team. He just finished creating his storyboard. Which tool should he us
    7·1 answer
  • The commands available here change depending on the activity taking place in the presentation window's main work area.
    15·2 answers
  • __________ was awarded the Nobel Prize in physics forhis work on the photoelectric effect.
    13·1 answer
  • Where is the thesis statement usually located in research paper?
    6·1 answer
  • My name Jeff <br><br> what movie is this off of
    6·2 answers
  • A popular encryption method used to protect data that travel over a wireless network is ___
    15·1 answer
  • What is the output?<br> &gt;&gt;&gt; phrase = "hello mom"<br> &gt;&gt;&gt; phrase upper()
    6·2 answers
  • How do I keep my computer and data safe and secure while using the Internet?
    14·2 answers
  • Point out the wrong statement:
    7·1 answer
  • If anyone gotta ps4, i'm a 15 yr old female n if u wanna b frens, hmu :))
    8·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!