Section1 Programming 2-Python
Section1 Programming 2-Python
PROGRAMMING
EXERCISE 1:
Write a python program that accepts two integer numbers and an
operator, like (+, -,*,/), and perform the operation indicated by the
operator, and then print the result on screen
SOLUTION
EXERCISE 2:
Design a program to calculate the sum of integers from 1 to 1000 and
then calculate the sum of odd numbers from 1 to 1000 and then
calculate the sum of even numbers from 2 to 1000 and print each sum
separately with printing the final sum which is equal to the sum of
integers, odd and even.
SOLUTION
sum=0
sum_even=0
sum_odd=0
for x in range(1,1001):
sum+=x
if x%2==0:
sum_even+=x
else:
sum_odd+=x
print(‘the summation of the integer numbers from 1 to 1000 is”,sum,”\nthe
summation of the even numbers from 1 to 1000 is”, sum_even,”\nthe summation of
the odd numbers from 1 to 1000 is”,sum_odd)
EXERCISE 3: WHAT ARE
THE OUTPUT?
for i in range(5):
if i == 3:
break
print(i)
Output?
6
EXERCISE 4:WHAT ARE
THE OUTPUT?
for i in range(5):
if i == 3:
continue
print(i)
Output?
Presentation title 7
EXERCISE 5