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
Juli2301 [7.4K]
3 years ago
6

Python

Computers and Technology
1 answer:
andreyandreev [35.5K]3 years ago
8 0

Answer:

<h2>1)   </h2>

h = 19  # h is already assigned a positive integer value 19

i = 1  # used to calculate perfect square

q = 0   # stores the sum of the perfect squares

while q < h:  

# this loop executes until value of number of perfect squares is less than h

   q = q + (i*i)  # to calculate the sum of perfect squares

   i = i + 1  # increments i by 1 at every iteration

print(q) # displays the sum of perfect squares

Output:

30

Explanation:

Here we see that the sum of the perfect square is printed in the output i.e. 30. If we want to assign value 4 to q then we should alter the code as  following:  

h = 19

i = 1

sum_of_ps = 0

q=0

while sum_of_ps < h:

   sum_of_ps = sum_of_ps + (i*i)

   q = q + 1

   i = i + 1  

print(q)  

If you want to take input from the user and also display the perfect squares in output you can use the following code:

h = int(input('Enter the value of h: ')) #takes value of h from user

i = 1

sum_of_ps = 0

q=0

while sum_of_ps < h:

   sum_of_ps = sum_of_ps + (i*i)

   print(i*i) #displays the perfect squares of h

   q = q + 1

   i = i + 1    

print(sum_of_ps)   #displays sum of perfect squares

print(q) #displays number of perfect squares whose value is less than h

Output:

1

4

9

16

30

4

<h2>2)</h2>

# k and m are already assigned positive integers 10 and 40

k = 10  

m = 40  

i = 1  # i is initialized to 1

q = 0  # q stores the number of perfect squares between k and m

while i*i < m:  # loop computes perfect square of numbers between k and m

   if i*i > k:          

       q = q + 1  # counts the number of perfect squares

   i = i + 1  #increments the value of i at each iteration

print (q) # prints the no of perfect squares between k and m

If you want to display the perfect squares too use , add print(i*i) statement after if statement  if i*i > k:        

Output:

3

<h2>3)</h2>

def Fibonacci(n):  # method Fibonacci which has an integer parameter n

   if n <= 1:  # if the value of n is less than or equals to 1

       result = n  # stores the value of n into result

   elif n > 1:  # else if the value of n is greater than 1

       result = Fibonacci(n-1) + Fibonacci(n-2)  

# calls Fibonacci method recursively to associate nth value of Fibonacci #sequence with variable result

   return result     #returns the final value stored in result variable

print(Fibonacci(8))

#calls Fibonacci function and passes value 8 to it

Output:

21

You might be interested in
If a user has just added a simple triangle shape into a diagram, how can the triangle be adjusted? Check all that apply. by maki
lesantik [10]
The first two make the most sense.
I hope this helps!
7 0
3 years ago
Read 2 more answers
A nonlinear optimization problem is any optimization problem in which at least one term in the objective function or a constrain
MAXImum [283]

Answer:

Yes

Explanation:

A nonlinear optimization problem is indeed a optimization problem in which there are nonlinear elements involved either as the objective function or one or more constraints may be nonlinear also. Let me show you an example. Let optimize de following function:

f(x) = x_{1} +x_{2}

These are the constraints:

x_{1} \geq  0\\x_{2} \geq  0\\\\x_{1} ^{2} +  x^{2}_{2}  \geq  1

The last constraint consists on nonlinear elements, so this problem in fact a nonlinear optimization problem.

5 0
3 years ago
(choose one) Which is the proper means to decrement the integer variable, myScore, by one?
kakasveta [241]

Answer

                                                                                                                                                                                                         

Explanation

its too short please add more characters

7 0
4 years ago
Which of the following is the fastest growing input technique​
Natali [406]
We need more information for this one, please.
8 0
3 years ago
Mike needs to export some animation videos from his smartphone to an online platform. Which common file format can he use for th
Anastasy [175]
The answer would be b
8 0
3 years ago
Other questions:
  • Currently James’s company is using RADIUS for AAA services to connect wireless users to the Windows Active Directory domain. How
    10·1 answer
  • Lance is at a bus station. His friend is using the ATM machine to withdraw some money. Lance notices a stranger deceptively watc
    6·2 answers
  • Which remarketing audiences can be defined in google analytics? (select all that apply)?
    10·1 answer
  • Plese give three examples of specilized servers.
    13·2 answers
  • An it department submits a purchase order to buy a new computer from a vendor. Which hardware lifecycle does this scenario belon
    15·1 answer
  • The physical components of a computer are called hardware
    5·1 answer
  • What episode and Season of Simpsons is this
    10·1 answer
  • Spreadsheets: what is a column?
    15·1 answer
  • Which formatting option(s) can be set for conditional formatting rules?
    9·1 answer
  • Brainliest For Tascake Because People Texted Before Tascake Could<br><br> Hurry Tascake
    13·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!