Page 112 - Code_GPT_Class_8
P. 112
Scratch Your Brain. 21 st Century #Critical Thinking
Skills
1. Write the output of the following programs:
a. sum = 0
for x in range(1, 11):
sum =sum+ x
print(sum)
b. for i in range (2, 100, 2):
if i % 3 == 0:
break
print(i)
c. total_sum = 0
num = 1
while num <= 5:
total_sum += num
num += 1
print("The sum of numbers from 1 to 5 is:", total_sum)
d. num = 5
factorial = 1
i = 1
while i <= num:
factorial *= i
i += 1
print("The factorial of", num, "is:", factorial)
e. correct_number = 7
user_guess = 0
while user_guess != correct_number:
user_guess = int(input("Guess the number
(between 1 and 10): "))
if user_guess == correct_number:
print("Congratulations! You guessed the
correct number.")
else:
print("Wrong guess. Try again!")
print("Game over.")
CodeGPT (Ver. 4.0)-VIII
110

