need to add this withdrawal and balance function to the script below:
Calculate the Balance - Withdrawal
If the action is Withdrawal ‘W’, use the withdrawal function to remove funds from the account
Hint – The formatter for a float value in Python is %f. With the formatter %.2f, you format the float to have 2 decimal places. For example:
print("Account balance: $%.2f" % account_balance)
Withdrawal Information
Withdraw Input
userchoice = input ("What would you like to do?\n")
userchoice = 'W'
withdrawal_amount = 100
Withdraw Output
What would you like to do? How much would you like to withdraw today? Withdrawal amount was $100, current balance is $600.25
ATM Summary Feedback Available
If you would like our automated system to review your code and give you some feedback on your project before you submit for a grade, just click the Help Me! button below.
Help Me!
withdrawal_amount is greater than your account balance of account_balance
Ensure you display the withdrawal amount and the account balance with the '$' and two decimal points.Withdrawal amount was withdrawal_amount, current balance is account_balance
Need to add the Withdrawal amount to this program:
import sys # importing the sys library
# account balance
account_balance = float(500.25)
# PPrint the balance
# This is a custom function, it returns the current balance upto 2 decimal places
def printbalance():
print('Your current balance:')
return account_balance
# the function for deposit
# This is a custom function
def deposit():
# takes in input for deposit amount
deposit_amount = float(
input("How much would you like to deposit today?\n"))
balance = account_balance + deposit_amount # calculates balance
print("Deposit was $%.2f, current balance is $%.2f" %
(deposit_amount, balance)) # prints out the balance
# function for withdraw
# this is a custom function
def withdraw():
# takes in the withdraw amount
withdraw_amount = float(input("Enter amount to withdraw"))
if(withdraw_amount > account_balance): # checks whether the amount is more than balance or not
print("$%2f is greater than account balance $%2f\n" %
(withdraw_amount, account_balance)) # if yes then
else:
balance = account_balance - withdraw_amount
print("$%2f was withdrawn, current balance is $%2f" %
(withdraw_amount, balance))
# User Input goes here, use if/else conditional statement to call function based on user input
userchoice = input("What would you like to do?\n")
if (userchoice == 'D'):
# here deposit function is called
deposit()
elif userchoice == 'W':
# here withdraw function is called
withdraw()
elif userchoice == 'B':
# here printbalance function is called
balance = printbalance()
print('{:.2f}'.format(balance))
else:
# it ends the program execution
sys.exit()
In: Computer Science
Suggest an appropriate project methodology that might be used for development of the following computer systems. Provide proper justification of your choice.
In: Computer Science
In: Computer Science
Distinguish between logical models and physical models. How is each useful?
In: Computer Science
Modify your program from Learning Journal Unit 7 to read dictionary items from a file and write the inverted dictionary to a file. You will need to decide on the following:
Create an input file with your original three-or-more items and add at least three new items, for a total of at least six items.
Copy your program from Part 1 and modify it to do the following:
It will be interesting to see if your original dictionary is reversible. If you invert it twice, do you get the original dictionary back?
Include the following in your Learning Journal submission:
Learning Journal Unit 7
Create a Python dictionary where the value is a list . The key can be whatever type you want.
Design the dictionary so that it could be useful for something meaningful to you. Create at least three different items in it. Invent the dictionary yourself. Do not copy the design or items from some other source.
Next consider the invert_dict function from Section 11.5 of your textbook.
# From Section 11.5 of:
# Downey, A. (2015). Think Python: How to think like a computer
scientist . Needham, Massachusetts: Green Tree Press.
definvert_dict(d):
inverse = dict()
for key in d:
val = d[key]
if val not in inverse:
inverse[val] = [key]
else:
inverse[val].append(key)
return inverse
Modify this function so that it can invert your dictionary. In particular, the function will need to turn each of the list items into separate keys in the inverted dictionary.
Run your modified invert_dict function on your dictionary. Print the original dictionary and the inverted one.
Include your Python program and the output in your Learning Journal submission.
Describe what is useful about your dictionary. Then describe whether the inverted dictionary is useful or meaningful, and why.
In: Computer Science
Letter Separated Numbers (C++)
I've encountered a corrupted database that has a series of important numbers, but instead of being separated by a space, the spaces have been randomly changed in alphabetic characters. Write a function named "my_numbers" that can take a string like "18y5638b-78" and return a vector of ints {18, 5638, -78}.
Thanks!
In: Computer Science
Write an inheritance hierarchy for classes Quadrilateral, Trapezoid, Parallelogram, Rectangle and Square. Use Quadrilateral as the superclass of the hierarchy. Create and use a Point class to represent the points in each shape. Make the hierarchy as deep ( i.e., as many levels ) as possible. Specify the instance variables and methods for each class. The private instances variables of Quadrilateral should be the x-y coordinate pairs for the four endpoints of the Quadrilateral. Write a program that instantiates objects of your classes and outputs each object’s area (except Quadrilateral).
In: Computer Science
Using java:
Implement a basic doubly-linked list that implements a priority system sorting the elements that are inserted. Sort based on the speed of the warrior.
Driver code:
public class LinkedListDriver {
public static void main(String[] args) {
LinkedList list = new SortedDoublyLinkedList();
System.out.println(list);
Warrior krogg = new Warrior("Krogg", 30, 50, 200);
list.insert(krogg);
System.out.println(list);
Warrior gurkh = new Warrior("Gurkh", 40, 45, 180);
list.insert(gurkh);
System.out.println(list);
Warrior brynn = new Warrior("Brynn", 45, 40, 190);
list.insert(brynn);
System.out.println(list);
Warrior dolf = new Warrior("Dolf", 20, 65, 210);
list.insert(dolf);
System.out.println(list);
Warrior zuni = new Warrior("Zuni", 50, 35, 170);
list.insert(zuni);
System.out.println(list);
}
}
Warrior class:
public class Warrior {
private String name;
private int speed;
private int strength;
private int hp;
public Warrior(String name, int speed, int str, int hp) {
this.name = name;
this.speed = speed;
this.strength = str;
this.hp = hp;
}
public String getName() { return this.name; }
public int getSpeed() { return this.speed; }
public int getStrength() { return this.strength; }
public int getHp() { return this.hp; }
public String toString() { return this.name + "(" +
this.speed + ")"; }
}
Class that needs to be done:
interface LinkedList {
void insert(Warrior warrior);
String toString();
}
Expected output:
[ Zuni(50) Brynn(45) Gurkh(40) Krogg(30) Dolf(20) ]
In: Computer Science
Design a universal hashing scheme using matrix operations.
In: Computer Science
A survey of chewing gum preferences was given to baseball players. On the survey form, fruit was checked a total of 21 times; spearmint was checked a total of 26 times; 12 players checked both; 7 surveys had nothing checked. How many players were surveyed?
In: Computer Science
2. Consider the following relations:
Doctor(SSN, FirstName, LastName, Specialty,YearsOfExperience, PhoneNum)
Patient(SSN, FirstName, LastName, Address, DOB, PrimaryDoctor_SSN)
Medicine(TradeName, UnitPrice, GenericFlag)
Prescription(Prescription Id, Date, Doctor_SSN, Patient_SSN)
Prescription_Medicine(Prescription Id, TradeName, NumOfUnits)
Note: The Medicine relation has attributes, trade name, unit price, and whether or not the medicine is generic (True or False).
a. Determine the functional dependencies that exist in each table given above.
In: Computer Science
the purpose of the code is to implement a stack
how can i convert this code in a way that these changes apply to it?
// simplify the logic of the main
// getline(cin, line) needs to be changed to a normal cin >> line;
//make a function for 'list'
// not allowed temporary stack (stack s2)
//merge the catches (errors)
// introduce another function for main
// avoid repetitive code
here is the code:
#include
#include
#include
#include
#include
using namespace std;
class Stack {
public:
bool isEmpty();
int top();
int pop();
void push(int);
private:
vector elements;
};
bool Stack::isEmpty() {
return elements.empty();
}
int Stack::top() {
if(isEmpty()) {
throw runtime_error("error: stack is empty");
}
else {
return elements.back();
}
}
int Stack::pop() {
if(isEmpty()) {
throw runtime_error("error: stack is empty");
}
else {
int item = elements.back();
elements.pop_back();
return item;
}
}
void Stack::push(int item) {
elements.push_back(item);
}
int main() {
string line, cmd;
int val;
Stack stack;
cout << "stack> " << endl;
while(getline(cin, line)) {
if(line.find_first_not_of(" \t") == string:: npos) {
cout << "stack> ";
continue;
}
line = line.substr(line.find_first_not_of(" \t"));
cmd = line.substr(0, line.find(" "));
if(cmd == "push") {
try {
line = line.substr(line.find(" ") + 1);
if(line.size() == 0 || line.at(0) == '-' || line.at(0) == '+' && line.find_first_of("0123456789") > 1 || line.find_first_not_of("0123456789+-") == 0) {
throw runtime_error("error: not a number");
}
else {
val = atoi(line.c_str());
stack.push(val);
}
}
catch(runtime_error& excpt) {
cout << excpt.what() << endl;
}
}
else if(cmd == "pop") {
try {
val = stack.pop();
cout << val << endl;
}
catch(runtime_error& excpt) {
cout << excpt.what() << endl;
}
}
else if(cmd == "top") {
try {
val = stack.top();
cout << val << endl;
}
catch(runtime_error& excpt) {
cout << excpt.what() << endl;
}
}
else if(cmd == "list") {
Stack s2;
bool first = true;
cout << "[";
while(!stack.isEmpty()) {
val = stack.pop();
s2.push(val);
if(!first) {
cout << ",";
}
cout << val;
first = false;
}
cout << "]" << endl;
while(!s2.isEmpty()) {
stack.push(s2.pop());
}
}
else if(cmd == "end") {
break;
}
else {
cin.ignore(numeric_limits::max(), '\n');
cout << "error: invalid command" << endl;
}
cout << "stack> " << endl;
}
}
In: Computer Science
Understand the following tools, the steps in creating the tool, and the purpose/usefulness of each: Activity Diagram, Use Case Description, Use Case Diagram, CRC Card, Class Diagram, Sequence Diagrams, Communication Diagram, or Behavioral State Machine. Define it, describe its purpose/usefulness, and list/define the major steps in using the tool. You should be able to illustrate the tool using a scenario.
In depicting a class on a class diagram, each class is shown with 3 parts. Define each part and explain what each part shows. Include an illustration.
In: Computer Science
Using C++, identify suitable coding modules for the following
(a) Overload the * operator so that two instances of Quat can be
multiplied using the * operator.
Given that q1 and q2 are Quaternions. Let q1 = (a1, b1i, c1j, d1k)
and q2 = (a2, b2i, c2j, d2k)
The product (q1 * q2) is ( a1a2 – b1b2 – c1c2 – d1d2, (a1b2 + b1a2
+ c1d2 – d1c2)i, (a1c2 + c1a2 + d1b2 – b1d2)j, (a1d2 + d1a2 + b1c2
– c1b2)k )
For example
sq1 = (5, 2i, 6j, 8k)
sq2 = (3, 5i, 7j, 6k)
sq3 = sq1 * sq2 = (-85, 11i, 81j, 38k)
(b) Overload the == operator so that we can check whether two
instances of Quat are equal. Two instances are equal if each
element in one instance is equal to the corresponding element in
the other instance.
In: Computer Science
You have 10 shirts, 9 pants, and 4 belts. How many outfits can you make out of these? (Assume all colors are perfectly coordinated.)
In: Computer Science