CSCE 101: Introduction to Computer Concepts



Lab 5: More on If..Elif..ElseAcademic HonestyThe work you turn in is to be your work, not copied from someone else, from the web, or generated by a program.Never allow anyone access to your files.Never give anyone your password.Never share your USB memory or email your files to anyone else.Never give anyone a printed copy of your file or an electronic copy.Never allow anyone to copy your work.PurposeIn this lab, we will implement more examples for if..else structure.Use IDLE icon on your desktop to start the IDE.Part 1: Extending the Grade CalculatorYou need to extend the grade calculator from Lab2. In lab2 we calculated the final score based on different points. Look at lab 2 if you are confused. In this lab, we will extend that to calculate the letter grade based on following table PointsGrade>= 90A87-89B+80-86B77-79C+70-76C67-69D+60-66D<60FYour program output should look as follows:Part 2: Checking DivisibilityIn this part you will generate a random number between 0-100.You can generate a random number using following two lines of code.import randomrandom_num = random.randint(0, 100)This will generate a random number between 0 and 100 including 0 excluding 100.This will give you a different number every time you run the program.Display that random number using print().Check if the random number is divisible by 2 and 3.There can be four cases:Number is divisible by 2 and 3 bothNumber is divisible by 2 but not 3Number is divisible by 3 but not 2Number is not divisible by both 2 and 3You can find the number is divisible by any other number by using %. % calculates the reaminder and if remainder is 0, then it is divisible.For example:If num % 2 == 0:print(“The number is divisible by 2”)You can do the same thing for 3.To make sure you can check if the number is not divisible by checking if remainder is not 0.For example:If num % 2 != 0:print(“The number is divisible by 2”)!= means not equal.Sample Program below:Another exampleAnother exampleSubmitting your filesIn both parts make sure your calculations and conditions are correct using a calculator.Copy your .py file and move it to your X:\101Labs directory for grading.Make sure your files are named Lab5P1XY.py, and Lab5P2XY where XY are your initialsPrint your code, and submit it to your lab instructor at the beginning of your next lab class. ................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download