Uploaded by natchajong

Python and Pseudocode pdf

advertisement
Python and Pseudocode
Question 1:
Write an algorithm in python and pseudocode to input some numbers. It only
outputs any numbers that are greater than or equal to 100. The number 999 is
not output and stops the algorithm.
(Python)
(Pseudocode)
DECLARE num:INTEGER
OUTPUT “Please enter a number: ”
INPUT num
WHILE num<>999 DO
IF num>=100 THEN
OUTPUT num
END IF
OUTPUT “Please enter a number: ”
INPUT num
END WHILE
Question 2:
Similar than the previous one. But this time using a for loop where you will
input 5 numbers, and it will output only the ones equals or greater than 100.
(Python)
(Pseudocode)
DECLARE num1: INTEGER
FOR i 1 to 5
OUTPUT “Please enter the number: ”
INPUT num1
IF num1 >= 100 THEN
OUTPUT num1
END IF
Next i
Question 3:
Write in pseudocode and python to write an algorithm to output all numbers
between 100 and 200 inclusive.
There are 2 ways to write.
(Python 1)
(Python 2)
(Pseudocode)
num <- 100
WHILE num >= 100 and num <= 200 DO
OUTPUT num
num <- num + 1
ENDWHILE
Question 4:
Write an algorithm in python and pseudocode where the user enters the
radius of a circle and the computer will calculate the area. Consider a constant
here
(Python)
Download