Tutorial 2

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

Assign 1

def savings(amount,number_of_weeks):
total=amount*number_of_weeks
return total

################################
x=int(input('enter an amount>'))
y=int(input('number of weeks>'))
tot=savings(x,y)
print('you can save $',tot,'over',y,'weeks')

part 1

#EXERCISE A
def total (a,b,c):
sum = a+b+c
return sum
t1 = total (2,3,4) + total (4,6,8)
print(t1)

#exercise B
def banner(name):
print("****************")
print(" " + name)
print("****************")

banner("i'm mango")

#excerxise C
def someFc(s):
s = s * 2
return s

food = 'bread'
someFc(food)
print(food)
print(someFc('egg'))

#excercise D
def double(x):
print('from double:',x)
return x*3

def subtract(y,z):
print('from subtract:',y,'and',z)
return y - z

result = subtract(20, double(10))


print(result)

#excercice E
def blah():
x=2015
print(x)
x = 234
print(x)

#excercise F
def block(x):
x = x+3

x = 5.6
block(x)
print(x)

#excericse G
def test(a):
a = 1.5*a
return a
a = a/0.1
x = 10
x = test(x)
print(x)

Part 2

import math
#excercise A
def gst(x):
return(0.15*x)
def total_gst(x,y,z):
x=gst(x)
y=gst(y)
z=gst(z)
return x+y+z

x=float(input("enter the total gst:"))


y=float(input("enter the total gst:"))
z=float(input("enter the total gst:"))
print(total_gst(x,y,z))

#excercise B
def price(x):
x=0.15
return price
price=50
print("price")

#excercise C
num1=float(input('please enter the cost of one ticket:'))
num2=float(input('please enter the number of tickets wanted:'))
print("the total cost for all tickets is",num1*num2)
#excercise D
def towncount(city,year):
number_of_people=1000000
return number_of_people
year=2011
city="blonkton"

print("in 2011 the population was",towncount(city,year))

part 3

#excercise A

def avg(x,y,z):
return((x+y+z)/3)
x=float(input("the value of first num:"))
y=float(input("the value of second num:"))
z=float(input("the value of third num:"))
print("the avg is",avg(x,y,z))

#excercise B

def avg4(x,y,z,w):
return((x+y+z+w)/4)

x=float(input("the value of first num:"))


y=float(input("the value of second num:"))
z=float(input("the value of third num:"))
w=float(input("the value of fourth num:"))
print("the avg4 is",avg4(x,y,z,w))

#excercise C
import math
pi=math.pi
def volume(r):
v=(4/3)*pi*r*r*r
return v

r=float(input("enter r:"))
print(volume(r))

#
def totalresistance(r1,r2,r3):
r=1/((1/r1)+(1/r2)+(1/r3))
return r
r1=float(input("enter r1:"))
r2=float(input("enter r2:"))
r3=float(input("enter r3:"))
print(totalresistance(r1,r2,r3))
#
def temperature_in_fahrenheit(c):
f=c*9/5+32
return f
c=float(input("enter c:"))
print(temperature_in_fahrenheit(c))

#
def value(x):
y=3*x**2-5*x+10
return y
x=float(input("enter x"))
print(value(x))

You might also like