Write the definition of a function twice

Assignment Help Python Programming
Reference no: EM132079688

Question: 1) Write the definition of a function twice, that receives an int parameter and returns an int that is twice the value of the parameter.

2) Write the definition of a function square which recieves a parameter containing an integer value and returns the square of the value of the parameter.

3) Write the definition of a function typing_speed, that receives two parameters. The first is the number of words that a person has typed (an int greater than or equal to zero) in a particular time interval. The second is the length of the time interval in seconds (an int greater than zero). The function returns the typing speed of that person in words per minute (a float).

4) Write a function min that has three str parameters and returns the smallest. (Smallest in the sense of coming first alphabetically, not in the sense of "shortest")

5) Assume the availability of a function is_prime. Assume a variable n has been associated with positive integer. Write the statements needed to compute the sum of the first n prime numbers. The sum should be associated with the variable total.
Note: is_prime takes an integer as a parameter and returns True if and only if that integer is prime.

6) Assume the availability of a function is_prime. Assume a variable n has been associated with positive integer. Write the statements needed to find out how many prime numbers (starting with 2 and going in increasing order with successively higher primes [2,3,5,7,11,13,...]) can be added before exceeding n. Associate this number with the variable k.

7) Write the definition of a function oneLess which recieves a parameter containing an integer value and returns an integer whose value is one less than the value of the parameter.

8) [Functions >> functions and if statements] Write the definition of a function powerTo which recieves two parameters, a double and an integer. If the second parameter is positive, the function returns the value of the first parameter raised to the power of the second. Otherwise, the function returns 0.

9) Write the definition of a function absoluteValue that recieves a parameter containing an integer value and returns the absolute value of that parameter.

10) 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.

11) 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.

12) Given a file object named output, associate it with a file named yearsummary.txt by opening the file for appending

13) 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.

14) Using the file object input, write code that read an integer from a file called rawdata into a variable datum (make sure you assign an integer value to datum). Open the file at the beginning of your code, and close it at the end.

15) 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 variable named maxvalue.

16) 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.

17) 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 variable called 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.

18) Two variables, num_boys and num_girls, hold the number of boys and girls that have registered for an elementary school. The variable budget 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".

Reference no: EM132079688

Questions Cloud

When should information be disseminated to each recipient : The lax security at these locations, coupled with a wide social and economic population sampling, will make identifying victims and stopping the spread.
What is the present value of an annuity : What is the present value of an annuity in which $200 is paid each year for 10 years, assuming a discount rate of 6% and the first payment is received one year
Investment earning a stated annual rate : You have $50,000 in savings for retirement in an investment earning a stated annual rate of 7% compounded monthly.
Total profit or loss on all the transactions : What will be your total profit or loss on all the transactions related to these option positions if the stock price is $28.40 on the day the options expire?
Write the definition of a function twice : Write the definition of a function twice, that receives an int parameter and returns an int that is twice the value of the parameter.
What is the value of five put option contracts : Andover Paper stock is selling for $28.75 a share. One $28 call is valued at $1.25 and one $28 put is valued at $.47.
Why you find the opinion or case to be most significant : Explain which of the landmark federal criminal justice cases below is the most significant for promoting social justice in our present day.
Explain the patriot act and the homeland security act : Many legal and political voices have advocated that these acts have resulted in a reduction in the rights of citizens and a loss of civil liberties.
Healthcare system using technology to connect with patients : Healthcare system using technology to connect with patients and providers - Write 2-5 paragraphs for each of your supporting points.

Reviews

Write a Review

Python Programming Questions & Answers

  Display the percent-ages of the overall grade

Write a program that uses a bar chart to display the percent-ages of the overall grade represented by the project, quizzes the midterm exam and the final exam

  Write program that read a text file and prints only odd line

Write a program that reads a text file and prints out only odd lines to the screen. Thus, lines 1, 3, 5,... only printed. Update your odd lines program (Q1) to write odd lines to the screen and write then lines to another file.

  Develop an employee class that keeps data attributes

Develop an Employee class that keeps data attributes for the following pieces of information: Employee name and Employee number.

  Implement functions for insertion sort

Implement functions for Insertion sort and bubble sort in python programming language and a function that calculates the function execution time.

  Simulate a simple banking interface

ITECH1400 – Foundations of Programming - Assignment – FedUni Banking - The ability to view the balance of the bank account and to deposit and withdraw virtual

  Write a python function named numvowels

Write a Python function named numVowels that is passed a string containing letters, each of which may be in either uppercase or lowercase.

  Email spam filter

Analyze the emails and predict whether the mail is a spam or not a spam - Create a training file and copy the text of several mails and spams in to it And create a test set identical to the training set but with different examples.

  Write a program that generates two integers

Write a program that generates two integers under 100, show them on screen, and prompts the user to enter the sum of these two integers. The program then reports true if the answer is correct, false otherwise.

  Write a python program that inputs a polynomial

Write a Python program that inputs a polynomial in standard algebraic notation and outputs the first derivative of that polynomial.

  The number of lowercase letters in the file

The number of uppercase letters in the file The number of lowercase letters in the file

  List similar names of the files in the directory

provide a written discussion of your code, what are its strengths and weaknesses, what are the boundary conditions where it will fail and where could it

  How is the survival chance related to the gender

How is the survival chance related to the gender? How is the survival chance related to age? How is the survival chance related to socio-economic status?

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd