0% found this document useful (0 votes)
22 views10 pages

CO - Lab - 4 (A)

This document discusses a computer organization lab assignment on algorithms and repetition structures in Python. It provides examples of problems using repetition, such as printing integers between 100-200 with an even digit sum. It also discusses looping forever with while True. The tasks section asks students to write programs that: 1) continually get and sum numbers unless they are multiples of 5 until a negative number is entered; 2) compute the value of n + (n + n) + (n + n + n) + ...; and 3) convert Roman numerals to decimal numbers. Hints and notes are provided to help students complete the tasks.

Uploaded by

Rameez Raja 10 F
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views10 pages

CO - Lab - 4 (A)

This document discusses a computer organization lab assignment on algorithms and repetition structures in Python. It provides examples of problems using repetition, such as printing integers between 100-200 with an even digit sum. It also discusses looping forever with while True. The tasks section asks students to write programs that: 1) continually get and sum numbers unless they are multiples of 5 until a negative number is entered; 2) compute the value of n + (n + n) + (n + n + n) + ...; and 3) convert Roman numerals to decimal numbers. Hints and notes are provided to help students complete the tasks.

Uploaded by

Rameez Raja 10 F
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Computer Organization

Lab #4
Dr Sajid Gul Khawaja
LE Kashaf Raheem
Algorithms and Repetition
Aim
Exploring python syntax and problem-
solving w.r.t repetition structures

2
Example:
› Write a Python program to display all
integers within the range 100-200 whose
sum of digits is an even number.
Example:

QUESTION SOLUTION
› Write a program that reads 10 count = 0
positive numbers from the
keyboard and determines and sum = 0
displays the sum and average of while (count < 10):
the numbers number = input("Input a new
number: ");
sum = sum + int(number)
count = count + 1
print ("Sum of 10 numbers is: ",
sum)

4
Looping “Forever”

PROBLEM SOLUTION
› Use a value that will always be while True:
true to loop until a “break”.
string = input()
if string==“exit”:
break
print (string)
print ("Done”)

5
Tasks
Make sure to comment your code.
Use appropriate variable name
Know the location where file is being saved
Create different files for different tasks

6
Task 1:
› Write a program that keeps getting and adding
the number (unless it is multiple of 5) until
negative number is entered. Display the final
sum as output.

Hint: Make use of nested if/else within while

7
Task 2:
› Write a Python program that accepts an integer (n)
and computes the value of 𝒏 + (𝒏 + 𝒏) + (𝒏 + 𝒏 +
𝒏) + … (𝒏 + 𝒏 + 𝒏 … + 𝒏)

8
Note: The characters are arranged
in descending order
Task 3:
› You are required to create a python program which can
convert numbers entered in ROMAN Numerals into decimal
numbers. E.g., user entered MLXVI number becomes 1066
(1000+50+10+5+1)

ROMAN Numeral Decimal Value


M 1000
D 500
C 100
L 50
X 10
V 5
I 1
9
Next week: Python Syntax
and Problem Solving!
Advice:
Explore Leetcode for problem solving!

27

You might also like