![CateL1515](/avatars/27186.jpg)
CateL1515
27.07.2019 •
Computers and Technology
How do i place a bald eagle, bay grasses,crab larvae,anchovy,and rockfish in a food chain
Solved
Show answers
More tips
- F Food and Cooking Delight for Gourmets: How to Prepare Liver Pate...
- S Style and Beauty How to braid friendship bracelets?...
- H Health and Medicine Mercury Thermometer Danger: What to do when a thermometer breaks?...
- F Food and Cooking Which Calamari Salad is the Most Delicious?...
- S Society and Politics 10 Tips for Boosting Your Self-Esteem...
- F Food and Cooking The Most Delicious and Simple Fish in Batter Recipe...
- H Health and Medicine What is Autism? Understanding the Basics of This Neurodevelopmental Disorder...
- P Philosophy How to Develop Extrasensory Abilities?...
- S Style and Beauty Don t Sacrifice Your Brows: How to Properly Pluck Stubborn Hairs...
- W Work and Career 10 Best Ways To Find A Job: Tips To Land Your Dream Job...
Answers on questions: Computers and Technology
- M Mathematics Please solve it please solve it...
- P Physics Identify five people whom you know and consider to be mature, based on the list above. mature person 1: explain how you know this person. mature person 2: explain...
- E English 1. What does Randy mean by all of this? Make an inference about what Bob was searching for. THE OUTSIDERS STORY...
- M Mathematics F r e e. p o i n t s have a great day! 3...
- E English The following sentences may contain a comma error. If a sentence has an error, select the answer option that corrects it. If the sentence is correct, select no change....
Ответ:
Ответ:
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
2)# 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
3)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