Presentation 4 - Inputs and Sequence
Presentation 4 - Inputs and Sequence
Seating arrangement
Yellow notebooks
Lesson Objectives Quiz on 29th Sept
1) Full name
3) Address
4) Contact Number
5) Whether he/she would like to opt for extra reinforcement classes or not
6) Current class section – class sections are single letters like A,B,C etc
USING THE SCRIPT MODE OF PYTHON , ASK FOR THE ABOVE INPUTS AND DISPLAY ALL THE ANSWERS. UPLOAD ON
SHOWBIE UNDER CW 5 – INPUTS IN PYTHON
Quiz#2
Please submit the
python file for Q3
on Showbie under
Quiz # 2
Test on Thursday 6th
Lesson Objectives
age=age+10
age_10=age+10
final_age=age+10
age_after_10_years=age+100
Producing Outputs in Python
Q) The following data about a student has been input:
student_name=”Esha”
age=16
address=”House No 34/1, DHA Phase 6, Karachi”
contact_number=033456784
promoted_class_11=True
school_fees_paid=’Y’
overall_percentage_class_10=89.9
Check the print statements on the next slides and determine which ones
are correct and which ones are not and explain why.
student_name=”Esha”
age=16
address=”House No 34/1, DHA Phase 6, Karachi”
contact_number=033456784
promoted_class_11=True
school_fees_paid=’Y’
overall_percentage_class_10=89.9
A. PRINT(“The name is “, name)
A. 1_name
B. name_&_
C. _age_
D. _address_123
E. !_weight
F. Height_4
G. average_*
3 Programming Constructs/Concepts
1. Sequence
2. Selection
3. Iteration
3 important concepts of programming
When you write lines of code, there are three ways you can control the order these lines will be executed
by the computer:
1. Sequencing: This means that the computer will run your code in order, one line at a time from the
top to the bottom of your program. It will start at line 1, then execute line 2 then line 3 and so on
till it reaches the last line of your program.
2. Selection: Sometimes you only want some lines of code to be run only if a condition is met,
otherwise you want the computer to ignore these lines and jump over them. This is achieved using
IF statements. e.g. If a condition is met then lines 4, 5, 6 are executed otherwise the computer
jumps to line 7 without even looking at line 4,5 and 6.
3. Iteration: Sometimes you want the computer to execute the same lines of code several times. This
is done using a loop. There are three types of loops: For loops, while loops and repeat until loops.
That’s handy as it enables you not to have to copy the same lines of code many times.
SEQUENCE
What is sequence?
(CLICK on the link attached)
Sequencing in Algorithms
● sequencing
● selection
● iteration
These building blocks help to describe solutions in a form ready for programming.
Algorithms consist of instructions that are carried out (performed) one after another.
1. draw a 3 cm line
2. turn left 90 degrees
3. draw a 3 cm line
4. turn left 90 degrees
5. draw a 3 cm line
6. turn left 90 degrees
7. draw a 3 cm line
The steps in this algorithm are in the correct sequence. This algorithm would result
in a perfect square as shown in the picture
If there was a mistake when designing the algorithm, and the steps in this sequence were
placed like this: Because step 6 is in the
1. draw a 3 cm line wrong sequence (it should
switch with step 7), this
2. turn left 90 degrees
algorithm failed. However,
3. draw a 3 cm line
fixing the algorithm - and
4. turn left 90 degrees the square - is easy, because
5. draw a 3 cm line there are only seven steps
6. draw a 3 cm line to look through for the
7. turn left 90 degrees error.
This algorithm would create this shape, rather than a perfect square.
Complex algorithms may have hundreds, if not
thousands, of steps.
Q2) Write a program to enter length and breadth of a rectangle and find its perimeter.
(P=2(L) + 2(B))
Q3) Write a program to enter length and breadth of a rectangle and find its area.
Q4) Write a program to enter radius of a circle and find its diameter, circumference and
area.
Q5) Write a program to enter length in centimeter and convert it into meter and kilometer.
Q6) Write a program to enter temperature in Celsius and convert it into Fahrenheit. To
convert temperatures in degrees Celsius to Fahrenheit, multiply by 1.8 (or 9/5) and add 32.
Q7) Write a program to enter temperature in Fahrenheit and convert to Celsius
Q8) Write a program to convert days into years, weeks and months.
Q10) Write a program to enter any number and calculate its square root.
Q11) Write a program to enter two angles of a triangle and find the third angle.
Q12) Write a program to enter base and height of a triangle and find its area.
Q14) Write a program to enter marks of five subjects and calculate total, average and
percentages of each subject as well as the overall percentage.
Q15) Write a program that solves a quadratic equation.
Q17) Write a program that asks the user for their name and greets them with their name.
Q18) Calculate the compound interest on a given principal amount, time period and rate
of interest. The formula is
Q19) Calculate the simple interest on a given principal amount, time period and rate
of interest. The formula is SI=PRT/100
Q20) Use the Pythagorean theorem to calculate the hypotenuse of a right angled
triangle (c**2=a**2 + b**2)
Q23) Find the volume and surface area of a cone. (SA=Pi*r(r+s)) (V=(1/3)*Pi*r2*h)
Q24) Write a program that reads a number in inches, converts it to meters. Note: One inch is
0.0254 meters
Q25) Input a 2 digit number and print the sum of the 2 digits in the number for example if 78 is
entered, 15 is output (Hint: Use the quotient and remainder theorem)
Q26) Write a program to convert minutes into a number of years and days
Q27) Write a program which takes the distance and time and outputs the speed. (S=D/T)
Q28) Write the program which takes 2 numbers as inputs, a and b, and prints the
remainder when a is divided by b and vice versa
Q29) Write a program in which 2 values are input into 2 different variables and then the
values are swapped and output.
Q30) Find the volume and surface area of a cuboid. (V=L*B*H) (SA=LW+WH+HL)
Q31) Find the volume and surface area of a cylinder. (V=Pi*r2*h) (SA=Pi*2*r(r+h))
Q33) Find the area and perimeter of a rhombus (Area=pq/2 where p and q are diagonals, P=4a
where a is the side) and a trapezoid (A=(a+b/2)*h where a and b are bases, h is the height,
P=a+b+c+d which are all sides)
Q35) Write a program which takes the name, age, contact number, address and DOB of a
student and stores all the details. Print the details back for the student to check and verify.
Q36) Write a program which calculates the cube root of an integer
Q37) Write a program which outputs the quotient only after a number is divided by another
number
Q38) Write a program which outputs the remainder only after a number is divided by
another number
Q39) Write a program which outputs the result of the complete division when a number is
divided by another number
Sequence Q1
Maria decides to buy some cupcakes and brownies.
CONST_num_students=110