~~~MUST BE IN PYTHON!! NOT JAVE~~~ NEED 8.4, 9.2, 9.7 - WILL INCREASE POINTS IF
ID: 638280 • Letter: #
Question
~~~MUST BE IN PYTHON!! NOT JAVE~~~
NEED 8.4, 9.2, 9.7 - WILL INCREASE POINTS IF I GET THESE FAST ENOUGH, AND IF THEY ARE RIGHT!!
8.4 (Occurrences of a specified character) Write a function that finds the number of occurrences of a specified character in a string using the following header:
def count(s, ch):
The str class has the count method. Implement your method without using the count method. For example, count("Welcome", 'e') returns 2. Write a test program that prompts the user to enter a string followed by a character and displays the number of occurrences of the character in the string.
Explanation / Answer
8.4)
def string(strin,ch):
count=0
for c in strin:
if c ==ch:
count=count+1
return count
9.2)
def future_value():
investmentAmount=float(raw_input("Enter the amount to invest: "))
monthlyInterestRate=float(raw_input("Enter the interest rate : "))
years=float(raw_input("Enter the number of years: "))
futureValue=investmentAmount * (1 + monthlyInterestRate) **(years*12)
return futureValue
9.7)
import random
def main():
num=int(raw_input())
matrix(num)
def matrix(n):
listy=[]
for i in range(n*n):
listy.append('0')
print listy
for j in range(random.randint(0,n*n)):
random_position=random.randint(0,n*n-1)
listy[random_position]='1'
pos=0
for i in range(n):
for j in range(n):
print listy[pos],
pos=pos+1
print ' '
if __name__ == '__main__':
main()
last one not in GUI, but it displays the matrix of two numbers 0,1. can be treated as colors.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.