0% found this document useful (0 votes)
17 views1 page

Python Programming Practice Exercises

The document contains a series of programming exercises focused on Python fundamentals. Each exercise requires the implementation of specific tasks, such as displaying jokes, calculating dates, generating outputs, and performing mathematical operations. The exercises aim to enhance programming skills through practical applications and problem-solving.

Uploaded by

kalpanapriyam213
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views1 page

Python Programming Practice Exercises

The document contains a series of programming exercises focused on Python fundamentals. Each exercise requires the implementation of specific tasks, such as displaying jokes, calculating dates, generating outputs, and performing mathematical operations. The exercises aim to enhance programming skills through practical applications and problem-solving.

Uploaded by

kalpanapriyam213
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

PROGRAMMING PRACTICE/KNOWLEDGE BASED QUESTIONS

Chapter: Python Fundamentals

1. Write a program that displays a joke. But display the punchline only when the
user presses enter key. (Hint. You may use input()).

2. Write a program to read today's date (only del part) from user Then display how
many days are left in the current month.

3. Write a program that generates the following output


5
10
9
Assign value 5 to a variable using assignment operator (=) Multiply it with 2 to
generate 10 and subtract 1 to generate 9.

4. Modify above program so as to print output as 5@10@9.

5. Write the program with maxımum three lines of code and that assigns first 5
multiples of a number to 5 variables and then print them.

6. Write a Python program that accepts radius of circle and prints its area.

7. Write Python program that accepts marks in 5 subjects and outputs average marks.

8. Write a short program that asks tor your height in centimetres and then converts
your height to feet and inches. (1 foot = 12 inches, 1inch =2.54 cm).

9. Write a program to read a number n and print n2, n3 and n4.

10. Write a program to find area of a triangle.

11. Write a program to compute simple interest and compound interest.

12. Write a program to input a number and print its first five multiples.

13. Write a program to read details like name, class, age of a student and then
print the details firstly in same line and then in separate lines. Make sure to
have two blank lines in these two different types of prints.

14. Write a program to input a single digit(n) and print a 3 digit number created
as <n(n + 1)(n + 2)> e.g., if you input 7 then it should print 789. Assume that the
input digit is in range 1-7.

15. Write a program to read three numbers in three variables and swap first two
variables with the sums of first and second, second and third numbers respectively.

Common questions

Powered by AI

The program can prompt the user to enter the circle's radius using 'input()' and convert it to a floating-point number. It then uses the formula 'area = π * radius^2' (where π can be obtained using the 'math.pi' constant) to compute the area, which is subsequently printed.

A value can be assigned to a variable and then manipulated using arithmetic operations. For instance, with the initial value 5, multiplying by 2 gives 10, and subtracting 1 results in 9. This illustrates the efficiency of using limited operations to achieve different results. Additionally, these expressions can be printed in a single line using the format method or string concatenation.

By leveraging Python's tuple assignment feature, we can assign the multiples in one line, e.g., 'a, b, c, d, e = n, 2*n, 3*n, 4*n, 5*n', and then use a loop or print statement to display them. This technique reduces code length while maintaining readability.

The program can take three inputs 'a', 'b', 'c'. It updates the first two variables using 'a = a + b' and 'b = b + c'. This logic reflects scenarios where sequential values need adjustment without using temporary variables or extra space, common in optimization challenges.

The program collects user details via 'input()' and uses formatted strings to display them sequentially and in new lines, separated by commands that introduce blank lines. This enhances readability and demonstrates the importance of format control in reporting user-specific data.

Python's exponentiation operator '**' can be used to calculate powers of a number. By reading a number 'n', the program can compute 'n^2', 'n^3', and 'n^4' directly using expressions like 'n**2, n**3, n**4', and print them in a structured format for efficient computation and display.

The program needs to account for the current month's total number of days minus today's date. This requires conditional logic to determine how many days remaining by addressing the length of each possible month in the Gregorian calendar, including considerations for leap year adjustments if applicable.

The program accepts height in centimeters, then uses conversion constants: 1 inch = 2.54 cm and 1 foot = 12 inches. The conversion involves calculating inches from centimeters, then dividing by 12 to get feet along with any additional leftover inches. These results are formatted and printed to display the height in feet and inches.

The program can use the 'input()' function to prompt the user to press the enter key before displaying the punchline. This will provide a pause that creates an engaging interaction with the user.

For simple interest, the program uses 'SI = P * R * T / 100'. For compound interest, it uses 'CI = P * (1 + R/100)^T - P'. It prompts for principal (P), rate (R), and time (T), computes both interests and prints them, making them distinguishable by using clear variable names and comments.

You might also like