PYTHON FUNCTIONS PLEASE! Write function headers with comments for the tasks desc
ID: 3687226 • Letter: P
Question
PYTHON FUNCTIONS PLEASE!
Write function headers with comments for the tasks described below. Computing the larger of two integers Computing the smallest of three floating-point numbers Checking whether an integer is a prime number, returning True if it is and False otherwise Checking whether a string is contained inside another string Computing the balance of an account with a given initial balance, an annual interest rate, and a number of years of earning interest Printing the balance of an account with a given initial balance and an annual interest rate over a given number of years Printing the calendar for a given month and year Computing the day of the week for a given day, month, and year (as a string such as "Monday") Generating a random integer between 1 and nExplanation / Answer
a).
a = 10
b =7
print max(a,b)
b).
a = 10.0
b =7.009
c = 7.0001
print min(a,b,c)
c).
num = int(input("Enter a number: "))
if num > 1:
for i in range(2,num):
if (num % i) == 0:
print("False")
break
else:
print("True")
else:
print("False")
d).
if "ABCD" in "xxxxABCDyyyy":
print "True"
else :
print "False"
e).
initial = 100000
rate = 6
years =1
print initial + ((initial*rate*years)/100)
f).
initial = 100000
rate = 6
years =1
print initial + ((initial*rate*years)/100)
g).
import calendar
yy = int(input("Enter year: "))
mm = int(input("Enter month: "))
print(calendar.month(yy,mm))
h).
def weekDay(year, month, day):
offset = [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334]
week = ['Sunday',
'Monday',
'Tuesday',
'Wednesday',
'Thursday',
'Friday',
'Saturday']
afterFeb = 1
if month > 2: afterFeb = 0
aux = year - 1700 - afterFeb
# dayOfWeek for 1700/1/1 = 5, Friday
dayOfWeek = 5
# partial sum of days betweem current date and 1700/1/1
dayOfWeek += (aux + afterFeb) * 365
# leap year correction
dayOfWeek += aux / 4 - aux / 100 + (aux + 100) / 400
# sum monthly and day offsets
dayOfWeek += offset[month - 1] + (day - 1)
dayOfWeek %= 7
return week[dayOfWeek]
yy = int(input("Enter year: "))
mm = int(input("Enter month: "))
dd = int(input("Enter Day: "))
print weekDay(yy, mm, dd)
i). Give the value of the n here
from random import randint
print(randint(0,n))
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.