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
Sammy created a new logo for his client enlarged to use on a billboard ad. Now Sammy needs to redo the logo. What should he do t
bazaltina [42]

Answer:

The answer is D. In order to make an advertisement, the photo or photos have to be clear and easy to see. They also have to stay clear when they are enlarged

Explanation:

4 0
3 years ago
The hardware that takes the input data and works with it
pogonyaev

Answer:

Examples of input devices include keyboards, mice, scanners, digital cameras and joysticks.

Explanation:

5 0
3 years ago
3. Write a program that inputs 4 hexadecimal digits as strings (example 7F), converts the string digits to a long – use strtol(i
never [62]

Answer:

#include <stdio.h>

#include <stdlib.h>

int main()

{

char num1[20],num2[20],num3[20],num4[20];

//Checks where the conversion of string to long stops and is required by strtol

char *ptr;

//Stores the converted number string into long.

long result_num1,result_num2,result_num3,result_num4;

//Prompt to enter all the four hexadecimal numbers.

printf("Enter the first hexadecimal number: ");

scanf("%s",num1);

printf("Enter the second hexadecimal number: ");

scanf("%s",num2);

printf("Enter the third hexadecimal number: ");

scanf("%s",num3);

printf("Enter the fourth hexadecimal number: ");

scanf("%s",num4);

//Converting the hexadecimal numbers into long using strtol() function with base 16 for hexadecimal.

result_num1 = strtol(num1,&ptr,16);

result_num2 = strtol(num2,&ptr,16);

result_num3 = strtol(num3,&ptr,16);

result_num4 = strtol(num4,&ptr,16);

//Casting the long to unsigned chars.

unsigned char numb1 = (unsigned char)result_num1;

unsigned char numb2 = (unsigned char)result_num2;

unsigned char numb3 = (unsigned char)result_num3;

unsigned char numb4 = (unsigned char)result_num4;

//Applying the boolean operation on unsigned chars and storing the resultant value in result.

unsigned char result = ((numb1&numb2)|numb3)^numb4;

//Printing the result in capital hex ("%X" take care of this).

printf("%X",result);

return 0;

}

Code OUTPUT

Enter the first hexadecimal number: 1 Enter the second hexadecimal number:2

Enter the third hexadecimal number: 3 Enter the fourth hexadecimal number: 4 Resultant Value: 7 Process returned o (0×0) execution time : 3.076 s

Press any key to continue

4 0
3 years ago
Write a code that calculates the Greatest Common Divisor (GCD) of two positive integers (user-defined inputs). Include an except
STALIN [3.7K]

Answer:

<em>This program is written using Java programming language</em>

import java.util.*;

public class calcGcd

{

   public static void main (String [] args)

   {

       int num1, num2;

       Scanner input = new Scanner(System.in);

       //Input two integers

       num1 = input.nextInt();

       num2 = input.nextInt();

       //Get least of the two integers

       int least = num1;

       if(num1 > num2)

       {

           least = num2;

       }

       //Initialize gcd to 1

       int gcd = 1;

       //Calculate gcd using for loop

       for(int i=1;i<=least;i++)

       {

           if(num1%i == 0 && num2%i == 0)

           {

               gcd = i;

           }

       }

       if(gcd == 1)

       {

           System.out.print("GCD is 1");

       }

       else

       {

           System.out.print("GCD is "+gcd);

       }

   }

}

Explanation:

To calculate the GCD, the program uses a for loop that iterates from 1 to the smaller number of the user input.

Within this iteration, the program checks for a common divisor of the two user inputs by the iterating element

The GCD is then displayed afterwards;

However, if the GCD is 1; the program prints the message "GCD is 1"

<em>Line by Line Explanation</em>

This line declares two integer numbers

       int num1, num2;

This line allows user the program to accept user defined inputs        

Scanner input = new Scanner(System.in);

The next two line allows gets inputs from the user

<em>        num1 = input.nextInt();</em>

<em>        num2 = input.nextInt();</em>

<em />

To calculate the GCD, the smaller of the two numbers is needed. The smaller number is derived using the following if statement

<em>        int least = num1;</em>

<em>        if(num1 > num2)</em>

<em>        {</em>

<em>            least = num2;</em>

<em>        }</em>

The next line initializes GCD to 1

       int gcd = 1;

The GCD is calculated using the following for loop

The GCD is the highest number that can divide both numbers

<em>        for(int i=1;i<=least;i++)</em>

<em>        {</em>

<em>            if(num1%i == 0 && num2%i == 0)</em>

<em>            {</em>

<em>                gcd = i;</em>

<em>            }</em>

<em>        }</em>

The following is printed if the calculated GCD is 1

       if(gcd == 1)

       {

           System.out.print("GCD is 1");

       }

Otherwise, the following is printed

       else

       {

           System.out.print("GCD is "+gcd);

       }

8 0
3 years ago
Conflict on cross-cultural teams
mars1129 [50]

Answer:

A : is inevitable and should just be ignored until it blows over

Explanation:

Hopefully this helps!

3 0
3 years ago
Read 2 more answers
Other questions:
  • When you are duplicating an object, what does the Rows field number tell you?
    10·1 answer
  • What differences in traffic patterns account for the fact that STDM is a cost-effective form of multiplexing for a voice telepho
    10·1 answer
  • A range of cells can be converted into an Excel ________ so that the data can be analyzed
    7·1 answer
  • अस्स्मन्चचरे ------------------- दृश्यते |
    8·1 answer
  • 1. What runs horizontally and is identified with numbers?
    12·2 answers
  • My sister put my phone in the microwave and I'm pretty sure the battery blew up. I'm too scared to open the microwave. What do I
    11·1 answer
  • Which formatting option(s) can be set for Conditional Formatting rules?
    8·2 answers
  • Under which tab would you look to find the Show in Groups and advanced sort options for messages in Outlook?
    11·2 answers
  • How can having more than one goal cause truble in the work place
    6·1 answer
  • 3 uses of Microsoft word in hospital
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!