A relational expression is a test between two or more statements. If the test passes, then...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
A relational expression is a test between two or more statements. If the test passes, then the result is true. Otherwise it's false. Write down the python statements for the given relational expressions. Assign a value of your choice to the variable. Use the print() function to print the output of relational expression. Make sure to use the correct operators for each mathematical operator used. Follow the first example. Example. x<16: #Your Code Here xs4x-4: #Your Code Here 2<x<4 : #Your Code Here x<yllysw: #Your Code Here Question 2: a. Suppose x and y are variables, each of which contains a number that you take as input from user. Write a code that can set y to x if x is positive and sets y to 0 if x is negative. b. Suppose x and y are variables, each of which contains a number. Write a code sets y to the absolute value of x without calling the abs() function. Use an if statement. Question 3: Demonstrate a program to read two positive numbers from the user. Those numbers represent the width and length of a two-dimensional shape. The solution should display whether the shape is a rectangle or a square based on the equality of the length and width values. Make sure to validate the user input, if the user does not enter positive numbers, display a logical error message. Valid input is the numbers between 1 and 20 for both length and width. Anything other than these numbers is considered as invalid input. You must compare the length and width to determine the shape only if the user enter correct values. This will require a nested if structure. Include the following: . reading input from user: • validate user input: • correct comparison: • used a nested-if structure: Demonstrate a program to receive the following inputs from a customer: Amount of grocery online shopping Store name Type of delivery (delivery or pick up) . Question 4: Use the above input values and compute the final total price and print the result to inform customer. (Do not forget to add service charges as well to each purchase, service charges are applied after adding the delivery or : cost.). Your format should be a "Nested branches" by using "if" and/or "else" and/or "elif" and any other necessary Python commands. Test the input for 2 different sets of inputs and show the results. In order to test the code for multiple inputs and to show the result, you can copy the same code and multiple cells and run each time with a different set of input values. Include the following: input (grocery amount, store name, delivery type): • correct use of decision statements: correct computation of total amount: • displaying output: . • proper use of variable names, proper comments, simple logic: • Testing for atleast 2 inputs: . . Question 5: In the class we discussed the example of students' grade using if-elif-else structure. In both of these examples, the order of tests matter. If you change the order of tests (conditions), you will get an incorrect ouput. Your task in this question is to give an example of an if/elif/else sequence where the order of the tests does not matter and give an example where the order of the tests matters. (please write a legit example like students' grading example, but do not write it) Specify your problem statement and then write down your input. Test your inputs for atleast 1 test cases in each group. Include the following: • correct example of "order of tests does not matter" and correct use of i-elif-else: . . • correct example of "order of tests matters" and correct use of if-elif-else: Testing: Probelm well explained: . . A relational expression is a test between two or more statements. If the test passes, then the result is true. Otherwise it's false. Write down the python statements for the given relational expressions. Assign a value of your choice to the variable. Use the print() function to print the output of relational expression. Make sure to use the correct operators for each mathematical operator used. Follow the first example. Example. x<16: #Your Code Here xs4x-4: #Your Code Here 2<x<4 : #Your Code Here x<yllysw: #Your Code Here Question 2: a. Suppose x and y are variables, each of which contains a number that you take as input from user. Write a code that can set y to x if x is positive and sets y to 0 if x is negative. b. Suppose x and y are variables, each of which contains a number. Write a code sets y to the absolute value of x without calling the abs() function. Use an if statement. Question 3: Demonstrate a program to read two positive numbers from the user. Those numbers represent the width and length of a two-dimensional shape. The solution should display whether the shape is a rectangle or a square based on the equality of the length and width values. Make sure to validate the user input, if the user does not enter positive numbers, display a logical error message. Valid input is the numbers between 1 and 20 for both length and width. Anything other than these numbers is considered as invalid input. You must compare the length and width to determine the shape only if the user enter correct values. This will require a nested if structure. Include the following: . reading input from user: • validate user input: • correct comparison: • used a nested-if structure: Demonstrate a program to receive the following inputs from a customer: Amount of grocery online shopping Store name Type of delivery (delivery or pick up) . Question 4: Use the above input values and compute the final total price and print the result to inform customer. (Do not forget to add service charges as well to each purchase, service charges are applied after adding the delivery or : cost.). Your format should be a "Nested branches" by using "if" and/or "else" and/or "elif" and any other necessary Python commands. Test the input for 2 different sets of inputs and show the results. In order to test the code for multiple inputs and to show the result, you can copy the same code and multiple cells and run each time with a different set of input values. Include the following: input (grocery amount, store name, delivery type): • correct use of decision statements: correct computation of total amount: • displaying output: . • proper use of variable names, proper comments, simple logic: • Testing for atleast 2 inputs: . . Question 5: In the class we discussed the example of students' grade using if-elif-else structure. In both of these examples, the order of tests matter. If you change the order of tests (conditions), you will get an incorrect ouput. Your task in this question is to give an example of an if/elif/else sequence where the order of the tests does not matter and give an example where the order of the tests matters. (please write a legit example like students' grading example, but do not write it) Specify your problem statement and then write down your input. Test your inputs for atleast 1 test cases in each group. Include the following: • correct example of "order of tests does not matter" and correct use of i-elif-else: . . • correct example of "order of tests matters" and correct use of if-elif-else: Testing: Probelm well explained: . .
Expert Answer:
Related Book For
Posted Date:
Students also viewed these programming questions
-
Find r'(t), r(t 0 ), and r'(t 0 ) for the given value of t 0 . Then sketch the plane curve represented by the vector-valued function, and sketch the vectors r(t 0 ) and r'(t 0 ). Position the vectors...
-
What pretax amounts related to the lease would Abbott report in its balance sheet on December 31, 2024 and income statement for the year ended December 31, 2024? Note: Enter your answers in whole...
-
Planning is one of the most important management functions in any business. A front office managers first step in planning should involve determine the departments goals. Planning also includes...
-
Francine Frost graduated from State University with a degree in accounting five years ago, she was promoted to manager last week by the local CPA firm Ross & Denning, LLP. The firm has two...
-
Reaction of (S)-3-methyl-2-pentanone with methyl magnesium bromide followed by acidification yields 2, 3-dlmethyl-2-pentanol. What is the stereo chemistry of the product? Is the product optically...
-
The Fundamental Theorem of Algebra, [22], states that a non-zero polynomial of degree n has at most n distinct real roots p(x) = 0. Use this fact to prove linear independence of the monomial...
-
The long, straight current-carrying wire of Figure P27.16 lies in the plane of the page, and the magnetic field it produces at position \(\mathrm{P}\) points out of the page. (a) In what direction...
-
Without referring to the preprogrammed function on your financial calculator, use the basic formula for future value along with the given interest rate, r, and the number of periods, n, to calculate...
-
15.A ray of light is incident on a slab as shown in figure. The refractive index of medium of slab changes as =1+ y. The angle made by ray with x-axis at y = 2 is 30 0 air 2
-
4. (Chapter 3) Skycell, a major European cell phone manufacturer, is making production plans for the coming year. Skycell has worked with its customers (the service providers) to come up with...
-
Explain the guidelines for building a successful Web strategy for a small e-company
-
This case is about the social network Facebook, which hardly needs an introduction. However, when we first featured it in an earlier edition of his text, it was a niche service mainly used in...
-
Explain the options for applying social media marketing to B2B marketing campaigns.
-
What is website prototyping? Give three benefits of this approach.
-
Explain personalisation in a digital marketing context.
-
How should companies decide on the granularity of targeting in digital media campaigns? Select two digital media channels to illustrate your examples.
-
Your credit card company charges you 1.06 percent per month.What is the annual percentage rate on your account?
-
Akramin just graduated with a Master of Engineering in Manufacturing Engineering and landed a new job in Melaka with a starting salary of RM 4,000 per month. There are a number of things that he...
-
The Iron Chicken restaurant is located on a busy interstate return to the Iron Chicken. But some are truck drivers whose routes take them past the Iron Chicken on a regular basis. Sybil, the...
-
Priscilla finds it optimal not to engage in trade at the going prices and just consumes her endowment. Priscilla has no kinks in her indifference curves, and she is endowed with positive amounts of...
-
Molly has a Cobb-Douglas utility function U (c1, c2) = ca1 c1a2, where 0 < a < 1 and where c1 and c2 are her consumptions in periods 1 and 2 respectively. We saw earlier that if utility has the form...
-
Why is it important to synchronize data and process models?
-
Create the use-case descriptions and diagram(s) for the system in problems 1 and 2. Be sure to create your use cases so that they are complete and clear. Remember, in real life, the system...
-
Conduct a technical feasibility study. What would you recommend the company use in the creation and maintenance of their site (e.g. languages, speciific host, encryption)? Why does your choice affect...
Study smarter with the SolutionInn App