Questions Uploads

code in Python

When I run this code in Python

# Get our list from the command line

import sys

numbers = sys.argv[1].split(“,”)

# Your code goes here

def sum(numbers):

 total = 0

 for x in numbers:

  total+=x

 return total

print(sum(numbers))

I get an error that says:

Program Output


Traceback (most recent call last):
  File "sum.py", line 13, in 
    print(sum(numbers))
  File "sum.py", line 10, in sum
    total+=x
TypeError: unsupported operand type(s) for +=: 'int' and 'str'

I don’t know what the error is saying. How can I fix this?

Top Answer

 
Looking for a Similar Assignment? Order now and Get 10% Discount! Use Coupon Code "Newclient"

leadership styles.

What are the different leadership styles. There are numerous sites with some saying 7 leadership styles. Others saying 4 leadership styles. What are the core types of leadership styles?

 
Looking for a Similar Assignment? Order now and Get 10% Discount! Use Coupon Code "Newclient"

Dametres Lopez Codio

A ALLKS Dametres Lopez
Codio – Loops
X
Q
->
https://codio.com/dlopez7/loops:5c1711cbab68f03457dca422:yIR3oRlv7A6p/tree/challenges%2Ffibonacci.py
O X
Coolo
Project
File
Edit
Find
View
Tools
Education
Help
a Configure….
Project Index (static)
Configure…
DL
fibona
nacci.py
6. 5. Fibonac…
# Get N from the command line
import sys
Collapse
Challenges
HNminor
N= int(sys . argv[1])
# Your code goes here
6. 5. Fibonacci sequence
fib=
co –
=0
We will pass in a value N. Write a program that
outputs the complete Fibonacci sequence for N
10
for num in range (0, N+1) :
iterations.
11 .
if (num==0) :
12
v=0
13 v
elif (num==1) :
Important: If N is 0, then we expect to get an output
14
v=1
of 0 . If N=1 then we expect 0, 1 etc.
15
else:
16
v=fib[num -1 ]+fib[num-2]
Check It!
print(v)
fib . append (v)
LAST RUN on 1/26/2019 5:27:18 PM
X
Program Output
Traceback (most recent call last)
File "fibonacci.py". line 16, in
v=fib[num – 1 ]+fib[num-2]
IndexError: list index out of range
50% (10:19
O Type here to search
Python
ei
5:28 PM
1/26/2019Read more

 
Looking for a Similar Assignment? Order now and Get 10% Discount! Use Coupon Code "Newclient"

account balance

I am a bit confused by this can someone explain what this means “As stated in the announcement for this week, global variables should not be used in this project. Information for the function needs to be passed through the argument list and any value returned to the main program has to be through a return  statement.”

this is my script and it worked but i guess i did something wrong??

import sys

#defines account balance 

account_balance = float(500.25)

#defines balance function and prints

def balance():

 print(“Your current balance:n %.2f” % account_balance)

#defines deposit function

def deposit():

#asks user for deposit amt input

 deposit_amount = float(input(“How much would you like to deposit today?n “))

 balance = account_balance + deposit_amount

#prints amt of deposit and acct balance

 print(“Deposit was $%.2f, current balance is $%.2f” % (deposit_amount, balance))

#defines withdraw function

def withdraw():

#asks user for input of withdraw amt 

 withdraw_amount = float(input(“How much would you like to withdraw today?n “))

#verify the withdraw_amount is greater than the account_balance

 if withdraw_amount > account_balance:

  print(“$%.2f is greater than your account balance of $%.2f” % (withdraw_amount, account_balance))

#Calculate the account_balance and display the withdraw_amount,and print the account balance with the ‘$’ and with two decimal points

 else:

  balance = account_balance – withdraw_amount

  print(“Withdrawal amount was $%.2f, current balance is $%.2f” % (withdraw_amount, balance))

#asks for input from user for choice of Withdrawal, Deposit, or Balance

#if/else conditional statement to call function based on user input

userchoice = input (“What would you like to do?n”)

if (userchoice == “D”):

 deposit()

elif (userchoice == “W”):

 withdraw()

elif (userchoice == “B”):

 balance()

else:

 print(“Thank you for banking with us.”)

 
Looking for a Similar Assignment? Order now and Get 10% Discount! Use Coupon Code "Newclient"