ict assignment # 4
ict assignment # 4
Question#1
(A)FLOWCHART:
OUTPUT:
(B) CODE:
n=int(input("Enter the number of units
consumed : ")) if n<=100: print("bill = 0 ")
elif n<=300:
print("Bill = ",(n-100)*25)
else:
print("Bill = ",7500+(n-300)*35) #7500 for first 300 units
OUTPUT:
QUESTION # 2
CODE:
while True:
choice = input("Enter your choice (1-
5): ") number=int(input("Enter a
number : "))
if choice == '1':
if number == 0 or number == 1:
factorial = 1
else:
factorial = 1 for i in
range(2, number + 1):
factorial *= i
print(f"The factorial of {number} is
{factorial}")
QUESTION 4
CODE:
sentence = input("Enter a sentence: ")
words = sentence.split(" ")
words_count =
{}
for word in words: if
word in words_count:
words_count[word] += 1
else:
words_count[word] = 1
for word in
words_count:
print(f"{word} : {words_count[word]}")
OUTPUT
QUESTION 5
CODE:
sentence = input("Enter a sentence: ")
words = sentence.split() reversed_words
= words[::-1] reversed_sentence = '
'.join(reversed_words)
print("Reversed sentence:",
reversed_sentence)
OUTPUT: