CENGAGE MINDTAP Lab Activity 1.2: Running Simple Python Scripts Running Simple main.py Python Scripts 1 import 2 print( 3 # get argume 4 print( 5 print( 6 print( 7 8 Your output should be similar to Figure 1.6: > Terminal workspace $ python3 main.py MR Matt + Initials: MR Nickname: Ratt workspace $ Figure 1.6 Grading Complete each task listed below. Each task contains automated checks which are
Added by Cameron A.
Close
Step 1
First, we need to import the sys module, which allows us to access command line arguments. Show more…
Show all steps
Your feedback will help us improve your experience
Sanchit Jain and 98 other AP CS educators are ready to help you.
Ask a new question
Labs
Want to see this concept in action?
Explore this concept interactively to see how it behaves as you change inputs.
Key Concepts
Recommended Videos
Write a Python program that will calculate and display the final grade of a student. The final grade is calculated as the weighted average of quizzes (15%), homework (10%), labs (15%), midterm exam (25%), and a final exam (35%).
Madhur L.
In this assignment, you will explore the sys, os, and subprocess modules in Python. You will execute a variety of basic functions in these modules that interface with the operating system. While the functions in these modules can be used in a program, for this assignment, you will take the opportunity to execute these commands directly in the Python shell. Assignment Requirements Using the Python shell, execute the following functions. You will take screenshots at key points to show the successful execution. These will be placed in a single Word document. Recommended screenshot points are listed within the assigned functions, but you may add screenshots if necessary to show the successful completion of the assignment. (Hint: Under Windows, some of these functions will accept a single backslash in a file path, while others require double backslash between folders.) Assignment Instructions In the Python shell, first import the sys, os, and subprocess modules. Execute os.getlogin() Execute os.get_exec_path() Take a screenshot. Execute sys.path Execute sys.byteorder Take a screenshot. Execute os.listdir on your C: drive Use os.mkdir to make a new folder on your C: drive named tempPython Take a screenshot. Use subprocess.Popen to execute the Windows dir command and have its output placed in a text file named pythonOut.txt. Hint: The argument for Popen in this case will be ('C:\\windows\\system32\\cmd.exe "/c dir C:\\ >> C:\\pythonOut.txt"') Open pythonOut.txt in Notepad and position that window next to the Python shell window where both can be seen. Take a screenshot. Use subprocess.Popen to open Windows calc.exe utility Take a screenshot.
Supreeta N.
Identifying Error Scenarios Scenario You are testing code to determine types of errors. During programming, errors often occur. But how can we anticipate when something will cause an error? You can anticipate errors by thoroughly understanding error scenarios and causes. Aim In this activity, we will create error scenarios. Let's write some code that will cause a KeyError and an AttributeError. Steps for Completion 1. Go to your main.py file. 2. Define a function createError to first generate a KeyError and then an AttributeError. In order to generate both errors, you will need to generate only one error at a time. Grading Complete each task listed below.
Akash M.
Recommended Textbooks
Computer Science and Information Technology
Introduction to Programming Using Python
Computer Science - An Overview
18,000,000+
Students on Numerade
Trusted by students at 8,000+ universities
Watch the video solution with this free unlock.
EMAIL
PASSWORD