Initial work
This commit is contained in:
7
CS1032/practical-2023-10-18/fn1.py
Normal file
7
CS1032/practical-2023-10-18/fn1.py
Normal file
@@ -0,0 +1,7 @@
|
||||
def trapezium_area(w1, w2, h):
|
||||
return h * (w1 + w2) / 2
|
||||
|
||||
w1 = int(input("Width of the top: "))
|
||||
w2 = int(input("Width of the bottom: "))
|
||||
h = int(input("Height: "))
|
||||
print(f"Area is {trapezium_area(w1, w2, h)}")
|
||||
20
CS1032/practical-2023-10-18/fn2.py
Normal file
20
CS1032/practical-2023-10-18/fn2.py
Normal file
@@ -0,0 +1,20 @@
|
||||
def bmi(weight, height):
|
||||
return weight * height ** -2
|
||||
|
||||
def bmi_category(bmi):
|
||||
if bmi < 18.5:
|
||||
return "underweight"
|
||||
elif bmi < 25:
|
||||
return "healthy"
|
||||
elif bmi < 30:
|
||||
return "overweight"
|
||||
elif bmi < 40:
|
||||
return "obese"
|
||||
else:
|
||||
return "severely obese"
|
||||
|
||||
weight = float(input("Weight? "))
|
||||
height = float(input("Height? "))
|
||||
bmi = bmi(weight, height)
|
||||
print(f"BMI is {bmi:.3}")
|
||||
print(f"The BMI is in the {bmi_category(bmi)} category")
|
||||
7
CS1032/practical-2023-10-18/fn3.py
Normal file
7
CS1032/practical-2023-10-18/fn3.py
Normal file
@@ -0,0 +1,7 @@
|
||||
def exp(n, p):
|
||||
if p == 0: return 1
|
||||
return n * exp(n, p - 1)
|
||||
|
||||
base = float(input("Base? "))
|
||||
power = int(input("Exponent? "))
|
||||
print(exp(base, power))
|
||||
9
CS1032/practical-2023-10-18/task1.py
Normal file
9
CS1032/practical-2023-10-18/task1.py
Normal file
@@ -0,0 +1,9 @@
|
||||
import random
|
||||
|
||||
randnumber = random.randint(1, 50)
|
||||
|
||||
while True:
|
||||
mynumber = int(input("Please enter a value: "))
|
||||
if randnumber == mynumber:
|
||||
print("[perfect guess, you won....")
|
||||
break
|
||||
2
CS1032/practical-2023-10-18/task2.py
Normal file
2
CS1032/practical-2023-10-18/task2.py
Normal file
@@ -0,0 +1,2 @@
|
||||
for i in range(10, 0, -1):
|
||||
print(i)
|
||||
4
CS1032/practical-2023-10-18/task3.py
Normal file
4
CS1032/practical-2023-10-18/task3.py
Normal file
@@ -0,0 +1,4 @@
|
||||
# If the example output is intended
|
||||
terms = int(input("Enter the Total Number of Terms:\n"))
|
||||
for i in range(16):
|
||||
print(f"2 raised to the power {i} is {2 ** i}")
|
||||
Reference in New Issue
Block a user