-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgramming_Assignment_4.py
More file actions
80 lines (65 loc) · 1.92 KB
/
Programming_Assignment_4.py
File metadata and controls
80 lines (65 loc) · 1.92 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
74
75
76
77
78
79
80
1. Write a Python Program to Find the Factorial of a Number:
```python
def factorial(n):
if n == 0 or n == 1:
return 1
else:
return n * factorial(n-1)
num = int(input("Enter a number: "))
result = factorial(num)
print(f"The factorial of {num} is {result}")
```
2. Write a Python Program to Display the multiplication Table:
```python
num = int(input("Enter a number: "))
print(f"Multiplication table of {num}")
for i in range(1, 11):
print(f"{num} x {i} = {num*i}")
```
3. Write a Python Program to Print the Fibonacci sequence:
```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))
```
4. Write a Python Program to Check Armstrong Number:
```python
num = int(input("Enter a number: "))
original_num = num
result = 0
while num > 0:
digit = num % 10
result += digit ** len(str(original_num))
num //= 10
if original_num == result:
print(f"{original_num} is an Armstrong number")
else:
print(f"{original_num} is not an Armstrong number")
```
5. Write a Python Program to Find Armstrong Number in an Interval:
```python
start = int(input("Enter the start of the interval: "))
end = int(input("Enter the end of the interval: "))
print("Armstrong numbers in the given interval are:")
for num in range(start, end+1):
original_num = num
result = 0
while num > 0:
digit = num % 10
result += digit ** len(str(original_num))
num //= 10
if original_num == result:
print(original_num)
```
6. Write a Python Program to Find the Sum of Natural Numbers:
```python
num = int(input("Enter a number: "))
sum_of_numbers = (num * (num + 1)) // 2
print(f"The sum of first {num} natural numbers is {sum_of_numbers}")
```