Lab Topic 4 individual F23
.docx
keyboard_arrow_up
School
Texas A&M University *
*We aren’t endorsed by this school
Course
102
Subject
Computer Science
Date
Jan 9, 2024
Type
docx
Pages
3
Uploaded by ProfLightning103643
Lab: Topic 4 (individual)
ENGR 102
Lab: Topic 4 (individual)
Deliverables
Please complete the four programs described below. Each program is an individual assignment, but you may
consult your teammates and others as you work. Please submit the following files to zyBooks.
largest_number.py
pretty_equation.py
how_many_gadgets.py
Activity #1:
Largest number - individual
Using conditional statements (i.e. statements like if-elif-else
) write a program named largest_number.py that takes as input from the user three (3) numbers from the keyboard and prints the value of the largest number. Your code should output in the format shown below.
Example output (using inputs 1
, 2
, 3
):
Enter number 1: 1
Enter number 2: 2
Enter number 3: 3
The largest number is 3.0
Activity #2
:
Pretty equation – individual
A quadratic equation is an equation of the form A x
2
+
Bx
+
C
=
0
where A
, B
, and C
are the coefficients of the equation. Write a program named pretty_equation.py that takes as input the coefficients A
, B
, and C
and outputs the quadratic equation in a nice format. Your program should not print the coefficient “1” or a term with a coefficient “0” and should replace plus signs (+) with minus signs (-) for negative coefficients. Include one space between the sign and the term. You may want to review the string formatting document posted with Lecture 3. Use the output format shown below. You may
assume the user only enters integers.
Example output (using inputs -1
, -2
, 3
):
Please enter the coefficient A: -1
Please enter the coefficient B: -2
Please enter the coefficient C: 3
The quadratic equation is - x^2 - 2x + 3 = 0
Activity #3:
How many gadgets - individual
Assume a machine during its initial testing phase produces 10 gadgets a day. After 10 days of testing (starting on day 11), it begins to ramp up, producing 1 more gadget per day (11 gadgets on day 11, 12 on day 12, etc). On day 50 it reaches full speed, where it continues to run until on day 101 it stops producing gadgets. Write a program named how_many_gadgets.py that reads in a day (as a number) from the keyboard and reports the total number of gadgets produced from the initial testing phase up to and including the day entered. For example, entering 3 would report 30 gadgets.
Your code should also . . .
Check for inappropriate day numbers and message the user accordingly
Echo the input in the output when you report the number of gadgets
Based upon Dr. Keyser’s Original
1
Revised Fall 2023 SNR
Lab: Topic 4 (individual)
Use the output format shown below
Note
: Do NOT
use a loop. Part of the challenge in this program is for YOU to work out the model for how to compute gadgets produced in total, given the above information. Hint:
Solve this problem by hand on paper first, then translate your solution to Python. A graph or diagram is extremely helpful
. This approach is much easier than debugging some lousy Python code written before you understand the problem.
Example output (using input 3
):
Please enter a positive value for day: 3
The sum total number of gadgets produced on day 3 is 30
Example output (using input -1
):
Please enter a positive value for day: -1
You entered an invalid number!
Activity #4:
Calculate roots - individual
The roots of a quadratic equation are the values of x
at which the equation evaluates to 0
. The well-
known quadratic formula is often used to find these roots. Write a program named calculate_roots.py that takes as input the coefficients A
, B
, and C
and outputs the roots of that equation. Be aware of the following:
Use the output format shown below
If the roots have an imaginary component (complex), use i
when representing the imaginary term in the output. For example, you may output “
3.0
+
7.0
i
” as a root.
Be sure to handle the cases in which any or all coefficients are equal to zero
o
If A != 0
, there could be 2 real distinct roots, 2 real identical roots (one root of multiplicity 2), or 2 complex roots
If there are two roots, output the larger root first
o
If A = 0
, we are left with Bx
+
C
=
0
, a linear equation with one root
o
If A = B = 0
, we are left with C = 0
, so if the user entered a non-zero value of C
, write a message to the screen indicating this error
Example output (using inputs 1
, 2
, 1
):
Please enter the coefficient A: 1
Please enter the coefficient B: 2
Please enter the coefficient C: 1
The root is x = -1.0
Example output (using inputs 1
, 2
, -3
):
Please enter the coefficient A: 1
Please enter the coefficient B: 2
Please enter the coefficient C: -3
The roots are x = 1.0 and x = -3.0
Example output (using inputs 0
, 0
, 1
):
Please enter the coefficient A: 0
Please enter the coefficient B: 0
Based upon Dr. Keyser’s Original
2
Revised Fall 2023 SNR
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
Related Questions
✓ Exercises
Exercise: Write a method _ and _ that computes the region representing the intersection of two regions.
Exercise: Write a method
_contains__, which checks whether a n-dimensional point belongs to the region. Remember, a point belongs to the
region if it belongs to one of the rectangles in the region.
✓ Membership of a point in a region
#@title Membership of a point in a region
def region_contains (self, p):
### YOUR SOLUTION HERE
Region._contains = region_contains
[ ] # Tests 10 points.
assert (2, 1) in Region (Rectangle((0, 2), (0, 3)), Rectangle((4, 6), (5,8)))
assert (2, 1) not in Region (Rectangle((0, 1), (0, 3)), Rectangle((4, 6), (5, 8)))
Exercise: Write a method _le_ for regions such that R <= S if the region R is contained in the region S. You can test this by checking that
the difference between R and S is empty.
arrow_forward
PYTHON ONLY PLZZZ
Create a class object with the following attributes and actions:
Class Name
Class number
Classroom
Semester
Level
Subject
Actions:
Store a class list
Print the class list as follows:
Class name Class Number Semester
Level
Subject
Test your object:
Ask the user for all the information and to enter at least 3 classes
test using all the actions of the object
print using the to string action
Describe the numbers and text you print. Do not just print numbers or strings to the screen explain what each number represents.
arrow_forward
The Problems - contains only problems from the last 2 contests
Separate Un-Attempted, Attempted and All cards Problem Difficulty Rating - The
Featured drop-down menu has different difficulty ranges so you can try problems that
best suit your experience.
Popular topics and brands Like most users, Chef didn't know that he could add
problems to his personal to-do list by clicking the magic "+" symbol in the upper
right corner of each problem page. But once he found out about it, he went crazy and
added a lot of problems to his to-do list without looking at their difficulty rating.
Rajesh is a beginner and ideally should only try to solve problems strictly below
10001000. Given the difficulty rating list of problems in Chef's to-do list, please help
him determine how many of these problems Chef should remove from his to-do list
so he is left with only problems with a difficulty rating of less than 10001000.
Note: Please answer the question in Python only:
Input
1
4
999 1000 1001 1002…
arrow_forward
S1
arrow_forward
C++HurdleWords The HurdleWords class is mostly provided to you. HurdleWords is constructed from two files in the data/ folder: ● valid_guesses.txt (all 5 letter guesses considered to be valid words to guess), and ● valid_hurdles.txt (all words that may be selected to be the secret Hurdle.) ● Note: you may edit both text files if you’d like to add custom words to your game. HurdleWords stores all potential valid Hurdles from valid_hurdles.txt into a vector of strings (valid_hurdles_), and all valid guesses from valid_guesses.txt into an unordered set of strings (valid_guesses_). A set is simply a data structure that contains no duplicates and allows for a speedy lookup to check if a given element exists within the set. Because there are over 10,000 valid guesses, we store them in an unordered set to leverage their speediness, as you will need to check if a user-submitted guess is considered valid (i.e. their guess is considered a valid guess in the dictionary). You are responsible for…
arrow_forward
Design the worst calculator ever: an application that accepts two numbers from the user and, when a button is pushed, performs a single operation and displays the results.
You may choose: Multiplication, Division, Subtraction, square root, or raising the first number to the exponent of the second number. Don't use addition as we already did that in class.
The result must be displayed to the user only when an appropriately labeled button is pushed.
arrow_forward
Pendant Publishing edits multi-volume manuscripts for many authors. For each volume, they want a label that contains the author’s name, the title of the work, and a volume number in the form Volume 9 of 9. For example, a set of three volumes requires three labels: Volume 1 of 3, Volume 2 of 3, and Volume 3 of 3. Design an application that reads records that contain an author’s name, the title of the work, and the number of volumes. The application must read the records until eof is encountered and produce enough labels for each work. The flowchart must include a call symbol, at the beginning, to redirect the input to the external data file.
create a solution algorithm using pseudocode
create a flowchart using RAPTOR
arrow_forward
Pendant Publishing edits multi-volume manuscripts for many authors. For each volume, they want a label that contains the author’s name, the title of the work, and a volume number in the form Volume 9 of 9. For example, a set of three volumes requires three labels: Volume 1 of 3, Volume 2 of 3, and Volume 3 of 3. Design an application that reads records that contain an author’s name, the title of the work, and the number of volumes. The application must read the records until eof is encountered and produce enough labels for each work. Design a flowchart and psuedocode Pendant Publishing.
arrow_forward
Create a simple program for a quiz
Software Requirements:
Latest version of NetBeans IDE
Java Development Kit (JDK) 8
Procedure:
Create a folder named LastName_FirstName (ex. Dahan yoon) in your local
Create a new project named LabExer5B. Set the project location to your own
The program shall:
contain an array of 10 multiple choice questions with three (3) choices each and
require the user to choose among A, B, or C;
Note: Cases are ignored. Lowercase letters are acceptable (a, b, c).
Create a try-catch structure to handle three (3) exceptions. These are when the user inputs the following:
an invalid letter (not A, B, or C)
a number or any special character
blank (no answer)
Prompt the user that he can answer again if any of the three (3) exceptions is
Display the score.
arrow_forward
Q1. Write java program for the class diagram given below using the object oriented design.
arrow_forward
Python
arrow_forward
Need help only with deductions part in Java
arrow_forward
#The game Mancala is one of the oldest games in recorded
#history. You can read more about it here:
#https://www.thesprucecrafts.com/how-to-play-mancala-409424
#
#For this problem, though, you don't need to know how to
#play the game. All you need to know is the board layout
#and the conditions for winning.
#
#A Mancala board is made of two rows of 6 cups, with two
#bigger cups at the ends. Each cup holds some number of
#stones or chips. For our purposes, though, we'll include
#the bigger cups at the end of the corresponding rows.
#
#So, for us, a Mancala board is represented as a
#2-dimensional list of integers. Each item in the lists
#represents a cup, and the number represents how many
#stones are currently in that cup. For example, this
#could be one board:
#
# [[5, 3, 0, 2, 6, 8, 1],
# [1, 6, 8, 0, 4, 1, 4]]
#
#With this board representation, the game is over when
#every cup is empty except the top left and the bottom
#right. When the game is over, whoever has more stones
#in…
arrow_forward
Force Completion
This test can be saved and resumed at any polnt until time has expired. The timer will continue to run if you
leave the test.
Remaining Time: 49 minutes, 11 seconds.
* Question Completion Status:
A Moving to another question will save this response.
« >
Question 4
8 points
Save Answer
(10101)2 xor (10111)2 = (abcde)2 based on the equation calculate
((not b or d) and e).
A Moving to another question will save this response.
« »
arrow_forward
Programming Exercise 3-5
Tasks
Create the
BookstoreCredit class.
The computeDiscount
method calculates a
discount based on
student's GPA.
The BookstoreCredit
program displays the
discount for the student's
information.
JO
>
>
arrow_forward
Instructions:
IMPORTANT: This is a continuation of the previous part of the project and assumes that you are starting with code that fulfills all requirements from that part of the project.
Modify the your code from the previous part of the project to make it modular.
In addition to the main method, your code must include the following static methods:
Method 1 - displayTitle
A method that creates a String object in memory to hold the text “Computer Hardware Graphics Quality Recommendation Tool” and displays it
Method 2 – getResolutionString
A method that accepts an integer value (1, 2, 3, or 4) that denotes the monitor resolution. The method should return the appropriate String representation of the monitor resolution. For example, if the method is passed an integer value of 1, it should return a String with a value of “1280 x 720”. (See Step 4 of Project 1)
Method 3 – getMultiplierValue
A method that accepts an integer value (1, 2, 3, or 4) that denotes the monitor resolution and…
arrow_forward
Instructor note:
Important Coding Guidelines:
Use comments, and whitespaces around operators and assignments.
Use line breaks and indent your code.
Use naming conventions for variables, functions, methods, and more. This makes it easier to understand the code.
Write simple code and do not over complicate the logic. Code exhibits simplicity when it’s well organized, logically minimal, and easily readable.
A pedometer treats walking 1 step as walking 2.5 feet. Define a method named feetToSteps that takes a double as a parameter, representing the number of feet walked, and returns an integer that represents the number of steps walked. Then, write a main program that reads the number of feet walked as an input, calls method feetToSteps() with the input as an argument, and outputs the number of steps.
Use floating-point arithmetic to perform the conversion.
Ex: If the input is:
150.5
the output is:
60
The program must define and call a method:public static int feetToSteps(double…
arrow_forward
1 dosage = 100
2 time since_last_dose = 7
3 is nighttime = False
4 took something_cross_reactive = False
5
6 #You may modify the lines of code above, but don't move them!
7 #When you Submit your code, we'll change these lines to
8 #assign different values to the variables.
9 #
10 # Let's try to use our mathematical operators and logical
11 #operators together.
12 #
13 #Imagine you've been battling a cold. You're deciding whether
14 #to take cough syrup or not, and if so, how much to take.
15 #
16 #time_since_last_dose represents the number of hours since
17 #you Tast took some cough syrup. For every hour it's been,
18 #you're allowed to have one dose.
19 #
20 #If it's nighttime (is_nighttime), then you may double
21 #your dose since you won't be taking any until morning.
22 #
23 #However, if you've taken something cross-reactive
24 #(took_something_cross_reactive), then you should not take
25 #any cough syrup.
26 #
27 #Write a program that will print how large a dose of cough
28 #syrup…
arrow_forward
Create
etBeans project with the following configuration:
Project Name: Assignment_3_6_1
Package: makechange
• Class Name: MakeChange
Write a program that calculates the number of coins necessary to make change for any amount the
user types in. The program should have variables for the amount of:
• toonies
• loonies
quarters
• dimes
nickels
pennies (even though they don't exist any more)
Display all of the information clearly in tl.e output of the program.
HINT: Use integer division (/) and modulus (8) in your calculations.
Your
tion could look similar to:
arrow_forward
SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:9781337102124
Author:Diane Zak
Publisher:Cengage Learning
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Related Questions
- ✓ Exercises Exercise: Write a method _ and _ that computes the region representing the intersection of two regions. Exercise: Write a method _contains__, which checks whether a n-dimensional point belongs to the region. Remember, a point belongs to the region if it belongs to one of the rectangles in the region. ✓ Membership of a point in a region #@title Membership of a point in a region def region_contains (self, p): ### YOUR SOLUTION HERE Region._contains = region_contains [ ] # Tests 10 points. assert (2, 1) in Region (Rectangle((0, 2), (0, 3)), Rectangle((4, 6), (5,8))) assert (2, 1) not in Region (Rectangle((0, 1), (0, 3)), Rectangle((4, 6), (5, 8))) Exercise: Write a method _le_ for regions such that R <= S if the region R is contained in the region S. You can test this by checking that the difference between R and S is empty.arrow_forwardPYTHON ONLY PLZZZ Create a class object with the following attributes and actions: Class Name Class number Classroom Semester Level Subject Actions: Store a class list Print the class list as follows: Class name Class Number Semester Level Subject Test your object: Ask the user for all the information and to enter at least 3 classes test using all the actions of the object print using the to string action Describe the numbers and text you print. Do not just print numbers or strings to the screen explain what each number represents.arrow_forwardThe Problems - contains only problems from the last 2 contests Separate Un-Attempted, Attempted and All cards Problem Difficulty Rating - The Featured drop-down menu has different difficulty ranges so you can try problems that best suit your experience. Popular topics and brands Like most users, Chef didn't know that he could add problems to his personal to-do list by clicking the magic "+" symbol in the upper right corner of each problem page. But once he found out about it, he went crazy and added a lot of problems to his to-do list without looking at their difficulty rating. Rajesh is a beginner and ideally should only try to solve problems strictly below 10001000. Given the difficulty rating list of problems in Chef's to-do list, please help him determine how many of these problems Chef should remove from his to-do list so he is left with only problems with a difficulty rating of less than 10001000. Note: Please answer the question in Python only: Input 1 4 999 1000 1001 1002…arrow_forward
- S1arrow_forwardC++HurdleWords The HurdleWords class is mostly provided to you. HurdleWords is constructed from two files in the data/ folder: ● valid_guesses.txt (all 5 letter guesses considered to be valid words to guess), and ● valid_hurdles.txt (all words that may be selected to be the secret Hurdle.) ● Note: you may edit both text files if you’d like to add custom words to your game. HurdleWords stores all potential valid Hurdles from valid_hurdles.txt into a vector of strings (valid_hurdles_), and all valid guesses from valid_guesses.txt into an unordered set of strings (valid_guesses_). A set is simply a data structure that contains no duplicates and allows for a speedy lookup to check if a given element exists within the set. Because there are over 10,000 valid guesses, we store them in an unordered set to leverage their speediness, as you will need to check if a user-submitted guess is considered valid (i.e. their guess is considered a valid guess in the dictionary). You are responsible for…arrow_forwardDesign the worst calculator ever: an application that accepts two numbers from the user and, when a button is pushed, performs a single operation and displays the results. You may choose: Multiplication, Division, Subtraction, square root, or raising the first number to the exponent of the second number. Don't use addition as we already did that in class. The result must be displayed to the user only when an appropriately labeled button is pushed.arrow_forward
- Pendant Publishing edits multi-volume manuscripts for many authors. For each volume, they want a label that contains the author’s name, the title of the work, and a volume number in the form Volume 9 of 9. For example, a set of three volumes requires three labels: Volume 1 of 3, Volume 2 of 3, and Volume 3 of 3. Design an application that reads records that contain an author’s name, the title of the work, and the number of volumes. The application must read the records until eof is encountered and produce enough labels for each work. The flowchart must include a call symbol, at the beginning, to redirect the input to the external data file. create a solution algorithm using pseudocode create a flowchart using RAPTORarrow_forwardPendant Publishing edits multi-volume manuscripts for many authors. For each volume, they want a label that contains the author’s name, the title of the work, and a volume number in the form Volume 9 of 9. For example, a set of three volumes requires three labels: Volume 1 of 3, Volume 2 of 3, and Volume 3 of 3. Design an application that reads records that contain an author’s name, the title of the work, and the number of volumes. The application must read the records until eof is encountered and produce enough labels for each work. Design a flowchart and psuedocode Pendant Publishing.arrow_forwardCreate a simple program for a quiz Software Requirements: Latest version of NetBeans IDE Java Development Kit (JDK) 8 Procedure: Create a folder named LastName_FirstName (ex. Dahan yoon) in your local Create a new project named LabExer5B. Set the project location to your own The program shall: contain an array of 10 multiple choice questions with three (3) choices each and require the user to choose among A, B, or C; Note: Cases are ignored. Lowercase letters are acceptable (a, b, c). Create a try-catch structure to handle three (3) exceptions. These are when the user inputs the following: an invalid letter (not A, B, or C) a number or any special character blank (no answer) Prompt the user that he can answer again if any of the three (3) exceptions is Display the score.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:CengageProgramming with Microsoft Visual Basic 2017Computer ScienceISBN:9781337102124Author:Diane ZakPublisher:Cengage Learning
- Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:9781337102124
Author:Diane Zak
Publisher:Cengage Learning
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,