Python. Please attach python file if possible. All Instructions
given:
# TEXT CODE:
# defining method recommendation which gives the
rerecommendation
def recommendation(lucky_number, stock_symbol,
current_price):
# create an empty dictionary which will be used to store the
average value of
# performance of last for days for the corresponding valid
symbol
dictionary = {}
print()
print("......calculating......")
print("......crunching........")
print("........hang on........")
# store the average
dictionary["WMT"] = (76.16 + 76.15 + 76.23 + 76.30)/4
dictionary["KO"] = (38.75 + 38.78 + 38.77 + 38.85)/4
dictionary["PG"] = (79.24 + 79.34 + 79.45 + 79.58)/4
dictionary["BRKA"] = (173396.00 + 173490.00 + 173762.00 +
173471.99)/4
dictionary["XOM"] = (87.78 + 88.72 + 87.36 + 89.58)/4
# get the average for the corresponding symbol
average = dictionary[stock_symbol.upper()]
# calculate threshold
threshold = (average*lucky_number - 1)/lucky_number
# if current price is greater than the threshold return SELL
if current_price > threshold:
return "SELL"
# else if current price is lesser than the threshold return
SELL
elif current_price < threshold:
return "BUY"
# else return HOLD
else: return "HOLD"
# defining main method to get the input, validate the inputs and
check the
# recommendation method
def main():
# print the greeting message
print("Welcome to the Lucky Fortune Trading Algorithm!")
# get the lucky_number
# check whether the input number is in valid format
try:
lucky_number = int(input("Enter the lucky number from lunch today:
"))
except:
print("Please enter a valid lucky number")
return
# if number is negative or zero
if lucky_number <= 0:
print("Please enter a positive lucky number")
return
# make a list of valid symbols
stock_symbols = ["WMT", "KO", "PG", "BRKA", "XOM"]
# get the stock_symbol
stock_symbol = str(input("Enter the stock symbol:"))
# check entered stock_symbol is in the the list of valid
stock_symbols
if stock_symbol.upper() not in stock_symbols:
print("Please enter valid stock symbol")
return
# get the current price
current_price = (input("Enter the current price:"))
# check whether first symbol of current_price is $ or not
if current_price[0] != '$':
print("You must enter the dollar sign $ before the current stock
price")
return
# now check whether $ symbol follow valid number in current
price
try:
current_price = float(current_price[1:])
except:
print("$ symbol should follow valid number in current price")
return
# now call recommendation method and store the result
result = recommendation(lucky_number, stock_symbol,
current_price)
print()
if result == "BUY":
print("This stock is undervalued.")
print("BUY!")
elif result == "SELL":
print("This stock is overvalued.")
print("SELL!")
else:
print("This stock is equal to threshold.")
print("HOLD!")
# Driver program
if __name__ == "__main__":
# call main method
main()
SCREENSHOTS:
code:
output:
Python. Please attach python file if possible. All Instructions given: General The program must allow a...
WRITE JAVA PROGRAM Problem Statement You are required to write a stock price simulator, which simulates a price change of a stock. When the program runs, it should do the following: Create a Stock class which must include fields: name, symbol, currentPrice, nextPrice, priceChange, and priceChangePercentage. The Stock class must have two constructor: a no-argument constructor and a constructor with four parameters that correspond to the four fields. o For the no-argument constructor, set the default value for...
I need help with a Python program that has error checking loops. Hour must be a number from 1 to 12. Minute and second must be numbers from 0 to 59. Also check whether “AM” or “PM” is entered. Every time an invalid value is entered, display an error message and ask the user to re-enter a valid value immediately. Functions are not covered yet and are not necessary. Thanks. The following is an example: Enter hour: 0 Hour must...
Project DescriptionWrite a program that calculates the average number of days a company's employees are absent during the year and outputs a report on a file named "employeeAbsences.txt".Project SpecificationsInput for this project:the user must enter the number of employees in the company.the user must enter as integers for each employee:the employee number (ID)the number of days that employee missed during the past year.Input Validation:Do not accept a number less than 1 for the number of employees.Do not accept a negative...
Write the code in Python. The output should be exact the same as
the given.
Question 1. Study the examples below carefully and write a program for journal subscription Your program should work exactly as the following examples The text in bold indicates user input. Example 1: The user is a student, and the user subscribes to 2 journals Question 1 - Journal of Commodity Markets Journal of Sustainable Mining Journal of Asia-Pacific Biodiversity Student $21 $22 $27 Non-student $50...
IN JAVAWrite a program that deals with inflation, which is essentially the rising cost of general goods over time. That is, the price of goods, such as a packet of peanuts, goes up as time goes by. So, you will write a program to gauge the expected cost of an item in a specified number of years. The program asks for the cost of the item, the number of years, and the rate of inflation. The output is the estimated...
I need to write a paint job estimator program in python. I have most of it down but i keep getting errors and I dont know how to fix it or what im doing worng specs: A painting company has determined that for every 350 square feet of wall space, one gallon of paint and six hours of labor are required. The company charges $62.25 per hour for labor. Write a program call paintjobestimator.py that asks the user to enter...
NOTE: Write the Program in python as mentioned below and use while loop and flags as necessary. And please write the code following the program description given below. Directions: Read the program description below carefully. All requirements must be met by your program to receive full credit. Thus, pay particular attention to input and output requirements, structural requirements, and so on. Furthermore, code that contains syntax errors will not receive any credit, so be sure that your code interprets correctly...
PYTHON PROGRAMMING - CODE THE PROGRAM BASED ON THE
INSTRUCTIONS AND ALGORITHM PROVIDED
home / study / engineering / computer science / questions and
answers / python programming - code the program based on ...
Your question has been answered! Rate it below.
Let us know if you got a helpful answer.
Question: PYTHON PROGRAMMING - CODE THE PROGRAM BASED ON
THE...
Bookmark
PYTHON PROGRAMMING - CODE THE PROGRAM BASED ON THE
INSTRUCTIONS AND ALGORITHM PROVIDED
Rainfall Algorithm
Declare and...
CSC151 Stock Portfolio GUI Project
Goal
You are to write a GUI program that will allow a user to
buy, sell and view stocks in a stock portfolio. This document will
describe the minimum expected functions for a grade of 90. Your
mission is to “go and do better.” You’ll find a list of enhancement
options at the end of this document.
Objectives
By the end of this project, the student will be able to
• write a GUI program...
NOTE: Write the Program in python as mentioned below and use while loop and flags as necessary. And please write the code following the program description given below. DON'T use Function concept or any other concept except while loop,if-else. Directions: Read the program description below carefully. All requirements must be met by your program to receive full credit. Thus, pay particular attention to input and output requirements, structural requirements, and so on. Furthermore, code that contains syntax errors will not...