Presentation is loading. Please wait.

Presentation is loading. Please wait.

Continue with conditional

Similar presentations


Presentation on theme: "Continue with conditional"— Presentation transcript:

1 Continue with conditional

2 If statements-example 1
Problem : At Kiddy School , the teachers used the A, B,C for grading the students’ works. If the student get an A, then the teacher will print “Excellent” and if the student get B, the teacher will print “Good”. For students that get C, the teacher will print “Work Harder”. Given the problem above, design a solution using flowchart.

3 Solution Y n n Y

4 Input is string therefore use raw_input function
Python code >>> grade=raw_input('enter student grade') enter student gradeA >>> if grade =='A': ... print "Excellent" ... elif grade =='B': ... print "Good" ... else: ... print "Work Harder" ... Excellent Input is string therefore use raw_input function User input A String –characters is compared lexicographically order, hence must put capital letter result

5 Another solution >>> grade =raw_input('enter student grade ')
enter student grade a >>> if grade=='A' or grade =='a': ... print 'excellent' ... elif grade =='B' or grade =='b': ... print 'good' ... else: ... print 'work harder' ... excellent ‘a’ and ‘A’ have two different values. To handle input either in capital letter or small letter, the condition is joining with ‘or’ operator

6 Example 2: Problem: Your instructor asked you to design a program that can receive two input number (assumed that both number are not the same) and determine the larger of the two. Design a flowchart the problem above.

7 solution

8 Python code: >>> a=input('input the first integer')
>>> b= input('input the second integer') input the second integer3 >>> if a > b: print a ... else: print b ... 3 Input by user Input by user Make sure the proper indentation is used Result after comparison

9 Exercise 1 Problem: Your instructor asked you to design a program that can take 3 input and determine the largest of three input integers. Draw flowchart and write Python code for the problem above.

10 Solution

11 Python code: >>> a=input(' enter the first number :')
>>> b=input(' enter the second number :') enter the second number :3 >>> c=input ('enter the third number :') enter the third number :1 >>> if a > b: ... if a> c: ... print a ... else: ... print c ... elif b > c: ... print b ... else: ... print c ... 3

12 Exercise 2 Start Put the envelope in the mail box Go to the mail box
Using the text given, draw a flowchart for mailing a letter: Start Put the envelope in the mail box Go to the mail box Stop Seal the envelope Put the airmail stamp on Put letter in the envelope Address the envelope Is it airmail? Put the local stamp on

13 Exercise 3 Given the following text, construct a flowchart for changing a flat tire on a car. Lower the car Put the spare tire Is flat a front tire? start Jack up the front of car Remove the jack from the trunk stop Put Jack & flat in the trunk Remove the spare from the trunk Remove the flat tire Jack up rear of car

14 Exercise 4 Draw a flowchart for a Patient Intake Process in the clinic. Use all the texts presented below. Patient in the system? Patient fill up the new patient form Patient leave the clinic Patient arrives at Front Desk Nurse ask for patient’s name and search the database Patient go to exam room Ask patient to be seated in the waiting room HIVQUAL Group Learning Guide

15 Exercise 5 The table below shows the normal boiling points of several substances. Design a program that prompts a user for the observed boiling point of a substance in degree Celsius ( C0 ) and identifies the substances if the observed boiling point is within 5% of the expected boiling point. If the data input is more than 5% higher or lower than any of the boiling points in the table, the program should output the message Substance unknown

16 Continue.. In your design : Identify the input The desired output
Substance Normal boiling point (Celsius) Water 100 Mercury 357 Copper 1187 Silver 2193 Gold 2660 In your design : Identify the input The desired output Write the algorithm and pseudo code

17 Exercise 6 Keith’s Sheet Music needs a program to implement its music teacher’s discount policy. The program is to prompt the user to enter the purchase total to indicate whether the purchaser is a teacher. Music teachers receive a 10% discount on their sheet music purchases unless the purchase total is RM100 or higher. In that case, the discount is 12%. The discount calculation occurs before addition of the 5% sales tax. The sample outputs are as below: two output , 1 for teacher another one is not teacher.

18 Continue.. What you need to do? Analyze the problem - Identify input Identify output Identify formula 2. Write a pseudo code 3.Draw a flowchart 4. Write a Python code Total purchases RM Teacher’s discount RM Discounted total RM Sales tax RM 5.37 Total RM Total purchases RM Sales tax RM 1.25 Total RM 26.15


Download ppt "Continue with conditional"

Similar presentations


Ads by Google