Question

In: Computer Science

in PYTHON If varible counter contains an integer, then write an augmented assignment operation to decrement...

in PYTHON

If varible counter contains an integer, then write an augmented assignment operation to decrement it by 1. A “count-controlled” for loop using the xrange function to average the scores for a class is given below and in the file PartD_average_with_for.py:

# Calculates the average score using a counter-controlled for-loop numberOfScores = input("Enter the number of scores to average: ")

total = 0.0;

for counter in xrange(numberOfScores):

score = input("Enter score #" + str(counter+1) + ": ") total = total + score

if numberOfScores > 0:

print "The average score is", total / numberOfScores

Solutions

Expert Solution

Code:

#Define count

numberOfScores=input("Enter count of scores:")

#Define total

total = 0.0;

#Loop until count of scores

for counter in xrange(numberOfScores):

    #Get value of score

    score = input("Enter score #" + str(counter+1) + ": ")

    #Update score

    total = total + score

    #Decrement counter

    counter = counter-1

#If count greater than 0

if numberOfScores > 0:

    #Display result

    print "The average score is", total / numberOfScores

#Receive number of days

days = int(input("Number of days"))

#Set amount as 1

amount = 1

#Loop until days count

for lcounter in range(days):

    #Double amount each day

    amount = amount*2

#Display total salary paid

print"Total salary paid is "

print amount

print "pennies"


Related Solutions

For Python: In this assignment you are asked to write a Python program to determine the...
For Python: In this assignment you are asked to write a Python program to determine the Academic Standing of a studentbased on their CGPA. The program should do the following: Prompt the user to enter his name. Prompt the user to enter his major. Prompt the user to enter grades for 3 subjects (A, B, C, D, F). Calculate the CGPA of the student. To calculate CGPA use the formula: CGPA = (quality points * credit hours) / credit hours...
IN PYTHON Write a program that takes in a positive integer as input, and outputs a...
IN PYTHON Write a program that takes in a positive integer as input, and outputs a string of 1's and 0's representing the integer in binary. For an integer x, the algorithm is: As long as x is greater than 0 Output x % 2 (remainder is either 0 or 1) x = x // 2 Note: The above algorithm outputs the 0's and 1's in reverse order. You will need to write a second function to reverse the string....
Question on Database Systems - Concurrency Control A popular update operation is increment/decrement the numeric value...
Question on Database Systems - Concurrency Control A popular update operation is increment/decrement the numeric value of data object by 1. Suppose we are now to create a lock mode I, along with usual shared and exclusive lock modes. Consider a locking protocol that will require a request for a lock with mode I on a data object Q (with numeric value) before proceeding with the increment/decrement operation on Q. (i) Provide a lock compatibility matrix with these three modes....
Write a Python program to find the smallest positive integer that is a perfect square and...
Write a Python program to find the smallest positive integer that is a perfect square and it contains exactly three different digits.
Write a function in python that takes in an integer n and computes the left hand...
Write a function in python that takes in an integer n and computes the left hand Riemann sum of the function f(x) = x^2 on the interval [0,1]. Hint: compute the error from the true answer
2) Write an elementary calculator in which the main program reads an integer input, an operation...
2) Write an elementary calculator in which the main program reads an integer input, an operation (+,-,*,/), and another integer input. It then passes this information to a function (calc) to perform this operation. This function (calc) returns the result using switch statements for operation decision. The program stops when the user inputs 0 for both integer inputs in the main program.
Long Integer Addition For this assignment you are to write a class that supports the addition...
Long Integer Addition For this assignment you are to write a class that supports the addition of extra long integers, by using linked-lists. Longer than what is supported by Java's built-in data type, called long. Your program will take in two strings, consisting of only digits, covert each of them to a linked-list that represents an integer version on that string. Then it will create a third linked-list that represents the sum of both of the linked lists. Lastly, it...
write a python program that inputs 10 integer values from the keyboard and then displays their...
write a python program that inputs 10 integer values from the keyboard and then displays their sum. use for loop
PLEASE INCLUDE #FOR EACH LINE EXPLANATION Write a PYTHON PROGRAM that prompts for an integer and...
PLEASE INCLUDE #FOR EACH LINE EXPLANATION Write a PYTHON PROGRAM that prompts for an integer and prints the integer, but if something other than an integer is input, the program keeps asking for an integer. Here is a sample session: Input an integer: abc Error: try again. Input an integer: 4a Error: try again. Input an integer: 2.5 Error: try again. Input an integer: 123 The integer is: 123 Hint: the string isdigit method will be useful to solve this...
Write, in Python, a recursive algorithm that takes, as input, a positive integer n, and returns,...
Write, in Python, a recursive algorithm that takes, as input, a positive integer n, and returns, as output, the sum of the first n positive odd integers. Your solution should be recursive, and it should not contain any "for" loops or "while" loops.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT