Q1:

Real Estate buy houses as investments. At the end of each year the value of the house is estimated to grow by 5%. An Example for 5 years investment is as follows.

#Sample run for q1.py
Please enter your investment amount: 1000000
Please enter number of years: 5
Year Value (Million Dollars)
---- -----------------------
1 1.050000
2 1.102500
3 1.157625
4 1.215506
5 1.276282

Write a function calc_profit that takes two parameters. A number (integer or decimal) called principal which is the amount of money to invest in the house and a number (integer) called year which represents the number of years of investment. The function calculates and displays the value of growth per year. Save the function in a PyDev library module named a6_functions.py

Write and test a main program named q1.py that tests the function.

  • Test your program with data different than the example.
  • The input is taken in q1.py but the output is displayed in the function.
  • The output investment value is always displayed/formatted in millions. The number of decimal points in the output must be six.
  • Copy the results to testing.txt .
  • Assume: for year only positive integer will be entered and for investment only positive integer/decimal value will be inserted.

Q2:

In mathematics, a square number or perfect square is an integer that is the square of an integer; in other words, it is the product of some integer with itself. (i.e 9 is a perfect square 9 = 3 x 3 while 7 is not). Write a function called perfect_square that takes an integer called num as parameter and prints all the perfect square numbers between 1 and num (exclusive). If num is not a positive integer, your function should display an error message. Save the function in a PyDev library module named a6_functions.py (same as other questions)

Write a main program q2.py to test the function by asking the user to enter a number.

#Sample run for q2.py
Enter a positive integer: 10
Perfect Squares below 10 are: 1, 4, 9
#Sample run for q2.py
Enter a positive integer: -10
You did not enter a positive integer
  • Test your program with at least 2 values for num that are different than the example. One of those must cause the program to display the error message.
  • Which loop is best suited for this question (while /for)? Briefly explain (add the explanation to the docstring of that function)
  • The input is taken in the q2.py while the output is displayed by the function.
  • Copy the results to testing.txt
  • Assume: user will enter only integer values, positive or negative. Also, user will never enter 1.

Q3:

In mathematics, the notation n! represents the factorial of a non-negative integer n. The factorial of n is the product of all the non-negative integers from 1 to n.

For example,
7! = 1 x 2 x 3 x 4 x 5 x 6 x 7 = 5,040
and
4! = 1 x 2 x 3 x 4 = 24

Write a function called factorial that takes a non-negative integer num as a parameter then uses a for loop to calculate and return the factorial of that number. If the user enters a negative number, the function returns the integer -1. Save the function in a PyDev library module named a6_functions.py (same as other questions)

Write a main program named q3.py that tests the function by asking the user to enter a number and displaying the output.

#Sample run for q3.py
Enter a positive integer: 7
7! = 5040
#Sample run for q3.py
Enter a positive integer: -7
You did not enter a positive integer
  • Test your program with 2 different values for num that are different than the example. One of those must cause the program to display the error message.
  • The input and output both are performed in the q3.py
  • Copy the results to testing.txt .
  • Assume: user will enter only integer values, positive or negative.

Q4:

In mathematics, a positive integer greater than 1, which has no other factors except 1 and the number itself, is called a prime number. 2, 3, 5, 7 etc. are prime numbers as they can only be divided by 1 and by themselves to give a whole number. 4, on the other hand is not a prime because, 4 can be divided by 1,2 and 4.

Write a function called is_prime that takes a positive integer called num as parameter and returns True if the number is prime and False otherwise. If the user enters an invalid input (negative integer) the testing program should keep asking the user for another input until the user enters a valid input. Save the function in a PyDev library module named a6_functions.py (same as other questions)

Write a main program named q4.py that tests the function by asking the user to enter an integer and displaying the output.

#Sample run for q4.py
Enter a positive integer: 8
8 is not a prime number
#Sample run for q4.py
Enter a positive integer: -8
Enter a positive integer: 23
23 is a prime number
  • Test your program with3 different numbers:
    • Prime number
    • Non-prime number
    • invalid input that will cause an error message to be displayed
  • Which loop did you use for validating the input? Briefly explain (add the explanation to the docstring of that function)
  • The input and output are performed in the q4.py
  • Copy the results to testing.txt
  • Assume: user will enter only integer values, positive or negative.
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.