You are on page 1of 6

Al Faisal University

College of Engineering
Software Engineering Department
SE 100L – Programming for Engineers Lab

Name: karam faroun Date:10/24/2023


Student ID:240419 Time and day:3:03 Tuesday

Lab 7 – More on Repetition Structures


Objective
 To reinforce the concept of loops through the implementation of further examples.
Exercise 1 (10 marks)
Write a program using for loop that finds the sum and average of all even integers between 1 and
10 (inclusive). Your program should also find how many numbers are greater, smaller and equal to
the calculated average.
Here is a sample run:

Paste the screenshot of your program and your output for Exercise 1 here:
Al Faisal University
College of Engineering
Software Engineering Department
SE 100L – Programming for Engineers Lab

Copy and paste the code of your program for Exercise 1 here:

print('The even numbers from 1 to 10 are:')


sum = 0
counteven = 0
for x in range(1,11):
if (x%2==0):
print(x)
sum+=x
counteven+=1

print('The sum of all the even numbers is:',sum)


average = sum/counteven

print('The average of all even numbers is:',average)


countequal = 0
countless = 0
Al Faisal University
College of Engineering
Software Engineering Department
SE 100L – Programming for Engineers Lab
countgreater = 0

for x in range(1,11,):
if (x%2==0):
if(x>average):
countgreater+=1
elif(x<average):
countless+=1
else:
countequal+=1

print('Number of even numbers greater than the average:',countgreater)


print('Number of even numbers lower than the avergae:',countless)
print('Number of even numbers Equal to the average:',countequal)

Exercise 2 (10 marks)


Write a program that uses nested for loops to print a multiplication table starting from 1 to 10.
Here is a sample run:

Paste the screenshot of your program and your output for Exercise 2 here:
Al Faisal University
College of Engineering
Software Engineering Department
SE 100L – Programming for Engineers Lab

Copy and paste the code of your program for Exercise 2 here:
print('\t Multiplication Table')
for x in range (1,11):
print(x,end=" ")
for d in range(1,11):
print('\t',x*d,end="")
print()

Exercise 3 (10 marks)


Write a program that calculates the age of a person born from 1920 to 2023. If input is not a
numeric or less than 1920, or greater than 2023, you need to ask for another valid input.
Here is a sample run:
Al Faisal University
College of Engineering
Software Engineering Department
SE 100L – Programming for Engineers Lab

Paste the screenshot of your program and your output for Exercise 3 here:

Copy and paste the code of your program for Exercise 3 here:
year = 2024
while (year < 1920 or year > 2023):
year = input('When were you born:')
if not year.isdigit():
print(year,"is not a number")
year = 2024
else:
year = int(year)
age = 2023 - year
Al Faisal University
College of Engineering
Software Engineering Department
SE 100L – Programming for Engineers Lab
print("you are",age,"years old")

You might also like