0% found this document useful (0 votes)
26 views2 pages

Lab 04 Selection Statements: All Scripts Should Be Stored in Your Firstlastname Folder and Have Clear Names

The document provides examples of code snippets for selection statements and conditional logic problems. It includes examples of taking input from a user to check if a number is odd or even, converting between weight units, grading a student on a scale, splitting an array into odd and even elements, calculating trip time from departure and arrival times, and calculating age from a date of birth.

Uploaded by

Bishoy Emile
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views2 pages

Lab 04 Selection Statements: All Scripts Should Be Stored in Your Firstlastname Folder and Have Clear Names

The document provides examples of code snippets for selection statements and conditional logic problems. It includes examples of taking input from a user to check if a number is odd or even, converting between weight units, grading a student on a scale, splitting an array into odd and even elements, calculating trip time from departure and arrival times, and calculating age from a date of birth.

Uploaded by

Bishoy Emile
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Cairo University Faculty of Engineering Credit Hour System GENN004

Lab 04 Selection Statements


All scripts should be stored in your FirstLastName folder and have clear names 1. Take a number from user and check if it is odd number or even number. Input: Enter a number: 5 Output: 5 is odd 2. Convert the weight from mg, Kg, Ton to Gram upon the user choice Input: Enter weight: 2 Enter unit (m for mg, k for kg, t for ton): k Output: 10 Kg= 10,000 Gram 3. Write program that takes the student grade out of 100 and prints Excellent if greater than or equal 90%, Very Good if greater than or equal 80% and smaller than 90%, Good if greater than or equal 70 and smaller than 80%, Fair if greater than or equal 60% and smaller than 70%,Fail if lower than 60%. Input: Enter course grade: 94 Output: 94/100 Excellent

4. Write a program that reads an array of length 8 and split it into two arrays; one has the odd elements and the other has the even elements Input: Enter an array of length 8: [1 7 8 9 4 Output: Odd elements = [1 7 9 9] Even elements = [8 4 6 4] 6 4 9]

Lab 04

1/2

Cairo University Faculty of Engineering Credit Hour System GENN004 5. Write a program that reads the departure time of a train and the arrival time and computes and displays the trip time. (Try also departure 12:30 and arrival 13:40) Input: Enter departure hour: 10 Enter departure min: 50 Enter arrival hour: 12 Enter arrival min: 20 Output: Trip time = 1 hr and 30 min 6. Write a program that reads your birth date and todays date and computes and displays your age. (Try also DOB 7/1994 and Today 9/2012) Input: Enter DOB year: 1990 Enter DOB month: 10 Enter date year: 2012 Enter date month: 9 Output: You are 21 years and 11 months old

Lab 04

2/2

You might also like