-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgramming_Assignment_6.py
More file actions
73 lines (56 loc) · 1.61 KB
/
Programming_Assignment_6.py
File metadata and controls
73 lines (56 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
1. Python Program to Display Fibonacci Sequence Using Recursion:
```python
def fibonacci(n):
if n <= 1:
return n
else:
return (fibonacci(n-1) + fibonacci(n-2))
n = int(input("Enter the number of terms: "))
print("Fibonacci sequence:")
for i in range(n):
print(fibonacci(i))
```
2. Python Program to Find Factorial of Number Using Recursion:
```python
def factorial(n):
if n == 0:
return 1
else:
return n * factorial(n-1)
num = int(input("Enter a number: "))
result = factorial(num)
print("The factorial of", num, "is", result)
```
3. Python Program to Calculate Body Mass Index (BMI):
```python
height = float(input("Enter your height in meters: "))
weight = float(input("Enter your weight in kilograms: "))
bmi = weight / (height ** 2)
print("Your Body Mass Index (BMI) is:", bmi)
if bmi < 18.5:
print("You are underweight.")
elif bmi >= 18.5 and bmi < 25:
print("You have a normal weight.")
elif bmi >= 25 and bmi < 30:
print("You are overweight.")
else:
print("You are obese.")
```
4. Python Program to Calculate the Natural Logarithm of a Number:
```python
import math
num = float(input("Enter a number: "))
result = math.log(num)
print("The natural logarithm of", num, "is", result)
```
5. Python Program for Cube Sum of First n Natural Numbers:
```python
def cube_sum(n):
if n == 0:
return 0
else:
return n**3 + cube_sum(n-1)
n = int(input("Enter the value of n: "))
result = cube_sum(n)
print("The cube sum of the first", n, "natural numbers is:", result)
```