Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
84 views

Practical 3 Python

The document provides examples of Python programs and code snippets to solve problems related to circles, collinear points, merging text files, creating and searching CSV files, printing patterns, calculating Fibonacci series recursively, and calculating the number of months needed to save for a down payment on a house. It includes the source code and output for each problem and asks the user to input variables like annual salary when calculating savings.

Uploaded by

Ayush Sheth
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
84 views

Practical 3 Python

The document provides examples of Python programs and code snippets to solve problems related to circles, collinear points, merging text files, creating and searching CSV files, printing patterns, calculating Fibonacci series recursively, and calculating the number of months needed to save for a down payment on a house. It includes the source code and output for each problem and asks the user to input variables like annual salary when calculating savings.

Uploaded by

Ayush Sheth
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

PRACTICAL-3

COMPILER USED : IDLE SHELL 3.10.2

1. Given the coordinates (x,y) of center of a circle and its radius, determine whether a point lies inside the
circle, on the circle or outside the circle. (Hint: Use sqrt( ), pow(
))

Source code:-

Output:

2. Given three points (x1,y1), (x2,y2) and (x3,y3), check if all the three points fall on one straight line.

Source code:-
Output:

3. WAP to read two text files and merge their contents into a third file.

Source code:-

Output:
4. Write a program in Python to create a CSV file by entering user-id and password, read and search the
password for given user-id.

Source code:-

Output:
5. WAP to ask the number of lines from the user and print the following pattern: 1
AB
234
ABCD

Source code:-
Output:

6. Display the user specified term in Fibonacci series using a recursive function fibo().

Source code:-

Output:

7. You have graduated from PDEU and now have a great job! You move to Banglore and decide that you want
to start saving to buy a house. As housing prices are very high in Banglore, you realize you are going to have
to save for several years before you can afford to make the down payment on a house. We are going to
determine how long it will take you to save enough money to make the down payment given the following
assumptions:

a. Call the cost of your dream home total_cost.

b. Call the portion of the cost needed for a down payment portion_down_payment. For simplicity, assume
that portion_down_payment = 0.25 (25%).

c. Call the amount that you have saved thus far current_savings. You start with a current savings of ₹ 0.
d. Assume that you invest your current savings wisely, with an annual return of r (in other words, at the
end of each month, you receive an additional current_savings*r/12 funds to put into your savings – the
12 is because r is an annual rate). Assume that your investments earn a return of r = 0.04 (4%).

e. Assume your annual salary is annual_salary.


6.Assume you are going to dedicate a certain amount of your salary each month to saving for the down
payment. Cal l that portion_saved. This variable should be in decimal form (i.e. 0.1 for 10%).

f. At the end of each month, your savings will be increased by the return on your investment, plus a
percentage of your monthly salary (annual salary / 12).

Write a program to calculate how many months it will take you to save up enough money for a down
payment. You will want your main variables to be floats, so you should cast user inputs to floats.

def calculate_months_to_save():

annual_salary = float(input("Enter your annual salary: "))

Output:

You might also like