 definition of a function absoluteValue that recieves a parameter containing an integer value and returns the absolute value of that parameter.
- Define a function called isPositive that takes a parameter containing an integer value and returns True if the paramter is positive or False if the parameter is negative or 0.
- Define a function called isSenior that takes a parameter containing an integer value and returns True if the parameter is greater than or equal to 65, and Falseotherwise.
Assume that max2 is a function that expects two int parameters and returns the value of the larger one.
Also assume that four variables, population1, population2, population3, and population4 have already been defined and associated with int values.
Write an expression (not a statement!) whose value is the largest of population1, population2, population3, and population4 by calling max2.
- Given a file object named output, associate it with a file named yearsummary.txt by opening the file for appending
- Given that corpdata is a file object used for reading data and that there is no more data to be read, write the necessary code to complete your use of this object.
- Using the file object input, write code that read an integer from a file called rawdata into a variabledatum (make sure you assign an integer value to datum). Open the file at the beginning of your code, and close it at the end.
- A file named numbers.txt contains an unknown number of lines, each consisting of a single positive integer. Write some code that reads through the file and stores the largest number read in a variablenamed maxvalue.
- A file named data.txt contains an unknown number of lines, each consisting of a single integer. Write some code that creates two files, dataplus.txt and dataminus.txt, and copies all the lines of data1.txt that have positive integers to dataplus.txt, and all the lines of data1.txt that have negative integers to dataminus.txt. Zeros are not copied anywhere.
- Two files named numbers1.txt and numbers2.txt both have an unknown number of lines, each line consisting of a single positive integer. Write some code that reads a line from one file and then a line from the other file. The two integers are multiplied together and their product is added to a variablecalled scalar_product which should be initialized to zero.
Your code should stop when it detects end of file in either file that it is reading.
For example, if the sequence of integers in one file was “9 7 5 18 13 2 22 16” and “4 7 8 2” in the other file, your code would compute:
4*9 + 7*7 + 8*5 + 2*18
and thus store 161 into scalar_product.
- Two variables, num_boys and num_girls, hold the number of boys and girls that have registered for an elementary school. The variablebudget holds the number of dollars that have been allocated to the school for the school year. Write code that prints out the per-student budget (dollar spent per student). If a division by zero error takes place, just print out the word “unavailable”.