0% found this document useful (0 votes)
51 views

Programming Third Batch (Selection) 21-29

This document provides instructions for 29 programming tasks involving selection statements and built-in functions. The tasks involve inputting values, checking conditions, and outputting results based on the inputs. Topics covered include Boolean operators, character classification, number ranges, palindrome checking, and random number generation. Students are asked to solve the tasks in a programming language and pseudocode.

Uploaded by

zoya bilal
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)
51 views

Programming Third Batch (Selection) 21-29

This document provides instructions for 29 programming tasks involving selection statements and built-in functions. The tasks involve inputting values, checking conditions, and outputting results based on the inputs. Topics covered include Boolean operators, character classification, number ranges, palindrome checking, and random number generation. Students are asked to solve the tasks in a programming language and pseudocode.

Uploaded by

zoya bilal
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/ 4

Programming Assignment

Third Batch
Selection with Boolean Operatores and Built-In Functions

Note: These tasks are to be solved in a programming language and in Pseudocode. Where instructed
give the output as given using concatenation operator of selected langauage and “&” for pseudocode.

TASK # 21: Input the marks obtained by a student in 2 test. Ouptut the grade

you dont need to do any validation

Distinction if both are above 80.

Merit if total of both is above 160

Credit if Total of both tests is above 120

Pass if above 100

Fail otherwise which means total is below OR EQUAL 100

82,83 => Distinction

100,79 => Merit

70,75 => Credit

58,59 => Pass

90,2 => Fail

Task # 22: Input the Carbon Contents, tensile strength and hardness of a steel.

Output the grade of steel.

Carbon Contents < 1.6

Tensile Strength > 1600

Hardness > 8

Grade is 10 if all three are true


Grade is 9 if (i) and (ii) are True

Grade is 8 if (i) and (iii) are True

Grade is 7 if (ii) and (iii) are True

Grade is 6 if either one is True

Grade is 5 otherwise { all are False }

For testing, check it 8 times and each time a different grade should be printed.

It is called exhaustive testing when you make sure each possible route/path is

checked in the program.

Task # 23: Input a character and print its category.

Capital Letter are between 65 and 90 Ascii Code

Lower Case Letter are between 97 and 122 Ascii Code

Digit are between 48 to 57 Ascii Codes

All other Ascii Codes are of Special Characters

Use the built-in Function ord() to get the ascii code of a character

e.g. ascii_code = ord(ch) where ch has "B" then it returns 66.

ch = input("Enter a character from keyboard")

x = ord(ch)

Task # 24: Input a number and print if it is special or ordinary

Special numbers are the ones that are in the following ranges inclusive

20 - 30

50 - 60

80 - 90

All numbers input must be in the range 0 - to 100 and if not an error

must be displayed.
Task # 25: Input a character and print if it is a vowel or consonant. Make sure

the input is a character. Upper and lower case both are allowed, but nothing

else other than a character should be allowed. Give an error in case input

is not a character.

Task # 26: Generate a random number between 1 and 10 inclusive using the library random.

Ask the user to guess it, if the guess is exactly the number print "Bingo"

if it is one above or below print "Too Close", if it is 2 below or 2 above then

print "Close" otherwise print "You Loose". If the guess is wrong then print the

number computer generated(correct one). Test your program multiple times to

check that each case is working fine.

Task # 27: Input a 4 digit number and print if it is a palindrome or not. Palindrome

are the same when reversed e.g. 3443

Task # 28: Input the marks obtained by a student in 2 test. Ouptut the grade

you dont need to do any validation

Distinction if both are above 80.

Drop is either is below 40

Merit if total of both is above 160

Credit if Total of both tests is above 120

Pass if above 100

Fail otherwise which means total is below OR EQUAL 100


82,83 => Distinction

98,39 => Drop

100,79 => Merit

70,75 => Credit

60,62 => Pass

42,43 => Fail

Task # 29 : Your program should generate a random number between 1 to 20. Now let the user

guess this number but only allow 3 tries. Your program must not use a loop( O Level Students).

Each time if the user guesses a number greater than the original one print

"Too High" or if is smaller print "Too Low!" otherwise if it is equal print "Bingo!"

If the user is done with 3 wrong attempts then print "You loose".

You might also like