I've been having issues with the programmers in this service providing a working python code that works
Question:
I've been having issues with the programmers in this service providing a working python code that works in Idle Shell 3.11.5 when executing the run button and not getting a error message. I now have only around an hour left to submit this homework assignment or I'll fail. At this point, I need to get this file in py uploaded or emailed to me ASAP and I review and I'll see if there's anything I been doing wrong when pasting the code into Idle Shell.
Attached is a screenshot of the error message I get. I was getting other messages as well. I used multiple credits already to get the correct answer for this assignment and other assignments and so far haven't had any luck with anyone sending me a correct code and it has been very stressful! Check the previous answer from 2 different experts who program didn't work correctly.
Please review the assignment below, including the screenshot and upload or send to my email: stanwilljr@yahoo.com
I'm getting ready to post the other question assignment file output in another post as well so look out for the other question in another post. Thanks!
Read assignment below, and the 2 different answers from the experts who program didn't work. I need this saved in py and uploaded and/or emailed ASAP!
Inspect input (branching)
Write a Python code program that does the following:
Given two integers input by the computer user from the console, return their product (the first number times the second number) only if the product is greater than 1000, else return their sum (the first number plus the second number).
How to accept user input
See this w3schools lesson https://www.w3schools.com/python/ref_func_input.asp
Hints on handling multiple inputs https://www.geeksforgeeks.org/taking-multiple-inputs-from-user-in-python/
How to change data types (you will need to convert the String from input into some kind of numerical type)
https://www.w3schools.com/python/python_casting.asp https://www.w3schools.com/python/python_casting.asp
(read the examples)
Expert Answer 2
Here's a Python program that takes two integers as input from the user, calculates their product or sum based on the condition, and then returns the result: a# Accept two integers as input from the user
try:
num1 = int(input("Enter the first integer: "))
num2 = int(input("Enter the second integer: "))
except ValueError:
print("Invalid input. Please enter integers.")
exit()
# Calculate the product and sum
product = num1 * num2
sum_result = num1 + num2
# Check the condition and return the result
if product > 1000:
print("Product:", product)
else:
print("Sum:", sum_result)
This code first tries to convert the user input into integers using int(). If the conversion fails (e.g., if the user enters non-integer values), it prints an error message and exits. Otherwise, it calculates both the product and the sum and checks the condition to determine which result to print.
You can run this code in a Python environment, and it will ask the user for two integers and provide the appropriate result.
Expert Answer 1
Python Code:
# Accept two integers as input from the user
try:
num1 = int(input("Enter the first integer: "))
num2 = int(input("Enter the second integer: "))
# Calculate the product and sum
product = num1 * num2
total = num1 + num2
# Check if the product is greater than 1000
if product > 1000:
print("The product is greater than 1000:", product)
else:
print("The sum is:", total)
except ValueError:
print("Please enter valid integers.")
Example output:
Example 1:
```
Enter the first integer: 20
Enter the second integer: 50
The sum is: 70
```
Example 2:
```
Enter the first integer: 40
Enter the second integer: 35
The sum is: 75
```
Example 3:
```
Enter the first integer: 25
Enter the second integer: 60
The product is greater than 1000: 1500
```
Example 4 (with invalid input):
```
Enter the first integer: abc
enter valid integers.
```
Accounting for Decision Making and Control
ISBN: 978-1259564550
9th edition
Authors: Jerold Zimmerman