Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Program Organization Create a project5 folder somewhere on a flash drive, onedrive or on your computer. Name your main python file lettergrade-yourlastnome.py, and use your

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

image text in transcribed

Program Organization Create a project5 folder somewhere on a flash drive, onedrive or on your computer. Name your main python file lettergrade-yourlastnome.py, and use your real last name. The program must accomplish all of the following prompt the user for the numeric grade utilize conditionals to determine the letter grade pop-up a graphical messagebox containing the letter grade. The top part of the messagbox must conain "Letter Grade Result", this is also known as the messagebox title. Getting the Numeric Grade and Displaying a Messagebox It is usually good to start small. The first step in getting a project to work is to try to capture the numeric grade and then print it out. This will require the use of input. Run your program in the Thonny editor by clicking the arrowhead to run programs on the toolbar or by hitting the F5 key. If an error / traceback message appears, fix the error before adding more code to the program! After you are able to capture the number and print it out the next step is to try to make the messagebox show. This will require several things: 1. First you must have done Adding PyQt5 to Thonny. 2. The gt messagebox.py, file containing the code to show a GUI pop-up message 3. The lines to show the messagebox must all be together. This includes this line (#2) and #3 below: from qt_messagebox import 4. Next try to display a messagebox. Try displaying the message "hello". This can be changed to the correct message later, right now we just want to make sure this is working! #show the messagebox messageBox("Letter Grade Result", "Hello") 5. Run your program in the Thonny editor by clicking the arrowhead to run programs on the toolbar or by hitting the F5 key. If an error / traceback message appears, fix the error before adding more code to the program! 6. It may be necessary to minimize the Thonny window in order to see the messagebox! On Windows computers the box seems to show behind the Thonny window, so if you don't see it, look behind the Thonny window and click the Ok button. After you get this working, continue to modify your lettergrade-yourlastname.py file (see the Stepwise Refinement section). Compliance Instructions To make sure that you have implemented your program correctly, run your program inputing the following values: (note: the number 90 is keyed in by the person running the program) Enter the numeric grade 90 The messagebox should show "A" inside the box (note: the number 80 is keyed in by the person running the program) Enter the numeric grade 80 The message box should show "B" inside the box (note: the number 70 is keyed in by the person running the program) Enter the numeric grade 70 The messagebox should show "C" inside the box (note: the number 60 is keyed in by the person running the program) Enter the numeric grade 60 The message box should show "D" inside the box (note: the number 59 is keyed in by the person running the program) Enter the numeric grade 59 The message box should show "F" inside the box Next you should try other values just to be sure. For instance a 69 is still the letter grade D You can confirm the correctness of your program by comparing your results (not code!) with others via the projects discussion board forum in Blackboard. You should try values other than the test data to make sure you have no errors. If your submission fails this simple test with a runtime /traceback error, then you will receive a zero for this assignment. Here is a sample of the messagebox showing a letter grade: The Thonny - Z:/lettergrade_yourlastname.py @ 23:18 File Edit View Run Tools Help lettergrade_yourlastname.py # Name: Firstname Lastname # Date: 5/17/19 # Assignment: Project 5 - Letter Grade # Description: Evaluate a numeric grade entered by the u the correct letter grade inside #-- Letter Grade Result X Grade: A #get grade from user grade_in - input("Enter the numeric grade: ") grade = int( grade_in ) D OK Cancel Shell >>> %Run lettergrade_yourlastname.py Enter the numeric grade: 90 Grade: A Note that your answers do not have to be correct for your program to be graded, only that it not crash. Of course, correct answers will yield a much higher grade. Challenges Try these refinements to your program, if you are inspired to earn 2 points extra credit! All items must be implemented Ensure that numeric grades over 100 still work. Of course anything over 100 is still just a letter grade of A Allow for decimal grades to be entered. For example a grade of 69.9 is still just a letter grade of D Add some descriptive text inside the messagebox to describe what is being shown. For example, Grade: A Stepwise Refinement Follow these steps for a stress-free time developing the project: 1. Implement the program as suggested in the Getting Started section. The program must include a set of comments (they begin with the pound sign #). Every program that is created for this class must include comments similar to the following: # Name: Sara Coe # Date: 5/1/17 # Assignment: Project 5 - Letter Grade # Description: Evaluate a numeric grade entered by the user and display the correct letter grade inside a messagebox. Copy and paste the lines that start with the #sign above into your program. Be sure to change the Name: to your first and last name, along with the date 2. Implement the program as suggested in the Getting the Numeric Grade and Displaying a Messagebox section. 3. Modify lettergrade-yourlostname.py so that it evaluates the numeric input using an if-elif-else decision structure to assign a letter grade to some variable. See the Reedy.py programming example inside Module 3 - Multiple Conditions Programming Lecture 4. Modify the call to messageBox() to show the variable with the letter grade inside the messagebox 5. Do the challenges to earn extra credit points! -# Name: #------ # File Name: # Purpose: # Requires PyQt5 # Usage Notes: qt_messagebox.py Display a GUI pop-up informational messagebox with Ok and Cancel buttons. function messageBox returns "Ok" if okay button pressed, "Cancel" if cancel button is pressed. PyQt5 must be installed in Thonny using tools, Manage Packages, search for PyQt5 and install it! 1) from qt_messagebox import * 2) button_clicked = messageBox("Title", "Text inside box") 3) print( button_clicked) # see the button clicked # Author: Ken Clifton # Created: 7/19/2019 # Last Revision: 10/11/2019 Added setWindowFlags (Qt.WindowStaysOnTopHint) to make always on top on MS Windows # Copyright: (c) Ken Clifton 2019 #---------------- import sys from PyQt5.QtWidgets import QApplication, Qwidget, QMessageBox, QDesktopWidget from PyQt5.QtCore import Qt class msgBox(QWidget): def _init__(self, mTitle, mText): super(). init o self.title = 'PyQt5 Messagebox' self.setWindowFlags (Qt.WindowStays On TopHint) self._buttonclicked = "" self.initUI (mTitle, mText) def initUI(self, mtitle, mText): self.setWindowTitle(self.title) qtRectangle = self.frameGeometry() centerPoint - DesktopWidget().availableGeometry().center() qtRectangle.moveCenter(centerPoint) self.move(qtRectangle.topleft() QApplication process Events buttonReply = QMessageBox. information(self, mTitle, mText, QMessageBox.OkQMessageBox.Cancel, QMessageBox.ok) QApplication.process Events() if buttonReply == QMessageBox.ok: self. __buttonclicked = "OK" QApplication. instance().quit() else: self.__buttonclicked = "Cancel" QApplication.instance().quit() #self.show() def buttonclicked(self): return self._buttonclicked def messageBox( mTitle, mText): app = QApplication(sys.argv) aMessageBox = msgBox(mTitle, mText) return aMessageBox.buttonclicked) # --- # must install PyQt5 from thonny, tools, manage packages # example usage # from qt_messagebox import * # button_clicked = messageBox("Title", "Text inside box") # get the return value: print( button_clicked) * - - - - - - - - - - - - - - - - - - - - - - - - - -- - - -- - - -- - - -- - - simple_popup_message (1).py X 1 -------- 2 # Name: Ken Clifton # Date: 07/19/2019 mtioco # Description: Demonstrate the use of qt_messagebox.py to show a Pop-Up GUI Messagebox # PyQt5 must be installed in Thonny using Tools, Manage Packages for this to work! #-------- 9 # the following three lines should be kept together! Do not separate them! # the message_text can be set to whatever needs to be inside the messagebox. 11 # and of course the title is what shows in the top border of the box. 12 from qt_messagebox import * 13 message_text = "This is the text shown inside the Message Box!" 14. button_clicked = messageBox("Messagebox Title Text", message_text) #>> %Run lettergrade_yourlastname.py Enter the numeric grade: 90 Grade: A Note that your answers do not have to be correct for your program to be graded, only that it not crash. Of course, correct answers will yield a much higher grade. Challenges Try these refinements to your program, if you are inspired to earn 2 points extra credit! All items must be implemented Ensure that numeric grades over 100 still work. Of course anything over 100 is still just a letter grade of A Allow for decimal grades to be entered. For example a grade of 69.9 is still just a letter grade of D Add some descriptive text inside the messagebox to describe what is being shown. For example, Grade: A Stepwise Refinement Follow these steps for a stress-free time developing the project: 1. Implement the program as suggested in the Getting Started section. The program must include a set of comments (they begin with the pound sign #). Every program that is created for this class must include comments similar to the following: # Name: Sara Coe # Date: 5/1/17 # Assignment: Project 5 - Letter Grade # Description: Evaluate a numeric grade entered by the user and display the correct letter grade inside a messagebox. Copy and paste the lines that start with the #sign above into your program. Be sure to change the Name: to your first and last name, along with the date 2. Implement the program as suggested in the Getting the Numeric Grade and Displaying a Messagebox section. 3. Modify lettergrade-yourlostname.py so that it evaluates the numeric input using an if-elif-else decision structure to assign a letter grade to some variable. See the Reedy.py programming example inside Module 3 - Multiple Conditions Programming Lecture 4. Modify the call to messageBox() to show the variable with the letter grade inside the messagebox 5. Do the challenges to earn extra credit points! -# Name: #------ # File Name: # Purpose: # Requires PyQt5 # Usage Notes: qt_messagebox.py Display a GUI pop-up informational messagebox with Ok and Cancel buttons. function messageBox returns "Ok" if okay button pressed, "Cancel" if cancel button is pressed. PyQt5 must be installed in Thonny using tools, Manage Packages, search for PyQt5 and install it! 1) from qt_messagebox import * 2) button_clicked = messageBox("Title", "Text inside box") 3) print( button_clicked) # see the button clicked # Author: Ken Clifton # Created: 7/19/2019 # Last Revision: 10/11/2019 Added setWindowFlags (Qt.WindowStaysOnTopHint) to make always on top on MS Windows # Copyright: (c) Ken Clifton 2019 #---------------- import sys from PyQt5.QtWidgets import QApplication, Qwidget, QMessageBox, QDesktopWidget from PyQt5.QtCore import Qt class msgBox(QWidget): def _init__(self, mTitle, mText): super(). init o self.title = 'PyQt5 Messagebox' self.setWindowFlags (Qt.WindowStays On TopHint) self._buttonclicked = "" self.initUI (mTitle, mText) def initUI(self, mtitle, mText): self.setWindowTitle(self.title) qtRectangle = self.frameGeometry() centerPoint - DesktopWidget().availableGeometry().center() qtRectangle.moveCenter(centerPoint) self.move(qtRectangle.topleft() QApplication process Events buttonReply = QMessageBox. information(self, mTitle, mText, QMessageBox.OkQMessageBox.Cancel, QMessageBox.ok) QApplication.process Events() if buttonReply == QMessageBox.ok: self. __buttonclicked = "OK" QApplication. instance().quit() else: self.__buttonclicked = "Cancel" QApplication.instance().quit() #self.show() def buttonclicked(self): return self._buttonclicked def messageBox( mTitle, mText): app = QApplication(sys.argv) aMessageBox = msgBox(mTitle, mText) return aMessageBox.buttonclicked) # --- # must install PyQt5 from thonny, tools, manage packages # example usage # from qt_messagebox import * # button_clicked = messageBox("Title", "Text inside box") # get the return value: print( button_clicked) * - - - - - - - - - - - - - - - - - - - - - - - - - -- - - -- - - -- - - -- - - simple_popup_message (1).py X 1 -------- 2 # Name: Ken Clifton # Date: 07/19/2019 mtioco # Description: Demonstrate the use of qt_messagebox.py to show a Pop-Up GUI Messagebox # PyQt5 must be installed in Thonny using Tools, Manage Packages for this to work! #-------- 9 # the following three lines should be kept together! Do not separate them! # the message_text can be set to whatever needs to be inside the messagebox. 11 # and of course the title is what shows in the top border of the box. 12 from qt_messagebox import * 13 message_text = "This is the text shown inside the Message Box!" 14. button_clicked = messageBox("Messagebox Title Text", message_text) #

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

=+ Of the HR issues mentioned in the case,

Answered: 1 week ago