-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday#4
58 lines (40 loc) · 1.45 KB
/
day#4
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
#Q16 WAP to use while loop to print table of 8
n = 1
while n<=10:
solution = n * 8
print(f"{n} x 8 = {solution}")
n+=1
#Q17 WAP to use while loop to print hello world 5 times
n = 1
while n<=5:
print("hello world")
n+=1
#Q18 WAP to use while loop to print characters of a string
string = str(input("Enter a string:"))
n = 0
while n < len(string):
print(string[n])
n +=1
#Q19 WAP to input n numbers using while loop and print the greatest one
numbers = input("Enter numbers separated by spaces: ").split()
numbers = [int(num) for num in numbers]
greatest_number = numbers[0]
i = 1
while i < len(numbers):
if numbers[i] > greatest_number:
greatest_number = numbers[i]
i += 1
print("The greatest number is:", greatest_number)
#Q20 WAP to design a function which takes input principal rate and time and prints simple interest as well as compound interest
principal = float(input("Enter the principal amount: "))
rate = float(input("Enter the interest rate: "))
time = float(input("Enter the time period: "))
def calculate_interest(principal, rate, time):
# Simple Interest calculation
simple_interest = (principal * rate * time) / 100
# Compound Interest calculation
compound_interest = principal * ((1 + rate / 100) ** time - 1)
# Print the results
print("Simple Interest:", simple_interest)
print("Compound Interest:", compound_interest)
calculate_interest(principal, rate, time)