CS计算机代考程序代写 python ”’

”’
Dr. A. Euler
Cass Business School
—————————–
Tested with Python 3.7 and 3.8
”’
import math as m
import random as r

##—————————————————————————-
x = float(input(‘Enter a real number: ‘))
print (m.sqrt(x))
##—————————————————————————
n = int(input(‘Enter an integer value: ‘))

pwr = 1.0
for i in range (n):
pwr *= x
print(‘%.2f’%pwr)
##————————————————————————–
rnd = r.uniform(0.0, 1.0)
print (‘%.2f’% rnd)
##————————————————————————–
ni, fi = input(‘Enter initials: ‘).split()

if ni.isupper():
ni = ni.lower()
if fi.isupper():
fi.lower()

print (ni, fi)
##————————————————————————
name = input(‘Enter name: ‘).lower()
print(name)
##————————————————————————
while True:
nper = int(input (‘Enter number of years: ‘))
if nper < 1: continue break while True: fv = float(input('Enter the amount projected at the end of %d years '%nper)) if fv < 0.0: continue break while True: rate = float(input('Enter interest rate[0.0 to 1.0]: ')) if rate <0.0 or rate > 1.0:
continue
break
pv = fv/((1+rate)**nper)
print(‘Present value is £%.2f ‘ %pv)
##——————————————————————-
c = input(‘Enter a character: ‘)
if c and not c.isspace():
print(‘The character in lower case is %s’ %c.lower())
else:
print(‘You entered a white space character!’)
##——————————————————————
s = float(input(‘Enter the stock price [50.00 t 150.00]: ‘))
k= 100
if s > k:
print(‘It is a call with payoff = £%.2f’ % max(s -k, 0))
if s < k: print('It is a put with payoff = £%.2f' % max(0, k - s)) ##----------------------------------------------------------------- rx = 0.15 ry = 0.21 wx, wy = list(input('Enter both of the capital weights [0.0 to 1.0]: ').split()) wx, wy = [float(wx), float(wy)] if (wx + wy) != 1.0: print('Weight for stock y adjusted! ') wy = 1 - wx port_ret = wx*rx + wy *ry print('Return of portfolio is {0:.2%} '.format(port_ret)) ##-------------------------------------------------------------------------------- ##Task 3 similar to various class demos, see moodle. ## words = 'Hello\t\b\nclass! ' counter = 0 i = 0 modified = [] for letter in words: if not letter or letter.isspace(): counter += 1 print('There are %d white space characters in the string! ' % counter) ##-------------------------------------------------------------------------- text = [] print('Enter a line of text (press ctrl^c to end input): ') counter = 0 while True: try: line = input() text.append(line) except: break counter = 0 for line in text: for word in line: for c in word: if c == 'a' or c == 'A': counter += 1 else: continue print ('The frequency of the character ‘a’ (and ‘A’) = %d ' % (counter))