Python Forum

Full Version: Python Homework Help *Urgent
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello everyone, first time posting here and just wanted some help with some python homework. I've been taking a GIS college program which consists of learning python (I'm still a beginner and the program is accelerated (7-8 courses a semester) so I've had some trouble catching up. If anyone can help with these set of questions, I would appreciate it or at least how I would go about completing it would be great. The assignment is due in a couple of hours so I can use all the help I can get, thanks again for any help and PM me if anything.




Deliverable 7
Consider the following code segment

m = [ ‘have’, ‘fun’ ]

x, y = m

a. What are the values of x and y after the second line has been processed.

b. What python structure is x, y

c. In your own words, explain what is happening when line 2 is processed.

d. Write a line of code that swaps the values of x and y



2.

a. Add Python statements below each comment to sequentially do the tasks specified in the comments

# Assign your name to the variable myName # Create an empty dictionary

# Create a loop that uses the variable myName to traverse the letters # in your name, one at a time

# For each letter, check to see whether the letter is in the dictionary

# When the letter is not in the dictionary, create a new item in the dictionary # with the letter as the key and the value 1

# When the letter is in the dictionary, increment that letter’s value # in the dictionary by 1

# After all the letters in your name have been processed, display the dictionary



b. In your own words, explain the purpose of this code segment




3. The following code segment creates a Customer class

class Customer(object):

def init (self):

self.name = name

self.balance = balance

def withdraw(self, amount):





a. Modify the Customer class as instructed below

· Give the Customer object a name and an initial balance when the Customer object is created (instantiated).

· Change the withdrawal method to

‒ make sure the amount to be withdrawn is less than the available balance

‒ adjust the Customer’s current balance by the withdrawal amount

· Include a deposit method that adds the amount of the deposit to the Customer’s current balance





b. Create a short Python program that does the following, in the order listed

· Creates a customer object with your name and an initial balance of 0 dollars using the Customer class

· Displays the customer’s name and current balance

· Uses the deposit method on the customer with your name to deposit $300, then $200 and then $100

· Displays the customer’s name and current balance

· Uses the withdrawal method on the customer with your name to take out $150

· Displays the customer’s name and current balance

· Creates a second customer object with a different name from your name and an initial balance of $1000

· Uses the withdrawal method on the second customer to take out $400

· Displays the second customer’s name and current balance
If you make a program that deposits all those amounts into my account, I'll do your homework for you. It's the only shot you have.

Try opening the book next time.
What have you tried? We're not big on writing code for people here, but we would be happy to help you fix your code when you run into problems. When you do run into problems, please post your code in Python tags, and clearly explain the problem you are having, including the full text of any errors.