[go: up one dir, main page]

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

Python U1

The document provides 10 programming problems of varying complexity: 1) print numbers from 1 to 10, 2) calculate the sum of integers from 1 to a user-input number, 3) print the multiplication table of a user-input number, 4) print the factorial of a user-input number, 5) calculate one number raised to the power of another, 6) reverse the digits of a user-input number, 7) calculate the sum of digits of a user-input number, 8) read and display the lines of a text file, 9) count lines in a text file not starting with "T", and 10) count and display the total words in a text file.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
81 views1 page

Python U1

The document provides 10 programming problems of varying complexity: 1) print numbers from 1 to 10, 2) calculate the sum of integers from 1 to a user-input number, 3) print the multiplication table of a user-input number, 4) print the factorial of a user-input number, 5) calculate one number raised to the power of another, 6) reverse the digits of a user-input number, 7) calculate the sum of digits of a user-input number, 8) read and display the lines of a text file, 9) count lines in a text file not starting with "T", and 10) count and display the total words in a text file.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

1.

 Write a program to print numbers from 1 to 10. Solution

2. Write a program that asks the user for a positive integer value. The program should
calculate the sum of all the integers from 1 up to the number entered. For example, if
the user enters 20, the loop will find the sum of 1, 2, 3, 4, ... 20. 

3. Write a program that prompts the user to input a number and prints its
mulitiplication table. 

4. Write a program that prompts the user to input a number and prints its factorial. The
factorial of an integer n is defined as n! = 1 x 2 x 3 x ... x n; if n > 0 = 1; if n = 0 For
instance, 6! can be calculated as 1 x 2 x 3 x 4 x 5 x 6. 

5. Two numbers are entered through the keyboard. Write a program to find the value of
one number raised to the power of another. 

6. Write a program that prompts the user to input a number and reverse its digits. For
example, the reverse of 12345 is 54321; reverse of 5600 is 65.

7. Write a program that asks the user to input a positive integer. Your program should
find and display the sum of digits of number. For example, sum of digits of number
32518 is 3+2+5+1+8 = 19

8. Write a function in python to read the content from a text file "poem.txt" line by line
and display the same on screen.

9. Write a function in python to count the number of lines from a text file "story.txt"
which is not starting with an alphabet "T". 

Example: If the file "story.txt" contains the following lines: A boy is playing there.
There is a playground.
An aeroplane is in the sky.
The sky is pink.
Alphabets and numbers are allowed in the password.

The function should display the output as 3 Solution

10. Write a function in Python to count and display the total number of words in a text
file. Solution

You might also like