Question

In: Computer Science

This is Python coding question, and topic is loop Can anyone help me figuring these out?...

This is Python coding question, and topic is loop

Can anyone help me figuring these out?

(Please do not use build in function)

Thanks.

1. Write a program that prints your name 100 times to the screen.

2. Write a program that takes a string s and an integer n as parameters and prints the string s a total of in n times(once per line)

3. Write a for loop that prints all the integers from 3141 to 5926, skipping every other one.

4. Write a for loop that prints every 5th integer from 5926 down to 3141

5. Write a function square that takes two parameters, a string s and an integer l and prints a square of size l using the string. For example, square(‘‘Q’’, 5) should produce the following output:

   QQQQQ
   QQQQQ
   QQQQQ
   QQQQQ
   QQQQQ

6. Write a program (using a for loop) to compute the following sum and print only the total: 3^1 +3^2 +3^3 +...+3^20.

7. Write a function that takes two integer parameters a and n, and returns the sum a^1 +a^2 +...+a^n.

8. A mortgage loan is charged interest every month based on the current balance of the loan. If the annual rate is r%, then the interest for the month is r/12% of the current balance. After the interest is applied each month, the borrower makes a payment which reduces the amount owed. Write a function mortgage(principal, rate, years, payment) that prints out the balance at the end of each month foryears number of years.

9. Write a function that takes an integer parameter n and returns the nth Fibonacci number. The Fibonacci numbers start 1,1,2,3,5,8,... and every subsequent one is the sum of the previous two.

Solutions

Expert Solution

Program 1

name=input("Enter yor name : ")
for i in range(100):
print(name)

Screenshot

Program 2

s=input("Enter a string : ")
n=int(input("Enter an integer : "))
for i in range(n):
print(s)

Screenshot

Program 3

for i in range(3141,5927):
print(i)
Screenshot

Program 4

for i in range(5926,3141,-5):
print(i)

Screenshot

Program 5

def square(s,l):
for i in range(l):
for j in range(l):
print(s,end="")
print()
def main():
s=input("Enter a string : ")
l=int(input("Enter an integer : "))
square(s,l)
main()

Screenshot

Output

Enter a string : Q
Enter an integer : 5
QQQQQ
QQQQQ
QQQQQ
QQQQQ
QQQQQ

Program 6

total=0
for i in range(20):
total=total+pow(3,i)   
print(total)

Screenshot

Program 7

def total(a,n):
sum=0
for i in range(n):
sum=sum+pow(a,i)   
return sum

def main():
a=int(input("Enter a :"))
n=int(input("Enter n :"))
print("Sum =",total(a,n))
main()

Screenshot

Program 9

def Fibonacci(n):
if n<0:
print("Incorrect input")
elif n==0:
return 0
elif n==1:
return 1
else:
return Fibonacci(n-1)+Fibonacci(n-2)
  


def main():
n=int(input("Enter n :"))
print(Fibonacci(n))
  
main()

Output

Enter n :8
21

Screenshot


Related Solutions

can anyone please help me woth graphs and business report for business computing?
can anyone please help me woth graphs and business report for business computing?
Using C programming make one for loop Description For this problem you will be figuring out...
Using C programming make one for loop Description For this problem you will be figuring out if it is more beneficial to pay off your loans first before investing or if you should only make the minimum payments and invest the rest. Some things to pay attention to Interest rates given are annual interests rates but we will be assuming that interest is compounded monthly so the real rates to use will be 1/12 of what we are given We...
I figured out the weighted average method, but can anyone show me the FIFO and LIFO...
I figured out the weighted average method, but can anyone show me the FIFO and LIFO treatment of this problem???? Timekeeper Inc. manufactures clocks on a highly automated assembly line. Its costing system uses two cost categories, direct materials and conversion costs. Each product must pass through the Assembly Department and the Testing Department. Direct materials are added at the beginning of the production process. Conversion costs are allocated evenly throughout production. Timekeeper Inc. uses weighted-average costing. Data for the...
I am having difficulties with figuring out the formulas for this this question. Is there a...
I am having difficulties with figuring out the formulas for this this question. Is there a walk-through for this? You are the manager of a monopoly that sells a product to two groups of consumers in different parts of the country. Group 1’s elasticity of demand is -2, while group 2’s is -3. Your marginal cost of producing the product is $30. a. You are a monopolist. b. You compete against one other firm in a Cournot oligopoly. c. You...
​​​​​​This is an assignment that I'm having trouble figuring out in python: Modify Node class so...
​​​​​​This is an assignment that I'm having trouble figuring out in python: Modify Node class so it has a field called frequency and initialize it as one. Add a search function. If a number is in the list, return its frequency. Modify Insert function. Remove push, append, and insertAfter as one function called insert(self, data). If you insert a data that is already in the list, simply increase this node’s frequency. If the number is not in the list, add...
can anyone give me an example of a job analysis?
can anyone give me an example of a job analysis?
can anyone summarize for me the below passage and to add for me some information that...
can anyone summarize for me the below passage and to add for me some information that u get from the below passage Thank You Theory of Reasoned Action stresses the importance of attitudes and intentions in changing a behavior. According to this theory, the most important determinant of behavior is intention.23 Very few actions that produce a healthy outcome happen without ample knowledge and full intention to practice the healthy behavior. Two cognitive processes are at work to develop healthy...
Can anyone tell me about the measurement of ICP-AES?
Can anyone tell me about the measurement of ICP-AES?
Can anyone give me a summary on "Dismantling the doctrine of Discovery" ?
Can anyone give me a summary on "Dismantling the doctrine of Discovery" ?
2) create a python program that uses a for loop and range to print out the...
2) create a python program that uses a for loop and range to print out the values 10 8 6 4 2 3) Create a python program that yses a for loop to print out ["bob","al","bert"]
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT